name: "Linux Build"
on:
  push:
    branches: [ v1.x ]
  pull_request:
    # branches: [ master ]

jobs:
  Latest:
    name: Linux ${{matrix.cxx}}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        cxx: ['g++-14', 'clang++-18']
    env:
      CMAKE_OPTIONS: -DBUILD_TESTING=ON -G Ninja
      CMAKE_MATROSKA_OPTIONS: -DBUILD_EXAMPLES=ON
      CXX: ${{matrix.cxx}}
    steps:
      - name: list compilers
        run: dpkg --list | grep compiler

      - name: Get pushed code
        uses: actions/checkout@v7

      - name: Checkout libebml
        uses: actions/checkout@v7
        with:
          repository: Matroska-Org/libebml
          path: libebml
          ref: v1.x

      - name: Configure libebml
        run: cmake -S libebml -B libebml/_build ${{ env.CMAKE_OPTIONS }}

      - name: Build libebml
        run: cmake --build libebml/_build --parallel

      - name: Install libebml
        run: cmake --install libebml/_build --prefix ${GITHUB_WORKSPACE}/_built

      - name: Configure
        run: cmake -S . -B _build  ${{ env.CMAKE_OPTIONS }} ${{ env.CMAKE_MATROSKA_OPTIONS }} -DEBML_DIR="${GITHUB_WORKSPACE}/_built/lib/cmake/EBML"

      - name: Build
        run: cmake --build _build --parallel

      - name: Test installation
        run: cmake --install _build --prefix ${GITHUB_WORKSPACE}/_built

  Current:
    name: libmatroska for Linux
    runs-on: ubuntu-latest
    env:
      CMAKE_MATROSKA_OPTIONS: -DBUILD_EXAMPLES=ON
    steps:

      - name: Get pushed code
        uses: actions/checkout@v7

      - name: Checkout libebml
        uses: actions/checkout@v7
        with:
          repository: Matroska-Org/libebml
          path: libebml
          ref: v1.x

      - name: Configure libebml
        run: cmake -S libebml -B libebml/_build -G Ninja

      - name: Build libebml
        run: cmake --build libebml/_build --parallel

      - name: Install libebml
        run: cmake --install libebml/_build --prefix ${GITHUB_WORKSPACE}/_built

      - name: Configure CMake
        run: cmake -S . -B _build ${{ env.CMAKE_MATROSKA_OPTIONS }} -DEBML_DIR="${GITHUB_WORKSPACE}/_built/lib/cmake/EBML" -G Ninja

      - name: Build with CMake
        run: cmake --build _build --parallel

      - name: Test installation
        run: cmake --install _build --prefix ${GITHUB_WORKSPACE}/_built

  s390X:
    name: Big Endian Linux
    runs-on: ubuntu-latest
    env:
      CMAKE_OPTIONS: -DDEV_MODE=ON -DBUILD_TESTING=ON -DCMAKE_SYSTEM_PROCESSOR=s390x -DCMAKE_CROSSCOMPILING_EMULATOR="qemu-s390x;-L;/usr/s390x-linux-gnu/" -G Ninja
      CMAKE_MATROSKA_OPTIONS: -DBUILD_EXAMPLES=ON
      CXX: s390x-linux-gnu-g++
    steps:
      - name: install toolchain
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends qemu-user crossbuild-essential-s390x qemu-system-s390x

      - name: list compilers
        run: dpkg --list | grep compiler

      - name: Get pushed code
        uses: actions/checkout@v7

      - name: Checkout libebml
        uses: actions/checkout@v7
        with:
          repository: Matroska-Org/libebml
          path: libebml
          ref: v1.x

      - name: Configure libebml
        run: cmake -S libebml -B libebml/_build ${{ env.CMAKE_OPTIONS }}

      - name: Build libebml
        run: cmake --build libebml/_build --parallel

      - name: Install libebml
        run: cmake --install libebml/_build --prefix ${GITHUB_WORKSPACE}/_built

      - name: Configure
        run: cmake -S . -B _build  ${{ env.CMAKE_OPTIONS }} ${{ env.CMAKE_MATROSKA_OPTIONS }} -DEBML_DIR="${GITHUB_WORKSPACE}/_built/lib/cmake/EBML"

      - name: Build
        run: cmake --build _build --parallel

      - name: Test installation
        run: cmake --install _build --prefix ${GITHUB_WORKSPACE}/_built
