name: Vangers Windows 32bit Build

on: [push, pull_request]

jobs:
  build:
    runs-on: windows-latest
    steps:
    - uses: msys2/setup-msys2@v2
      with:
        msystem: MINGW32
    - name: install libs
      run: msys2 -c 'pacman --noconfirm -S
        mingw-w64-i686-ninja
        mingw-w64-i686-gcc
        mingw-w64-i686-SDL2
        mingw-w64-i686-SDL2_net
        mingw-w64-i686-cmake
        mingw-w64-i686-libogg
        mingw-w64-i686-libvorbis
        mingw-w64-i686-nasm
        mingw-w64-i686-yasm
        mingw-w64-i686-make'
    - uses: actions/checkout@v1
    - name: clunk -- download
      run: git clone --depth 1 https://github.com/stalkerg/clunk.git clunk
    - name: clunk -- create build dir
      run: msys2 -c 'mkdir clunk/build'
    - name: clunk -- build and install
      run: |
        msys2 -c 'cmake -DCMAKE_INSTALL_PREFIX=/mingw32 -G Ninja ..'
        msys2 -c 'ninja'
        msys2 -c 'ninja install'
      working-directory: clunk/build
    - name: ffmpeg -- download
      run: git clone --depth 1 --branch n4.2.2 https://git.ffmpeg.org/ffmpeg.git ffmpeg
    - name: ffmpeg -- configure
      run: msys2 -c './configure --enable-shared --prefix=/mingw32
        --disable-everything
        --enable-swscale
        --enable-zlib
        --enable-demuxer=avi,rawvideo
        --enable-decoder=png,rawvideo,h264
        --enable-parser=png
        --enable-protocol=file
        --disable-d3d11va
        --disable-dxva2
        --disable-doc --disable-ffplay --disable-ffprobe --disable-ffmpeg
        --disable-static --disable-bzlib --disable-libopenjpeg --disable-iconv'
      working-directory: ffmpeg
    - name: ffmpeg -- build and install
      run: |
        msys2 -c 'mingw32-make -j4'
        msys2 -c 'mingw32-make install'
      working-directory: ffmpeg
    - name: vangers -- create build dir
      run: msys2 -c 'mkdir build'
    - name: vangers -- configure
      run: msys2 -c 'cmake -G Ninja ..'
      working-directory: build
    - name: vangers -- make
      run: msys2 -c 'ninja'
      working-directory: build
    - name: vangers -- prepare release folder
      run: |
        msys2 -c 'mkdir -p vangers/bin'
        msys2 -c 'cp /mingw32/bin/SDL2.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/SDL2_net.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/avcodec-58.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/avformat-58.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/avutil-56.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/libogg-0.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/libvorbis-0.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/libvorbisfile-3.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/zlib1.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/libgcc_s_dw2-1.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/libgcc_s_seh-1.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/libstdc++-6.dll vangers/bin/'
        msys2 -c 'cp /mingw32/bin/libwinpthread-1.dll vangers/bin/'
        cp clunk/build/libclunk.dll vangers/bin/
        cp build/src/vangers.exe vangers/bin/
        cp build/src/vangers.exe vangers/bin/vangers_debug.exe
        msys2 -c 'strip vangers/bin/vangers.exe'
        cp build/server/vangers_server.exe vangers/bin/
        cp build/server/vangers_server.exe vangers/bin/vangers_server_debug.exe
        msys2 -c 'strip vangers/bin/vangers_server.exe'
        cp build/surmap/surmap.exe vangers/bin/
    - uses: actions/upload-artifact@v1
      with:
        name: Vangers-Release-32
        path: vangers
