name: Build Linux x86_64 Distributable

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

env:
  target_cpu: x86_64
  target_os: linux
  target_flavour: opt

jobs:
  build:

    runs-on: ubuntu-20.04
    
    steps:
    - uses: actions/checkout@v2
    - name: Fetch entire repository
      run: git fetch --prune --unshallow
    - name: Install prerequisites
      run: sudo apt-get install libgl1-mesa-dev
    - name: Make
      run: make OPENMSX_TARGET_CPU=${{ env.target_cpu }} OPENMSX_TARGET_OS=${{ env.target_os }} OPENMSX_FLAVOUR=${{ env.target_flavour }} staticbindist
    - name: Determine version
      id: get_version
      run: |
        OPENMSX_VERSION=`python3 build/version.py`
        echo ::set-output name=OPENMSX_VERSION::$OPENMSX_VERSION
    - name: Prepare redistributable directory
      run: |
        cd derived/${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd/bindist
        mv install openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd
    - name: Upload redistributable zip
      uses: actions/upload-artifact@v1
      with:
        name: openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd.zip
        path: derived/${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd/bindist/openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd
