name: GCC

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - '*'

jobs:
  bip-apps:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
    - name: Build Demo Apps GNU89
      run: |
        gcc --version
        make clean
        make LEGACY=true CSTANDARD="-std=gnu89" all
    - name: LEGACY=true Build Demo Apps GNU99
      run: |
        make clean
        make LEGACY=true CSTANDARD="-std=gnu99" all
    - name: LEGACY=true Build Demo Apps GNU11
      run: |
        make clean
        make LEGACY=true CSTANDARD="-std=gnu11" all
    - name: LEGACY=true Build Demo Apps GNU17
      run: |
        make clean
        make LEGACY=true CSTANDARD="-std=gnu17" all

  bip-no-bbmd-apps:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
    - name: Build Demo Apps BBMD=none
      run: |
        gcc --version
        make clean
        make LEGACY=true BBMD=none all

  bip-client-bbmd-apps:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
    - name: Build Demo Apps BBMD=client
      run: |
        gcc --version
        make clean
        make LEGACY=true BBMD=client all

  gateway:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
    - name: Build Gateway Demo
      run: |
        gcc --version
        make clean
        make LEGACY=true gateway

  bacnet-sc-hub:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout BACnet Stack
      uses: actions/checkout@v5
    - name: Checkout libwebsockets
      uses: actions/checkout@v5
      with:
        repository: warmcat/libwebsockets
        ref: v4.3-stable
        path: libwebsockets
    - name: Create BACnet/SC Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
        sudo apt-get install -qq libcap-dev
        sudo apt-get install -qq libssl-dev
        sudo apt-get install -qq libuv1-dev
        bash -c 'cd libwebsockets;mkdir build;cd build;cmake .. -DLWS_WITH_LIBUV=ON -DLWS_WITH_MINIMAL_EXAMPLES=0 -DLWS_MAX_SMP=32 -DCMAKE_POLICY_VERSION_MINIMUM=3.5;make'
        sudo bash -c 'cd libwebsockets;cd build;make install'
    - name: Build BACnet/SC Hub Demo
      run: |
        gcc --version
        pwd
        ls -al
        make clean
        make sc-hub

  router:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout BACnet Stack
      uses: actions/checkout@v5
    - name: Checkout libwebsockets
      uses: actions/checkout@v5
      with:
        repository: warmcat/libwebsockets
        ref: v4.3-stable
        path: libwebsockets
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
        sudo apt-get install -qq libcap-dev
        sudo apt-get install -qq libssl-dev
        sudo apt-get install -qq libuv1-dev
        bash -c 'cd libwebsockets;mkdir build;cd build;cmake .. -DLWS_WITH_LIBUV=ON -DLWS_WITH_MINIMAL_EXAMPLES=0 -DLWS_MAX_SMP=32 -DCMAKE_POLICY_VERSION_MINIMUM=3.5;make'
        sudo bash -c 'cd libwebsockets;cd build;make install'
    - name: Build Router Demo
      run: |
        gcc --version
        pwd
        ls -al
        make clean
        make LEGACY=true router

  router-ipv6:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
    - name: Build Router IPv6 Demo
      run: |
        gcc --version
        make clean
        make LEGACY=true router-ipv6

  router-mstp:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
    - name: Build Router MSTP Demo
      run: |
        gcc --version
        make clean
        make LEGACY=true router-mstp

  bip6:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
    - name: Build BACnet/IPv6 Demo Apps
      run: |
        gcc --version
        make clean
        make LEGACY=true bip6

  mstp:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
    - name: Build MSTP Demo Apps
      run: |
        gcc --version
        make clean
        make LEGACY=true mstp

  ethernet:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq libconfig-dev
        sudo apt-get install -qq libcap-dev
    - name: Build Ethernet Demo Apps
      run: |
        gcc --version
        make clean
        make LEGACY=true ethernet

  ports-arm-makefile:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq build-essential
        sudo apt-get install -qq gcc-arm-none-eabi
        sudo apt-get install -qq libnewlib-arm-none-eabi
    - name: ports-arm-makefile
      run: |
        make clean
        arm-none-eabi-gcc --version
        make LEGACY=true stm32f10x
        make LEGACY=true stm32f4xx
        make LEGACY=true at91sam7s

  ports-arm-cmake:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq build-essential
        sudo apt-get install -qq gcc-arm-none-eabi
        sudo apt-get install -qq libnewlib-arm-none-eabi
        sudo apt-get install -qq cmake
    - name: ports-arm-cmake
      run: |
        arm-none-eabi-gcc --version
        make stm32f4xx-cmake
        make at91sam7s-cmake

  ports-avr:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq build-essential
        sudo apt-get install -qq gcc-avr avr-libc binutils-avr
    - name: ports-avr
      run: |
        avr-gcc --version
        make LEGACY=true atmega328
        make LEGACY=true bdk-atxx4-mstp
        make LEGACY=true xplained

  ports-lwip:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq build-essential
        sudo apt-get install -qq liblwip-dev
    - name: ports-lwip
      run: |
        make lwip

  mingw:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq build-essential
        sudo apt-get install -qq mingw-w64
    - name: Build Win32 Demo Apps
      run: |
        export CC=i686-w64-mingw32-gcc
        export LD=i686-w64-mingw32-ld
        i686-w64-mingw32-gcc --version
        make win32
    - name: Build Win32 Demo IP to IPv6 Router
      run: make LEGACY=true BUILD=win32 router-ipv6
    - name: Build Win32 Demo IP to MS/TP Router
      run: make LEGACY=true BUILD=win32 router-mstp
    - name: Build Win32 Demo Gateway
      run: make LEGACY=true BUILD=win32 gateway

  piface:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v5
    - name: Build PiFace Demo
      run: |
        gcc --version
        make clean
        make LEGACY=true BUILD=pipeline piface

  blinkt:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v5
    - name: Build Blinkt! Demo
      run: |
        gcc --version
        make clean
        make LEGACY=true BUILD=pipeline blinkt

  gtk-discover:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v5
    - name: Create Build Environment
      run: |
        sudo apt-get update -qq
        sudo apt-get install -qq build-essential libgtk-3-dev
    - name: Build BACnet GTK Discover Demo
      run: |
        gcc --version
        make clean
        make gtk-discover
