{% set version = "4.1.6" %}
{% set major = version.rpartition('.')[0] %}
{% set build = 1 %}

# give conda package a higher build number
{% if mpi_type == 'conda' %}
{% set build = build + 100 %}
{% endif %}

package:
  # must not match any outputs for requirements to be handled correctly
  name: openmpi-mpi
  version: {{ version }}

source:
  fn: openmpi-{{ version }}.tar.bz2
  url: https://www.open-mpi.org/software/ompi/v{{ major }}/downloads/openmpi-{{ version }}.tar.bz2
  sha256: f740994485516deb63b5311af122c265179f5328a0d857a567b85db00b11e415

build:
  number: {{ build }}
  skip: true  # [win]

outputs:
  {% if mpi_type == 'conda' %}
  - name: openmpi
    script: build-mpi.sh
    build:
      run_exports:
        - {{ pin_subpackage('openmpi', min_pin='x.x.x', max_pin='x') }}
      ignore_run_exports:
        - ucx  # [enable_cuda]
      script_env:
        - CUDA_HOME     # [enable_cuda]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - {{ compiler('fortran') }}
        - autoconf  # [unix]
        - automake  # [unix]
        - libtool   # [unix]
        - make  # [unix]
        - perl 5.26.2
      host:
        - zlib
        - ucx                 # [enable_cuda]
        - ucx-proc =*=gpu     # [enable_cuda]
      run:
        - zlib
        - mpi 1.0 openmpi
      run_constrained:
        - cudatoolkit  >= {{ cudatoolkit }}         # [enable_cuda]
        - {{ pin_compatible("ucx", max_pin="x") }}  # [enable_cuda]
    test:
      script: run_test.sh
      files:
        - mpiexec.sh
        - tests/helloworld.sh

  - name: openmpi-mpicc
    build:
      script:
        - echo 'ok'  # [not osx]
        # make CONDA_BUILD_SYSROOT a 'used variable'
        # so that conda-build knows to pass it to the test env
        - echo "{{ CONDA_BUILD_SYSROOT }}"  # [osx]
    requirements:
      run:
        - {{ pin_subpackage('openmpi', exact=True) }}
        # host C compilers work fine (better) on mac
        - {{ compiler('c') }}
    test:
      script: run_test.sh
      files:
        - mpiexec.sh
        - tests/helloworld.c

  - name: openmpi-mpicxx
    build:
      script:
        - echo 'ok'  # [not osx]
        # make CONDA_BUILD_SYSROOT a 'used variable'
        # so that conda-build knows to pass it to the test env
        - echo "{{ CONDA_BUILD_SYSROOT }}"  # [osx]
    requirements:
      run:
        - {{ pin_subpackage('openmpi', exact=True) }}
        # host C compilers work fine (better) on mac
        - {{ compiler('cxx') }}
    test:
      script: run_test.sh
      files:
        - mpiexec.sh
        - tests/helloworld.cxx

  - name: openmpi-mpifort
    build:
      script:
        - echo 'ok'  # [not osx]
        # make CONDA_BUILD_SYSROOT a 'used variable'
        # so that conda-build knows to pass it to the test env
        - echo "{{ CONDA_BUILD_SYSROOT }}"  # [osx]
    requirements:
      run:
        - {{ pin_subpackage('openmpi', exact=True) }}
        - {{ compiler('fortran') }}
    test:
      script: run_test.sh
      files:
        - mpiexec.sh
        - tests/helloworld.f
        - tests/helloworld.f90
  {% else %}
  - name: openmpi
    build:
      string: {{ mpi_type }}_{{ build }}
      track_features:
        - openmpi_{{ mpi_type }}
    requirements:
      host: []
      run:
        - mpi 1.0 openmpi
    test:
      commands:
        - echo "It works!"
  {% endif %}

about:
  home: https://www.open-mpi.org/
  license: BSD-3-Clause
  license_family: BSD
  license_file: LICENSE
  summary: An open source Message Passing Interface implementation.
  description: |
    The Open MPI Project is an open source Message Passing Interface
    implementation that is developed and maintained by a consortium of academic,
    research, and industry partners.
  doc_url: https://www.open-mpi.org/doc/
  dev_url: https://github.com/open-mpi/ompi

extra:
  recipe-maintainers:
    - astrofrog
    - bekozi
    - dalcinl
    - leofang
    - minrk
    - msarahan
    - ocefpaf
    - beckermr
