name: ci

on:
  pull_request:
    branches: [ master ]
  workflow_dispatch:

permissions: read-all

jobs:
  linux_autotools:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: autoreconf
      run:  autoreconf -vif
    - name: configure
      run:  ./configure --enable-dwarfexample
    - name: make -j
      run:  make
    - name: make -j check
      run:  make check
    - name: make distcheck
      run:  make distcheck
  linux_cmake:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Install cmake
      run: |
        sudo apt-get -qq update
        sudo apt install build-essential cmake
    - name: Build libdwarf
      run: |
        mkdir builddir && cd builddir
        cmake -G "Unix Makefiles" -DDO_TESTING=ON -DBUILD_DWARFEXAMPLE=ON ../CMakeLists.txt
        make
        ctest -R self

  linux_meson:
    runs-on: ubuntu-latest
    steps:  
    - uses: actions/checkout@v4
    - name: Install meson / ninja
      run: |
        sudo apt-get -qq update
        sudo apt install build-essential meson ninja-build python3-pip python3-setuptools
        pip3 install --upgrade pip
        pip3 install meson --user
    - name: Install doxygen
      run: | 
        sudo apt install doxygen
    - name: Build libdwarf
      run: |
        mkdir builddir && cd builddir
        meson setup -Ddwarfexample=true . ..
        ninja
        ninja test                       

  freebsd_autotools:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: FreeBSD-with-autotools
        uses: cross-platform-actions/action@v0.23.0
        with:
          operating_system: freebsd
          sync_files: runner-to-vm
          version:  '14.0'
          run: |
            uname -a
            whoami
            freebsd-version
            echo $SHELL
            sudo pkg install -y python3 bash automake pkgconf
            sudo pkg install -y libtool gmake binutils lzlib
            autoreconf --warnings=all  -vif
            ./configure
            make
            make check

  freebsd_cmake:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: FreeBSD-with-cmake
        uses: cross-platform-actions/action@v0.23.0
        with:
          operating_system: freebsd
          sync_files: runner-to-vm
          version:  '14.0'
          run: |
            uname -a
            freebsd-version
            echo $SHELL
            sudo pkg install -y python3 bash cmake ninja pkgconf
            sudo pkg install -y gmake binutils lzlib
            mkdir builddir && cd builddir
            cmake -G Ninja -DDO_TESTING=YES -DBUILD_NON_SHARED=YES -DBUILD_SHARED=NO -DBUILD_DWARFEXAMPLE=ON ../CMakeLists.txt
            ninja
            ninja test

  freebsd_meson:
    runs-on: ubuntu-latest
    name: FreeBSD-with-meson
    steps:
    - uses: actions/checkout@v4
    - name: FreeBSD-meson 
      uses: cross-platform-actions/action@v0.23.0
      with:
        operating_system: freebsd
        sync_files: runner-to-vm
        version:  '14.0'
        run: |
          uname -a
          freebsd-version
          echo $SHELL
          sudo pkg install -y python3 bash meson ninja 
          sudo pkg install -y pkgconf gmake binutils zstd
          mkdir build && cd build
          meson setup -Ddwarfexample=true . ..
          ninja
          ninja test

  macos_autotools:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - name: tools
      run:  brew install automake libtool
    - name: autoreconf
      run: autoreconf --warnings=all  -vif
    - name: config
      run: ./configure --enable-dwarfexample --enable-wall
    - name: make
      run:  |
        make
        make check

  macos_cmake:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - name: brew
      run: brew install cmake ninja
    - name: cmake
      run:  |
        mkdir builddir && cd builddir
        cmake -G Ninja -DDO_TESTING=YES -DBUILD_NON_SHARED=YES -DBUILD_SHARED=NO -DBUILD_DWARFEXAMPLE=ON ../CMakeLists.txt
        ninja
        ninja test

  macos_meson:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - name: brew
      run:  |
        brew install meson ninja
    - name: meson
      run:  |
        mkdir builddir && cd builddir
        meson setup -Ddwarfexample=true . ..
        ninja
        ninja test

  msys2_autotools:
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}
    env:
      PYTHONIOENCODING: "utf-8"
    steps:
    - uses: actions/checkout@v4
    - uses: msys2/setup-msys2@v2
      with:
        msystem: MINGW64
        update: true
        install: base-devel git autoconf automake libtool mingw-w64-x86_64-toolchain mingw-w64-x86_64-zlib
    - name: Configure
      run: autoreconf -vif && ./configure --disable-static --enable-shared
    - name: Build
      run:  make
    - name: Check
      run:  make check
    - name: Distcheck
      run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--disable-static --enable-shared"

  msys2_cmake:
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}
    env:
      PYTHONIOENCODING: "utf-8"
    steps:
    - uses: actions/checkout@v4
    - uses: msys2/setup-msys2@v2
      with:
        msystem: MINGW64
        update: true
        install: base-devel git  mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-zlib mingw-w64-x86_64-doxygen  mingw-w64-x86_64-ninja
    - name: Build libdwarf
      run: |
        mkdir builddir && cd builddir
        cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/c/msys64/usr -DBUILD_DWARFEXAMPLE=ON -DDO_TESTING=ON  -DBUILD_SHARED:BOOL=TRUE -DBUILD_NON_SHARED:BOOL=FALSE ../CMakeLists.txt
        ninja 
        ninja install
        ninja test

  msys2_meson:
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}
    env:
      PYTHONIOENCODING: "utf-8"
    steps:
    - uses: actions/checkout@v4
    - uses: msys2/setup-msys2@v2
      with:
        msystem: MINGW64
        update: true
        install: base-devel git  mingw-w64-x86_64-toolchain mingw-w64-x86_64-python3 mingw-w64-x86_64-python3-pip mingw-w64-x86_64-meson mingw-w64-x86_64-ninja mingw-w64-x86_64-zlib mingw-w64-x86_64-doxygen 
    - name: Build libdwarf
      run: |
        mkdir builddir && cd builddir
        meson setup --default-library shared -Ddwarfexample=true -Ddwarfgen=false . ..
        ninja 
        ninja install
        ninja test
