name: Build Windows Distributable

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v2
    - name: Fetch entire repository
      run: git fetch --prune --unshallow
    - name: Install prerequisites
      run: sudo apt-get install mingw-w64 gcc make tcl
    - name: Configure MinGW to use Posix threads
      run: |
        sudo update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix
        sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-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 x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix   
    - name: Make
      run: make OPENMSX_TARGET_CPU=x86_64 OPENMSX_TARGET_OS=mingw-w64 OPENMSX_FLAVOUR=opt staticbindist
    - name: Determine version
      id: get_version
      run: |
        OPENMSX_VERSION=`python3 build/version.py`
        echo ::set-output name=OPENMSX_VERSION::$OPENMSX_VERSION
    - name: Create redistributable zip
      run: cd derived/x86_64-mingw-w64-opt-3rd/bindist/install && zip -r ../openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-mingw-w64-opt.zip *
    - name: Upload redistributable zip
      uses: actions/upload-artifact@v1
      with:
        name: openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-mingw-w64-opt.zip
        path: derived/x86_64-mingw-w64-opt-3rd/bindist/openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-mingw-w64-opt.zip
