{% set version = "3.9.0" %}
# if build_num is reset to 0 (for new version), update increment for blas_minor below
{% set build_num = 5 %}
{% set version_major = version.split(".")[0] %}
# blas_major denotes major infrastructural change to how blas is managed
{% set blas_major = "2" %}
# make sure we do not create colliding version strings of output "blas"
# for builds across lapack-versions within the same blas_major
{% set blas_minor = build_num + 100 %}

{% if unix %}
{% set library = "" %}
{% else %}
{% set library = "Library/" %}
{% endif %}

package:
  name: blas-split
  version: {{ version }}

source:
  url: https://github.com/Reference-LAPACK/lapack/archive/v{{ version }}.tar.gz
  sha256: 106087f1bb5f46afdfba7f569d0cbe23dacb9a07cd24733765a0e89dbe1ad573
  patches:
    # Avoid setting current_version and compatibility_version
    - patches/0001-Avoid-setting-current_version-and-compatibility_vers.patch  # [osx]
    #
    # carry upstream patches for build errors/bugs; these can all be removed upon next release
    # ===FIX BUILD ERRORS===
    # restore deprecated symbols that were inadvertently removed (from Reference-LAPACK/lapack#367);
    # squashed with fix-ups Reference-LAPACK/lapack#434 & #437 (cf. xianyi/OpenBLAS#2808 & #2819)
    - patches/0002-Restore-missing-prototypes-for-deprecated-LAPACK-fun.patch
    # fix compile errors due to trying to cast complex_float to int (from Reference-LAPACK/lapack#370)
    - patches/0003-Fix-MinGW-build-error.patch
    # ===OTHER BUG FIXES===
    # from Reference-LAPACK/lapack#390, see also xianyi/OpenBLAS#2442
    - patches/0004-NaN-not-propagating-in-DCOMBSSQ-and-SCOMBSSQ.patch
    # from Reference-LAPACK/lapack#408, see also xianyi/OpenBLAS#2635
    - patches/0005-Fix-the-loop-index-scalar-in-ZHEEQUB.f.patch
    # from Reference-LAPACK/lapack#436, see also xianyi/OpenBLAS#2817
    - patches/0006-Fix-some-minor-inconsistencies-in-LAPACK-E-_-cz-gesv.patch
    # from Reference-LAPACK/lapack#443, see also xianyi/OpenBLAS#2845
    - patches/0007-fix-workspace-query-in-dgelq.patch
    # from Reference-LAPACK/lapack#445, see also xianyi/OpenBLAS#2864
    - patches/0008-fix-dlanv2.patch

build:
  number: "{{ build_num }}"

requirements:
  build:
    - {{ compiler("c") }}               # [unix]
    - {{ compiler("fortran") }}         # [unix]
    - {{ compiler("m2w64_c") }}         # [win]
    - {{ compiler("m2w64_fortran") }}   # [win]
    # This is just for creating the import libaries
    - vs2017_win-64                     # [win64]
    - m2w64-make                        # [win]
    - make
    - cmake

outputs:
  - name: libblas
    build:
      string: "{{ build_num }}_h{{ PKG_HASH }}_netlib"
      track_features:
       - blas_netlib
      run_exports:
        - {{ pin_subpackage("libblas", max_pin="x") }}
    requirements:
      build:
        - {{ compiler("c") }}               # [unix]
        - {{ compiler("fortran") }}         # [unix]
        - {{ compiler("m2w64_c") }}         # [win]
        - {{ compiler("m2w64_fortran") }}   # [win]
      run_constrained:
        - blas * netlib
    files:
      - {{ library }}lib/pkgconfig/blas.pc
      - {{ library }}lib/cmake/blas-{{ version }}/*.cmake
      - lib/libblas.so                          # [linux]
      - lib/libblas.so.{{ version_major }}      # [linux]
      - lib/libblas.so.{{ version }}            # [linux]
      - lib/libblas.dylib                       # [osx]
      - lib/libblas.{{ version_major }}.dylib   # [osx]
      - lib/libblas.{{ version }}.dylib         # [osx]
      - Library/bin/libblas.dll                 # [win]
      - Library/lib/blas.lib                    # [win]
      - Library/lib/libblas.dll.a               # [win]

  - name: libtmglib
    build:
      string: "{{ build_num }}_h{{ PKG_HASH }}_netlib"
      track_features:
       - blas_netlib
      run_exports:
        - {{ pin_subpackage("libtmglib", max_pin="x") }}
    requirements:
      build:
        - {{ compiler("c") }}               # [unix]
        - {{ compiler("fortran") }}         # [unix]
        - {{ compiler("m2w64_c") }}         # [win]
        - {{ compiler("m2w64_fortran") }}   # [win]
      run_constrained:
        - blas * netlib
    files:
      - lib/libtmglib.so                          # [linux]
      - lib/libtmglib.so.{{ version_major }}      # [linux]
      - lib/libtmglib.so.{{ version }}            # [linux]
      - lib/libtmglib.dylib                       # [osx]
      - lib/libtmglib.{{ version_major }}.dylib   # [osx]
      - lib/libtmglib.{{ version }}.dylib         # [osx]
      - Library/bin/libtmglib.dll                 # [win]
      - Library/lib/libtmglib.dll.a               # [win]

  - name: libcblas
    build:
      string: "{{ build_num }}_h{{ PKG_HASH }}_netlib"
      track_features:
        - blas_netlib
      run_exports:
        - {{ pin_subpackage("libcblas", max_pin="x") }}
    requirements:
      build:
        - {{ compiler("c") }}               # [unix]
        - {{ compiler("fortran") }}         # [unix]
        - {{ compiler("m2w64_c") }}         # [win]
        - {{ compiler("m2w64_fortran") }}   # [win]
      run:
        - libblas {{ version }}.*
    files:
      - {{ library }}include/cblas*.h
      - {{ library }}lib/pkgconfig/cblas.pc
      - {{ library }}lib/cmake/cblas-{{ version }}/*.cmake
      - lib/libcblas.so                          # [linux]
      - lib/libcblas.so.{{ version_major }}      # [linux]
      - lib/libcblas.so.{{ version }}            # [linux]
      - lib/libcblas.dylib                       # [osx]
      - lib/libcblas.{{ version_major }}.dylib   # [osx]
      - lib/libcblas.{{ version }}.dylib         # [osx]
      - Library/bin/libcblas.dll                 # [win]
      - Library/lib/cblas.lib                    # [win]
      - Library/lib/libcblas.dll.a               # [win]

  - name: liblapack
    build:
      string: "{{ build_num }}_h{{ PKG_HASH }}_netlib"
      track_features:
        - blas_netlib
      run_exports:
        - {{ pin_subpackage("liblapack", max_pin="x") }}
    requirements:
      build:
        - {{ compiler("c") }}               # [unix]
        - {{ compiler("fortran") }}         # [unix]
        - {{ compiler("m2w64_c") }}         # [win]
        - {{ compiler("m2w64_fortran") }}   # [win]
      run:
        - libblas {{ version }}.*
    files:
      - {{ library }}lib/pkgconfig/lapack.pc
      - {{ library }}lib/cmake/lapack-{{ version }}/*.cmake
      - lib/liblapack.so                          # [linux]
      - lib/liblapack.so.{{ version_major }}      # [linux]
      - lib/liblapack.so.{{ version }}            # [linux]
      - lib/liblapack.dylib                       # [osx]
      - lib/liblapack.{{ version_major }}.dylib   # [osx]
      - lib/liblapack.{{ version }}.dylib         # [osx]
      - Library/bin/liblapack.dll                 # [win]
      - Library/lib/lapack.lib                    # [win]
      - Library/lib/liblapack.dll.a               # [win]

  - name: liblapacke
    build:
      string: "{{ build_num }}_h{{ PKG_HASH }}_netlib"
      track_features:
        - blas_netlib
      run_exports:
        - {{ pin_subpackage("liblapacke", max_pin="x") }}
    requirements:
      build:
        - {{ compiler("c") }}               # [unix]
        - {{ compiler("fortran") }}         # [unix]
        - {{ compiler("m2w64_c") }}         # [win]
        - {{ compiler("m2w64_fortran") }}   # [win]
      run:
        - libblas    {{ version }}.*
        - libcblas   {{ version }}.*
        - liblapack  {{ version }}.*
    files:
      - {{ library }}include/lapack*.h
      - {{ library }}lib/pkgconfig/lapacke.pc
      - {{ library }}lib/cmake/lapacke-{{ version }}/*.cmake
      - lib/liblapacke.so                          # [linux]
      - lib/liblapacke.so.{{ version_major }}      # [linux]
      - lib/liblapacke.so.{{ version }}            # [linux]
      - lib/liblapacke.dylib                       # [osx]
      - lib/liblapacke.{{ version_major }}.dylib   # [osx]
      - lib/liblapacke.{{ version }}.dylib         # [osx]
      - Library/bin/liblapacke.dll                 # [win]
      - Library/lib/lapacke.lib                    # [win]
      - Library/lib/liblapacke.dll.a               # [win]

  - name: blas-devel
    build:
      string: "{{ build_num }}_netlib"
      track_features:
       - blas_netlib
    requirements:
      run:
        - {{ pin_subpackage("libblas", exact=True) }}
        - {{ pin_subpackage("libcblas", exact=True) }}
        - {{ pin_subpackage("liblapack", exact=True) }}
        - {{ pin_subpackage("liblapacke", exact=True) }}

  # For conda-forge blas selector, see also blas-feedstock
  - name: blas
    version: "{{ blas_major }}.{{ blas_minor }}"
    build:
      string: "netlib"
      track_features:
       - blas_netlib
    requirements:
    - {{ pin_subpackage("liblapack", exact=True) }}
    - {{ pin_subpackage("liblapacke", exact=True) }}
    - {{ pin_subpackage("libcblas", exact=True) }}
    - {{ pin_subpackage("libblas", exact=True) }}
    - {{ pin_subpackage("blas-devel", exact=True) }}
    - {{ pin_subpackage("libtmglib", exact=True) }}
    test:
      commands:
        {% for each_lib in ['blas', 'cblas', 'lapack', 'lapacke'] %}
        - test -f $PREFIX/lib/lib{{ each_lib }}.so                          # [linux]
        - test -f $PREFIX/lib/lib{{ each_lib }}.so.{{ version_major }}      # [linux]
        - test -f $PREFIX/lib/lib{{ each_lib }}.so.{{ version }}            # [linux]
        - test -f $PREFIX/lib/lib{{ each_lib }}.dylib                       # [osx]
        - test -f $PREFIX/lib/lib{{ each_lib }}.{{ version_major }}.dylib   # [osx]
        - test -f $PREFIX/lib/lib{{ each_lib }}.{{ version }}.dylib         # [osx]
        - test -f $PREFIX/lib/pkgconfig/{{ each_lib }}.pc                   # [unix]
        - if not exist "%LIBRARY_LIB%\\pkgconfig\\{{ each_lib }}.pc" exit 1  # [win]
        - if not exist "%LIBRARY_LIB%\\{{ each_lib }}.lib" exit 1           # [win]
        - if not exist "%LIBRARY_BIN%\\lib{{ each_lib }}.dll" exit 1        # [win]
        {% endfor %}

  # For compatiblity (see #33)
  - name: lapack
    build:
      string: "netlib"
    requirements:
      run:
        - liblapack {{ version }}.*

about:
  home: http://www.netlib.org/lapack
  license: BSD-3-Clause
  license_file: LICENSE
  summary: Linear Algebra PACKage

extra:
  feedstock-name: lapack
  recipe-maintainers:
    - jakirkham
    - isuruf
