name: Test Builds

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

jobs:
  basic-ubuntu-build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Update Packages
      run: sudo apt-get update
    - name: Install Packages
      run: sudo apt-get install -y build-essential xorg-dev graphicsmagick libgraphicsmagick1-dev libmotif-dev libcurl4-openssl-dev libpcre2-dev libdb-dev shapelib libshp-dev libxpm-dev
    - name: Bootstrap
      run: ./bootstrap.sh
    - name: configure
      run: ./configure CPPFLAGS="-I/usr/include/geotiff"
    - name: make
      run: make
    - name: make install
      run: sudo make install

  full-ubuntu-build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Update Packages
      run: sudo apt-get update
    - name: Install Packages
      run: sudo apt-get install -y build-essential xorg-dev graphicsmagick libgraphicsmagick1-dev libmotif-dev libcurl4-openssl-dev libpcre2-dev libdb-dev shapelib libshp-dev libxpm-dev libproj-dev festival festival-dev libgeotiff-dev gpsman gpsmanshp libcjson1 libcjson-dev wget
    - name: Bootstrap (with autoreconf)
      run: autoreconf -i
    - name: configure
      run: ./configure CPPFLAGS="-I/usr/include/geotiff"
    - name: make
      run: make
    - name: make check
      run: make check
    - name: make install
      run: sudo make install
    - name: get NWS data
      run:  sudo /usr/local/share/xastir/scripts/get-NWSdata

  macos-build:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - name: Install XQuartz
      run: brew install xquartz --cask
    - name: Install Packages
      run: brew install autoconf automake libtool berkeley-db graphicsmagick libgeotiff openmotif pcre proj shapelib cjson
    - name: Bootstrap
      run: ./bootstrap.sh
    - name: configure
      run: ./configure CPPFLAGS="-I/usr/include/geotiff -I/opt/homebrew/include -I/opt/homebrew/opt/berkeley-db/include" "LDFLAGS=-L/opt/homebrew/lib -L/opt/homebrew/opt/berkeley-db/lib"
    - name: make
      run: make
    - name: make check
      run: make check
    - name: make install
      run: sudo make install

  freebsd-build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Set-up VM
      uses: vmactions/freebsd-vm@v1
      with:
        sync: nfs
        usesh: true
        prepare: |
          pkg install -y devel/autoconf devel/automake devel/shapelib devel/pcre2 graphics/GraphicsMagick graphics/libgeotiff ftp/curl databases/db18 lang/gcc13 x11-toolkits/open-motif audio/festival devel/libcjson lang/gcc14
    - name: Bootstrap
      shell: freebsd {0}
      run: |
        cd $GITHUB_WORKSPACE
        autoreconf -i
    - name: configure out-of-source gcc13
      shell: freebsd {0}
      run: |
        cd $GITHUB_WORKSPACE
        cd ..
        mkdir build
        cd build
        ../Xastir/configure --with-bdb-incdir=/usr/local/include/db18 --with-bdb-libdir=/usr/local/lib CFLAGS="-O2 -g" CC=gcc13 CXX=g++13
    - name: configure out-of-source gcc14
      shell: freebsd {0}
      run: |
        cd $GITHUB_WORKSPACE
        cd ..
        mkdir build-gcc14
        cd build-gcc14
        ../Xastir/configure --with-bdb-incdir=/usr/local/include/db18 --with-bdb-libdir=/usr/local/lib CFLAGS="-O2 -g" CC=gcc13 CXX=g++14
    - name: make gcc13
      shell: freebsd {0}
      run: |
        cd $GITHUB_WORKSPACE/../build
        make
    - name: make gcc14
      shell: freebsd {0}
      run: |
        cd $GITHUB_WORKSPACE/../build-gcc14
        make
    - name: make check gcc13
      shell: freebsd {0}
      run: |
        cd $GITHUB_WORKSPACE/../build
        make check
    - name: make check gcc14
      shell: freebsd {0}
      run: |
        cd $GITHUB_WORKSPACE/../build-gcc14
        make check
