name: Makefile

on:
  push:
    branches:
    - master
    - try-github-actions
    paths:
    - .github/workflows/makefile.yml
    - '**Makefile'
    - 'BLAS/**'
    - 'CBLAS/**'
    - 'INSTALL/**'
    - 'LAPACKE/**'
    - 'SRC/**'
    - 'TESTING/**'
    - '!**README'
    - '!**CMakeLists.txt'
    - '!**md'
  pull_request:
    paths:
    - .github/workflows/makefile.yml
    - '**Makefile'
    - 'BLAS/**'
    - 'CBLAS/**'
    - 'INSTALL/**'
    - 'LAPACKE/**'
    - 'SRC/**'
    - 'TESTING/**'
    - '!**README'
    - '!**CMakeLists.txt'
    - '!**md'

permissions:
  contents: read

env:
  CC: "gcc"
  FC: "gfortran"
  CFLAGS: "-O3 -flto -Wall -pedantic-errors"
  FFLAGS: "-O2 -flto -Wall -Werror=conversion -pedantic -fimplicit-none -frecursive -fopenmp -fcheck=all"
  FFLAGS_NOOPT: "-O0 -flto -Wall -fimplicit-none -frecursive -fopenmp -fcheck=all"
  LDFLAGS: ""
  AR: "ar"
  ARFLAGS: "cr"
  RANLIB: "ranlib"

defaults:
  run:
    shell: bash

jobs:

  install-ubuntu:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout LAPACK
      uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
    - name: Set configurations
      run: |
        echo "SHELL = /bin/sh" >> make.inc
        echo "FFLAGS_DRV = ${{env.FFLAGS}}" >> make.inc
        echo "TIMER = INT_ETIME" >> make.inc
        echo "BLASLIB = ${{github.workspace}}/librefblas.a" >> make.inc
        echo "CBLASLIB = ${{github.workspace}}/libcblas.a" >> make.inc
        echo "LAPACKLIB = ${{github.workspace}}/liblapack.a" >> make.inc
        echo "TMGLIB = ${{github.workspace}}/libtmglib.a" >> make.inc
        echo "LAPACKELIB = ${{github.workspace}}/liblapacke.a" >> make.inc
        echo "DOCSDIR = ${{github.workspace}}/DOCS" >> make.inc
    - name: Install
      run: |
        make -s -j2 all
        make -j2 lapack_install

  install-macos:
    runs-on: macos-latest
    steps:
    - name: Checkout LAPACK
      uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
    - name: Set configurations
      run: |
        echo "SHELL = /bin/sh" >> make.inc
        echo "FFLAGS_DRV = ${{env.FFLAGS}}" >> make.inc
        echo "TIMER = INT_ETIME" >> make.inc
        echo "BLASLIB = ${{github.workspace}}/librefblas.a" >> make.inc
        echo "CBLASLIB = ${{github.workspace}}/libcblas.a" >> make.inc
        echo "LAPACKLIB = ${{github.workspace}}/liblapack.a" >> make.inc
        echo "TMGLIB = ${{github.workspace}}/libtmglib.a" >> make.inc
        echo "LAPACKELIB = ${{github.workspace}}/liblapacke.a" >> make.inc
        echo "DOCSDIR = ${{github.workspace}}/DOCS" >> make.inc
    - name: Alias for GCC compilers
      run: |
        sudo ln -s $(which gcc-14) /usr/local/bin/gcc
        sudo ln -s $(which gfortran-14) /usr/local/bin/gfortran
    - name: Install
      run: |
        make -s -j2 all
        make -j2 lapack_install
