{% set name = "libhwloc" %}
{% set pname = "hwloc" %}
{% set version = "2.9.3" %}
{% set sha256 = "5985db3a30bbe51234c2cd26ebe4ae9b4c3352ab788b1a464c40c0483bf4de59" %}
{% set build_num = 9 %}

{% if cuda_compiler_version == "None" and ROCM_COMPILATION == "disabled" %}
{% set build_num = build_num + 1000 %}
{% endif %}

package:
  name: {{ name|lower }}
  version: {{ version }}

source:
  url: https://www.open-mpi.org/software/hwloc/v{{ '.'.join(version.split('.')[:2]) }}/downloads/{{ pname }}-{{ version }}.tar.gz
  sha256: {{ sha256 }}

build:
  number: {{ build_num }}
  skip: true  # [win and vc<14]
  skip: true  # [cuda_compiler_version != "None" and win]
  skip: true  # [cuda_compiler_version != "None" and ROCM_COMPILATION == "enabled"]
  skip: true  # [not linux64 and ROCM_COMPILATION == "enabled"]
  string: cuda{{ cuda_compiler_version | replace('.', '') }}_h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version != "None"]
  string: rocm_h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [ROCM_COMPILATION == "enabled"]
  string: default_h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version == "None" and ROCM_COMPILATION == "disabled"]
  run_exports:
    - {{ pin_subpackage(name, max_pin='x.x.x') }}
  # weigh down gpu implementation and give nocuda preference
  track_features:
    - cudatoolkit               # [cuda_compiler_version != "None"]
    - rocm                      # [ROCM_COMPILATION == "enabled"]

requirements:
  build:
    - {{ compiler('cxx') }}
    - {{ compiler('cuda') }}    # [cuda_compiler_version != "None"]
    - pkg-config                # [unix]
    - autotools_clang_conda     # [win]
    - make                      # [unix]
    - automake                  # [unix]
    - libtool                   # [unix]
    - autoconf                  # [unix]
  host:
    - libxml2
    - pthreads-win32            # [win]
    - rocm-smi                  # [linux and cuda_compiler_version == "None" and ROCM_COMPILATION == "enabled"]
  run:
    - libxml2
    - pthreads-win32            # [win]
    - __cuda                    # [cuda_compiler_version != "None"]
    - rocm-smi                  # [linux and cuda_compiler_version == "None" and ROCM_COMPILATION == "enabled"]

test:
  commands:
    - hwloc-ls                                     # [cuda_compiler_version == "None"]
    - test -f ${PREFIX}/lib/libhwloc${SHLIB_EXT}   # [unix]
    - if not exist %LIBRARY_LIB%\hwloc.lib exit 1  # [win]

about:
  home: https://www.open-mpi.org/projects/hwloc/
  license: BSD-3-Clause
  license_file: COPYING
  summary: Portable Hardware Locality (hwloc)
  description: |
    This feedstock builds the hwloc library in the `libhwloc` conda package. Different variants of the package are built:
    * `default` in the build string: Without CUDA or ROCM support, installed by default. Install specifically this version with `conda install libhwloc=*=*default*`.
    * `cuda` in the build string: With CUDA support. Install specifically this version with  `conda install libhwloc=*=*cuda*`
    * `rocm` in the build string: With ROCM support. Install specifically this version with  `conda install libhwloc=*=*rocm*`


extra:
  recipe-maintainers:
    - jan-janssen
    - inducer
    - isuruf
