name: CI Configure
on: [push, pull_request]
jobs:
  ci-configure:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: Ubuntu GCC
            os: ubuntu-latest
            compiler: gcc
            configure-args: --warn

          - name: Ubuntu GCC OSB
            os: ubuntu-latest
            compiler: gcc
            configure-args: --warn
            build-dir: ../build
            build-src-dir: ../zlib-ng

          - name: Ubuntu GCC Compat No Opt
            os: ubuntu-latest
            compiler: gcc
            configure-args: --warn --zlib-compat --without-optimizations --without-new-strategies

          - name: Ubuntu GCC ARM SF
            os: ubuntu-latest
            compiler: arm-linux-gnueabi-gcc
            configure-args: --warn
            chost: arm-linux-gnueabi
            packages: qemu gcc-arm-linux-gnueabi libc-dev-armel-cross

          - name: Ubuntu GCC ARM SF Compat No Opt
            os: ubuntu-latest
            compiler: arm-linux-gnueabi-gcc
            configure-args: --warn --zlib-compat --without-optimizations --without-new-strategies
            chost: arm-linux-gnueabi
            packages: qemu gcc-arm-linux-gnueabi libc-dev-armel-cross

          - name: Ubuntu GCC ARM HF
            os: ubuntu-latest
            compiler: arm-linux-gnueabihf-gcc
            configure-args: --warn
            chost: arm-linux-gnueabihf
            packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross

          - name: Ubuntu GCC ARM HF No ACLE
            os: ubuntu-latest
            compiler: arm-linux-gnueabihf-gcc
            configure-args: --warn --without-acle
            chost: arm-linux-gnueabihf
            packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross

          - name: Ubuntu GCC ARM HF No NEON
            os: ubuntu-latest
            compiler: arm-linux-gnueabihf-gcc
            configure-args: --warn --without-neon
            chost: arm-linux-gnueabihf
            packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross

          - name: Ubuntu GCC ARM HF Compat No Opt
            os: ubuntu-latest
            compiler: arm-linux-gnueabihf-gcc
            configure-args: --warn --zlib-compat --without-optimizations --without-new-strategies
            chost: arm-linux-gnueabihf
            packages: qemu gcc-arm-linux-gnueabihf libc-dev-armel-cross

          - name: Ubuntu GCC AARCH64
            os: ubuntu-latest
            compiler: aarch64-linux-gnu-gcc
            configure-args: --warn
            chost: aarch64-linux-gnu
            packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross

          - name: Ubuntu GCC AARCH64 No ACLE
            os: ubuntu-latest
            compiler: aarch64-linux-gnu-gcc
            configure-args: --warn --without-acle
            chost: aarch64-linux-gnu
            packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross

          - name: Ubuntu GCC AARCH64 No NEON
            os: ubuntu-latest
            compiler: aarch64-linux-gnu-gcc
            configure-args: --warn --without-neon
            chost: aarch64-linux-gnu
            packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross

          - name: Ubuntu GCC AARCH64 Compat No Opt
            os: ubuntu-latest
            compiler: aarch64-linux-gnu-gcc
            configure-args: --warn --zlib-compat --without-optimizations --without-new-strategies
            chost: aarch64-linux-gnu
            packages: qemu gcc-aarch64-linux-gnu libc-dev-arm64-cross

          - name: Ubuntu GCC PPC
            os: ubuntu-latest
            compiler: powerpc-linux-gnu-gcc
            configure-args: --warn --static
            chost: powerpc-linux-gnu
            packages: qemu gcc-powerpc-linux-gnu libc-dev-powerpc-cross
            cflags: -static
            ldflags: -static

          - name: Ubuntu GCC PPC64
            os: ubuntu-latest
            compiler: powerpc64-linux-gnu-gcc
            configure-args: --warn --static
            chost: powerpc-linux-gnu
            packages: qemu gcc-powerpc64-linux-gnu libc-dev-ppc64-cross
            cflags: -static
            ldflags: -static

          - name: Ubuntu GCC PPC64LE
            os: ubuntu-latest
            compiler: powerpc64le-linux-gnu-gcc
            configure-args: --warn
            chost: powerpc64le-linux-gnu
            packages: qemu gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross

          - name: Ubuntu GCC S390X
            os: ubuntu-latest
            compiler: s390x-linux-gnu-gcc
            configure-args: --warn --static
            chost: s390x-linux-gnu
            packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
            cflags: -static
            ldflags: -static

          - name: Ubuntu GCC S390X DFLTCC
            os: ubuntu-latest
            compiler: s390x-linux-gnu-gcc
            configure-args: --warn --static --with-dfltcc-deflate --with-dfltcc-inflate
            chost: s390x-linux-gnu
            packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
            cflags: -static
            ldflags: -static

          - name: Ubuntu GCC S390X DFLTCC Compat
            os: ubuntu-latest
            compiler: s390x-linux-gnu-gcc
            configure-args: --warn --zlib-compat --static --with-dfltcc-deflate --with-dfltcc-inflate
            chost: s390x-linux-gnu
            packages: qemu gcc-s390x-linux-gnu libc-dev-s390x-cross
            cflags: -static
            ldflags: -static

          - name: macOS GCC
            os: macOS-latest
            compiler: gcc
            configure-args: --warn

    steps:
    - name: Checkout repository
      uses: actions/checkout@v1

    - name: Install packages (Ubuntu)
      if: runner.os == 'Linux' && matrix.packages
      run: |
        sudo apt-get update
        sudo apt-get install -y ${{ matrix.packages }}

    - name: Generate project files
      run: |
        mkdir ${{ matrix.build-dir || '.not-used' }}
        cd ${{ matrix.build-dir || '.' }}
        ${{ matrix.build-src-dir || '.' }}/configure ${{ matrix.configure-args }}
      env:
        CC: ${{ matrix.compiler }}
        CFLAGS: ${{ matrix.cflags }}
        LDFLAGS: ${{ matrix.ldflags }}
        CHOST: ${{ matrix.chost }}
        CI: true

    - name: Compile source code
      run: |
        cd ${{ matrix.build-dir || '.' }}
        make -j2

    - name: Run test cases
      run: |
        cd ${{ matrix.build-dir || '.' }}
        make test
