{% set version = "1.14.5" %}
{% set maj_min_ver = ".".join(version.split(".")[:2]) %}

package:
  name: hdf5
  version: {{ version }}

source:
  url: https://github.com/HDFGroup/hdf5/releases/download/hdf5_{{ version }}/hdf5-{{ version }}.tar.gz
  sha256: ec2e13c52e60f9a01491bb3158cb3778c985697131fc6a342262d32a26e58e44

build:
  number: 2
  run_exports:
    # hdf5 has historically broken API between bugfix revisions.  Pin it to be safe.
    #    This pinning is using the implicitly defined output for the top-level recipe.
    #    We use pin_subpackage here so that we have more control over the pinning.
    - {{ pin_subpackage('hdf5', min_pin='x.x.x', max_pin='x.x.x') }}

requirements:
  build:
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - {{ compiler('fortran') }}
    - make  # [linux]
    - cmake >=3.1 
  host:
    - zlib {{ zlib }}
    - libcurl 7.88.1  # [not win]
    - openssl {{ openssl }}  # [not win]
    - libgfortran5 11.2.0  # [unix]
  run:
    - openssl 3.*  # [not win]

# no explicit run deps.  zlib is one, and C/C++/Fortran runtimes are others, but these are taken care of
#   with conda-build 3's run_exports in those packages.  They will be run reqs in the final package.  See
#   for yourself by running conda render on this recipe.

test:
  requires:
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - {{ compiler('fortran') }}
    - pkg-config  # [not win]
  files:
    - h5_cmprss.c
    - h5tutr_cmprss.cpp
    - h5_cmprss.f90
    - compound_fortran2003.f90

  commands:
    # Verify UNIX CLI tools.
    {% set hdf5_unix_cmds = [
        "h5c++",
        "h5cc",
        "h5perf_serial",
        "h5fc"
    ] %}
    {% for each_hdf5_unix_cmd in hdf5_unix_cmds %}
    - command -v {{ each_hdf5_unix_cmd }}   # [unix]
    {% endfor %}

    # Verify CLI tools.
    {% set hdf5_cmds = [
        "h5copy",
        "h5debug",
        "h5diff",
        "h5dump",
        "h5import",
        "h5jam",
        "h5ls",
        "h5mkgrp",
        "h5repack",
        "h5repart",
        "h5stat",
        "h5unjam"
    ] %}
    {% for each_hdf5_cmd in hdf5_cmds %}
    - command -v {{ each_hdf5_cmd }}        # [unix]
    - where {{ each_hdf5_cmd }}             # [win]
    {% endfor %}

    # Verify libraries.
    {% set hdf5_libs = [
        "hdf5",
        "hdf5_cpp",
        "hdf5_hl",
        "hdf5_hl_cpp",
    ] %}
    {% for each_hdf5_lib in hdf5_libs %}
    - test -f $PREFIX/lib/lib{{ each_hdf5_lib }}.a                           # [unix]
    - test -f $PREFIX/lib/lib{{ each_hdf5_lib }}.dylib                       # [osx]
    - test -f $PREFIX/lib/lib{{ each_hdf5_lib }}.so                          # [linux]
    - if not exist %PREFIX%\\Library\\lib\\{{ each_hdf5_lib }}.lib exit 1    # [win]
    - if not exist %PREFIX%\\Library\\bin\\{{ each_hdf5_lib }}.dll exit 1    # [win]
    {% endfor %}

    # Inspect linkages of HDF5.
    {% for each_hdf5_lib in hdf5_libs %}
    - otool -L $PREFIX/lib/lib{{ each_hdf5_lib }}.dylib                      # [osx]
    {% endfor %}

    # Test C compiler
    - echo "Testing h5cc"            # [unix]
    - h5cc -show                     # [unix]
    - h5cc h5_cmprss.c -o h5_cmprss  # [unix]
    - export DYLD_LIBRARY_PATH=$PREFIX/lib:$DYLD_LIBRARY_PATH  # [osx]
    - export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH      # [linux]
    - ./h5_cmprss                    # [unix]

    # Test C++ compiler
    - echo "Testing h5c++"                      # [unix]
    - h5c++ -show                               # [unix]
    - h5c++ h5tutr_cmprss.cpp -o h5tutr_cmprss  # [unix]
    - ./h5tutr_cmprss                           # [unix]

    # Test Fortran 90 compiler
    - echo "Testing h5fc"              # [unix]
    - h5fc -show                       # [unix]
    - h5fc h5_cmprss.f90 -o h5_cmprss  # [unix]
    - ./h5_cmprss                      # [unix]

    # Test Fortran 2003 compiler, note that the file has a 90 extension
    - echo "Testing h5fc for Fortran 2003"                   # [unix]
    - h5fc compound_fortran2003.f90 -o compound_fortran2003  # [unix]
    - ./compound_fortran2003                                 # [unix]

about:
  home: https://www.hdfgroup.org/solutions/hdf5/
  license: OTHER
  license_family: BSD
  license_file:
    - COPYING
    - COPYING_LBNL_HDF5
  summary: HDF5 is a data model, library, and file format for storing and managing data
  description: |
    HDF5 supports an unlimited variety of datatypes, and is designed for
    flexible and efficient I/O and for high volume and complex data.
  doc_url: https://support.hdfgroup.org/documentation/index.html
  dev_url: https://github.com/HDFGroup/hdf5

extra:
  recipe-maintainers:
    - jakirkham
    - gillins
    - groutr
    - ocefpaf
    - astrofrog
    - marqh
    - msarahan
