name: MinGW

on:
  push:
  pull_request:


jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        window_backend: [ Glfw, Sdl ]

    steps:
    - uses: actions/checkout@master
    - name: Checkout submodules
      run: git submodule update --init --recursive

    - name: Install MinGW
      run: |
        sudo apt-get update && sudo apt-get install -y mingw-w64
        sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
        sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
        sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
        sudo update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix

#    - name: Setup interactive tmate session
#      uses: mxschmitt/action-tmate@v3

    - name: Build x86_64
      run: |
          mkdir build_x86_64
          cd build_x86_64
          if [ "${{ matrix.window_backend }}" = "Sdl" ]; then
            cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_x86_64.cmake -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_OPENGL3=ON
          fi
          if [ "${{ matrix.window_backend }}" = "Glfw" ]; then
            cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_x86_64.cmake -DCMAKE_BUILD_TYPE=Release
          fi
          make -j 4

    - name: Build i686
      run: |
        mkdir build_i686
        cd build_i686
          if [ "${{ matrix.window_backend }}" = "Sdl" ]; then
            cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_i686.cmake -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_USE_SDL2=ON -DHELLOIMGUI_HAS_OPENGL3=ON
          fi
          if [ "${{ matrix.window_backend }}" = "Glfw" ]; then
            cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_i686.cmake -DCMAKE_BUILD_TYPE=Release
          fi
          make -j 4
  
