name: build

# build on c/cpp changes or workflow changes
on:
  - push
  - pull_request

jobs:

  linux-gl:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - name: Install deps
        run: |
          sudo apt-get update
          sudo apt-get install g++ cmake libxxf86vm-dev libgl1-mesa-dev libpng-dev libjpeg-dev zlib1g-dev -qyy

      - name: Build
        run: |
          cmake .
          make VERBOSE=1 -j2

      - name: Package
        run: |
          make DESTDIR=$PWD/_install install
          tar -c -I "gzip -9" -f irrlicht-linux.tar.gz -C ./_install/usr/local .

      - uses: actions/upload-artifact@v2
        with:
          name: irrlicht-linux
          path: ./irrlicht-linux.tar.gz

  linux-gles:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - name: Install deps
        run: |
          sudo apt-get update
          sudo apt-get install g++ cmake libxxf86vm-dev libgles2-mesa-dev libpng-dev libjpeg-dev zlib1g-dev xvfb -qyy

      - name: Build
        run: |
          sed '/#define _IRR_COMPILE_WITH_OGLES2_/ s|^//||g' -i include/IrrCompileConfig.h
          sed '/#define _IRR_COMPILE_WITH_OPENGL_/ s|^|//|g' -i include/IrrCompileConfig.h
          cmake . -DBUILD_EXAMPLES=1
          make -j2

      - name: Test (headless)
        run: |
          cd bin/Linux
          ./AutomatedTest null

      - name: Test (Xvfb)
        run: |
          cd bin/Linux
          LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest

  win32:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: Install compiler
        run: |
          sudo apt-get update && sudo apt-get install cmake -qyy
          wget http://minetest.kitsunemimi.pw/mingw-w64-i686_11.2.0_ubuntu20.04.tar.xz -O mingw.tar.xz
          sudo tar -xaf mingw.tar.xz -C /usr

      - name: Build
        run: |
          ./scripts/ci-build-mingw.sh package
        env:
          CC: i686-w64-mingw32-gcc
          CXX: i686-w64-mingw32-g++

      - uses: actions/upload-artifact@v2
        with:
          name: irrlicht-win32
          path: ./irrlicht-win32.zip

  win64:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: Install compiler
        run: |
          sudo apt-get update && sudo apt-get install cmake -qyy
          wget http://minetest.kitsunemimi.pw/mingw-w64-x86_64_11.2.0_ubuntu20.04.tar.xz -O mingw.tar.xz
          sudo tar -xaf mingw.tar.xz -C /usr

      - name: Build
        run: |
          ./scripts/ci-build-mingw.sh package
        env:
          CC: x86_64-w64-mingw32-gcc
          CXX: x86_64-w64-mingw32-g++

      - uses: actions/upload-artifact@v2
        with:
          name: irrlicht-win64
          path: ./irrlicht-win64.zip

  macos:
    runs-on: macos-10.15
    steps:
      - uses: actions/checkout@v2
      - name: Install deps
        run: |
          brew update
          brew install cmake libpng jpeg

      - name: Build
        run: |
          cmake . -DCMAKE_FIND_FRAMEWORK=LAST -DBUILD_EXAMPLES=1
          make -j3

      - name: Test (headless)
        run: |
          ./bin/OSX/AutomatedTest null