name: Build eismuliplexer for windows
run-name: Building eismuliplexer for windows
on: [push]

jobs:
  Build:
    runs-on: ubuntu-latest
    steps:
      - name: Install dependancies
        run: |
            apt update
            apt install -y cmake mingw-w64-x86-64-dev gcc-mingw-w64 g++-mingw-w64 p7zip-full wget
            wget https://github.com/libusb/libusb/releases/download/v1.0.29/libusb-1.0.29.7z -o ${{ gitea.workspace }}/libusb.7z
            mkdir ${{ gitea.workspace }}/libusb
            7z x ${{ gitea.workspace }}/libusb.7z -o${{ gitea.workspace }}/libusb
      - name: Check out repository code
        uses: ischanx/checkout@8c80eac3058d03dc5301629e8f7d59ae255d6cc3
      - name: Version
        id: version
        run: git fetch -a; echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
      - name: Build
        run: |
            mkdir ${{ gitea.workspace }}/build
            cd ${{ gitea.workspace }}/build
            cmake -DCMAKE_INSTALL_PREFIX=/usr/x86_64-w64-mingw32/ -DCMAKE_TOOLCHAIN_FILE=../crossW64.cmake -DCMAKE_BUILD_TYPE=Release -DLIBUSB_INCLUDE_DIRS=${{ gitea.workspace }}/libusb/include/ -DLIBUSB_LIBRARIES=${{ gitea.workspace }}/libusb/MinGW64/static/libusb-1.0.a -DGIT_TAG=${{ steps.version.outputs.tag }} ..
            make
      - name: Package
        run: cd ${{ gitea.workspace }}/build; make package
      - name: Upload artifacts
        uses: actions/upload-artifact@v3
        with:
            name: eismultiplexer-win-x86_64-${{ steps.version.outputs.tag }}
            path: ${{ gitea.workspace }}/build/packaged/${{ steps.version.outputs.tag }}/*
