name: Clang Build CI

concurrency:
  group: build-${{ github.ref }}
  cancel-in-progress: true

on:
  workflow_dispatch:
  push:
    paths:
      - '.github/workflows/build.yml'
      - 'src/*.c'
      - 'src/*.h'
      - 'configure.ac'
      - 'Makefile.am'

env:
  GCC_ARGS: src/*.c src/*.h -lglfw -lGL -lm -lasound -Wno-format-truncation -Iinclude hashmap.c/hashmap.c log.c/src/log.c -DGLFW_INCLUDE_NONE -DGLFW_NATIVE_INCLUDE_NONE
  GCC_ARGS_VIDEO: -DGLFW_EXPOSE_NATIVE_EGL  -DVIDEO_IN
  PACKAGES: "libglfw3-dev libgl-dev libasound2-dev"
  PACKAGES_VIDEO: "libv4l-dev"
  TARGET: forge
  TEST_ARGS: "--help"

jobs:
  build-release:
    runs-on: ubuntu-latest
    steps:
      - name: Install packages
        run: apt update && apt install -y $PACKAGES $PACKAGES_VIDEO
      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          submodules: 'true'
      - name: aclocal
        run: aclocal
      - name: autoconf
        run: autoconf
      - name: automake
        run: automake --add-missing
      - name: configure
        run: ./configure
      - name: make
        run: make
      - name: make distcheck
        run: make distcheck

  run-no-video:
    runs-on: ubuntu-latest
    steps:
      - name: Install packages
        run: apt update && apt install -y $PACKAGES
      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          submodules: 'true'
      - name: gcc
        run: mkdir -p build && gcc $GCC_ARGS -o build/$TARGET
      - name: run program
        run: ./build/$TARGET $TEST_ARGS

  run-video:
    runs-on: ubuntu-latest
    steps:
      - name: Install packages
        run: apt update && apt install -y $PACKAGES $PACKAGES_VIDEO
      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          submodules: 'true'
      - name: gcc
        run: mkdir -p build && gcc $GCC_ARGS $GCC_ARGS_VIDEO -o build/$TARGET
      - name: run program
        run: ./build/$TARGET $TEST_ARGS
