parameters:
- name: checkoutRepo
  type: string
  default: 'self'
- name: checkoutRef
  type: string
  default: ''
- name: lapackVersion
  type: string
  default: ''
- name: aptPackages
  type: object
  default:
    - wget
    - cmake
    - ninja-build
    - gfortran

jobs:
- job: lapack
  variables:
  - group: common
  - template: /.azuredevops/variables-global.yml
  pool:
    vmImage: ${{ variables.BASE_BUILD_POOL }}
  workspace:
    clean: all
  steps:
  - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/dependencies-other.yml
    parameters:
      aptPackages: ${{ parameters.aptPackages }}
  - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/preamble.yml
  - task: Bash@3
    displayName: 'Download lapack Source Code'
    inputs:
      targetType: inline
      script: wget -nv -O lapack-${{ parameters.lapackVersion }}.tar.gz https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v${{ parameters.lapackVersion }}.tar.gz
      workingDirectory: '$(System.ArtifactsDirectory)'
  - task: ExtractFiles@1
    displayName: Extract lapack Source Code
    inputs:
      archiveFilePatterns: '$(System.ArtifactsDirectory)/**/*.tar.gz'
      destinationFolder: '$(Agent.BuildDirectory)'
      cleanDestinationFolder: false
      overwriteExistingFiles: true
  - task: DeleteFiles@1
    displayName: Cleanup Compressed lapack
    inputs:
      SourceFolder: '$(System.ArtifactsDirectory)'
      Contents: '/**/*.tar.gz'
      RemoveDotFiles: true
  - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/build-cmake.yml
    parameters:
      cmakeBuildDir: $(Agent.BuildDirectory)/lapack-${{ parameters.lapackVersion }}/build
      extraBuildFlags: >-
        -DCMAKE_BUILD_TYPE=Release
        -DCMAKE_Fortran_COMPILER=gfortran
        -DCMAKE_Fortran_FLAGS=-fno-optimize-sibling-calls
        -DBUILD_TESTING=OFF
        -DCBLAS=ON
        -DLAPACKE=OFF
        -GNinja
  - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/artifact-upload.yml
