name: C-lang CI

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

env:
  GCC_ARGS: src/*.c src/*.h -Ofast
  TARGET: margen
  TEST_ARGS: ""

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: gcc
        run: gcc -v -Wall -Wextra -Werror $GCC_ARGS

  build-release:
    needs: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - 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:
    needs: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: gcc
        run: mkdir -p build && gcc $GCC_ARGS -o build/$TARGET
      - name: run program
        run: ./build/$TARGET $TEST_ARGS
