name: osx

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

jobs:
  build_osx_autotools_default_args:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    # Brew may not have permission to install its packages
    - name: change brew install folder permissions
      run: sudo chmod -R a+rwx /usr/local/share/ || mkdir -p /usr/local/share/ -m a+rwx
    - name: install maxtex
      run: brew cask install mactex
    - name: install doc programs
      run: brew install texi2html doxygen
    - name: install automake
      run: brew install automake
    - name: install pkg-config
      run: brew install pkgconfig
    - name: create configure
      run: autoreconf -i
    - name: configure
      run: ./configure --disable-timeout-tests
    - name: make
      run: make
    - name: make check
      run: make check
    - name: make install
      run: sudo make install
    
  build_osx_autotools_other_args:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    # Brew may not have permission to install its packages
    - name: change brew install folder permissions
      run: sudo chmod -R a+rwx /usr/local/share/ || mkdir -p /usr/local/share/ -m a+rwx
    - name: install maxtex
      run: brew cask install mactex
    - name: install doc programs
      run: brew install texi2html doxygen
    - name: install automake
      run: brew install automake
    - name: install pkg-config
      run: brew install pkgconfig
    - name: create configure
      run: autoreconf -i
    - name: configure with args
      run: ./configure --disable-fork --disable-subunit --enable-snprintf-replacement --enable-timer-replacement --disable-timeout-tests 
    - name: make
      run: make
    - name: make check
      run: make check
    - name: make install
      run: sudo make install
  
  build_osx_autotools_gcc:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    # Brew may not have permission to install its packages
    - name: change brew install folder permissions
      run: sudo chmod -R a+rwx /usr/local/share/ || mkdir -p /usr/local/share/ -m a+rwx
    - name: install automake
      run: brew install automake
    - name: install pkg-config
      run: brew install pkgconfig
    - name: create configure 
      run: autoreconf -i
    - name: configure gcc
      run: ./configure CC=gcc --enable-snprintf-replacement --enable-timer-replacement --disable-build-docs --disable-timeout-tests
    - name: make
      run: make
    - name: make check
      run: make check

  build_osx_autotools_clang:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    # Brew may not have permission to install its packages
    - name: change brew install folder permissions
      run: sudo chmod -R a+rwx /usr/local/share/ || mkdir -p /usr/local/share/ -m a+rwx
    - name: install automake
      run: brew install automake
    - name: install pkg-config
      run: brew install pkgconfig
    - name: create configure
      run: autoreconf -i
    - name: configure clang
      run: ./configure CC=clang --enable-snprintf-replacement --enable-timer-replacement --disable-build-docs --disable-timeout-tests
    - name: make
      run: make
    - name: make check
      run: make check

  build_osx_autotools_docs:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    # Brew may not have permission to install its packages
    - name: change brew install folder permissions
      run: sudo chmod -R a+rwx /usr/local/share/ || mkdir -p /usr/local/share/ -m a+rwx
    - name: install maxtex
      run: brew cask install mactex
    - name: install doc programs
      run: brew install texi2html doxygen
    - name: install automake
      run: brew install automake
    - name: install pkg-config
      run: brew install pkgconfig
    - name: create configure
      run: autoreconf -i
    - name: configure
      run: ./configure
    - name: make docs
      run: make doc/check_html
    - name: make doxygen 
      run: make doc/doxygen
      
  build_osx_autotools_example:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    # Brew may not have permission to install its packages
    - name: change brew install folder permissions
      run: sudo chmod -R a+rwx /usr/local/share/ || mkdir -p /usr/local/share/ -m a+rwx
    - name: install maxtex
      run: brew cask install mactex
    - name: install doc programs
      run: brew install texi2html doxygen
    - name: install automake
      run: brew install automake
    - name: install pkg-config
      run: brew install pkgconfig
    - name: create configure
      run: autoreconf -i
    - name: configure
      run: ./configure
    - name: make
      run: make
    - name: make install
      run: sudo make install
    - name: create configure example
      working-directory: doc/example
      run: autoreconf -i
    - name: configure example
      working-directory: doc/example
      run: ./configure
    - name: build example
      working-directory: doc/example
      run: make 
    - name: test example
      working-directory: doc/example
      run: make check
    
  build_osx_cmake:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    - name: cmake cversion
      run: cmake --version
    - name: create configs
      run: cmake . -D CHECK_ENABLE_TIMEOUT_TESTS=0
    - name: make
      run: make
    - name: unit tests
      run: ctest -V
    - name: make install 
      run: sudo make install
