name: autotools

on:
  push:
    branches: [ "master", "devel", "citest", "citest-autotools" ]
    tags:
      - '**'
  pull_request:
    branches: [ "master", "devel" ]

jobs:
  ubuntu:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        conf_options: [ "", --enable-native-generic ]
    steps:
    - uses: actions/checkout@v4
    - name: install prereq.
      run: sudo apt-get update ; sudo apt-get install -y check
    - name: autogen
      run: ./autogen.sh
    - name: configure
      run: ./configure ${{ matrix.conf_options }}
    - name: make
      run: make
    - name: make check
      run: make check
    - name: make distcheck
      run: make distcheck
    - name: make install
      run: sudo make install
    - name: check installation
      run: find /usr/local -iname '*adf*'
    - name: update ldconfig
      run: sudo ldconfig
    - name: test installed command-line utils
      run: ./examples/tests/test-all-examples.sh /usr/local/bin
    - name: store logs from failed tests
      if: failure()
      uses: actions/upload-artifact@v4
      with:
        name: ubuntu_autotools_logs_failed_tests
        path: |
          examples/tests/*.log
          regtests/Test/*.log
          tests/*.log

  cygwin:
    runs-on: windows-latest
    defaults:
      run:
        shell: C:\cygwin\bin\bash.exe '{0}'
#    env:
#      SHELLOPTS: igncr
    steps:
    - name: setup git (eol)
#      shell: powershell
      shell: cmd
      run: |
        git config --global core.autocrlf false
#        git config --global core.eol lf
    - uses: actions/checkout@v4
    - uses: cygwin/cygwin-install-action@v4
      with:
        site: https://sunsite.icm.edu.pl/pub/cygnus/cygwin/
        packages: autoconf automake check diffutils findutils gcc-core grep gzip libtool make sed tar
    - name: autogen
      run: ./autogen.sh
    - name: configure
      run: ./configure --prefix=/tmp/adflib
    - name: make
      run: make
    - name: make check
      run: make check
    - name: make distcheck
      run: make distcheck
    - name: make install
      run: make install
    - name: check installation
      run: find /tmp/adflib -iname '*adf*'
    - name: test installed command-line utils
      run: ./examples/tests/test-all-examples.sh /tmp/adflib/bin
    - name: store logs from failed tests
      if: failure()
      uses: actions/upload-artifact@v4
      with:
        name: cygwin_autotools_native_logs_failed_tests
        path: |
          examples/tests/*.log
          regtests/Test/*.log
          tests/*.log
#          C:\cygwin\var\log\setup.log.full

  msys2:
#    if: false
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 '{0}'
    steps:
    - uses: actions/checkout@v4
    - uses: msys2/setup-msys2@v2.22.0
      with:
        update: true
        install: autotools diffutils mingw-w64-x86_64-check mingw-w64-x86_64-toolchain
    - name: autogen
      run: ./autogen.sh
    - name: configure
      run: ./configure --prefix=/tmp/adflib
    - name: make
      run: make
    - name: make check
      #run: ( make check || grep . examples/*.log examples/tests/*.log )
      run: make check
    - name: make distcheck
      run: make distcheck
    - name: make install
      run: make install
    - name: check installation
      run: find /tmp/adflib -iname '*adf*'
    - name: test installed command-line utils
      run: ./examples/tests/test-all-examples.sh /tmp/adflib/bin
    - name: store logs from failed tests
      if: failure()
      uses: actions/upload-artifact@v4
      with:
        name: msys2_autotools_logs_failed_tests
        path: |
          examples/tests/*.log
          regtests/Test/*.log
          tests/*.log

  macos:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - name: install prereq.
      run: brew install automake check libtool
    - name: autogen
      run: ./autogen.sh
    - name: configure
      run: ./configure
    - name: make
      run: make
    - name: make check
      run: ( make check || grep .  regtests/Test/*.log )
    - name: make distcheck
      run: make distcheck
    - name: make install
      run: sudo make install
    - name: check installation
      run: find /usr/local/ -iname '*adf*'
    - name: test installed command-line utils
      run: ./examples/tests/test-all-examples.sh /usr/local/bin
    - name: store logs from failed tests
      if: failure()
      uses: actions/upload-artifact@v4
      with:
        name: macos_autotools_native_logs_failed_tests
        path: |
          examples/tests/*.log
          regtests/Test/*.log
          tests/*.log
