distributable:
  url: https://download.open-mpi.org/release/open-mpi/v{{version.marketing}}/openmpi-{{version}}.tar.bz2
  strip-components: 1

versions:
  github: open-mpi/ompi/tags

dependencies:
  open-mpi.org/hwloc: '*'
  libevent.org: '*'
  gnu.org/gcc: '*' # for gfortran
  gnu.org/inetutils: '*' # for rsh

runtime:
  env:
    OPAL_PREFIX: '{{prefix}}'
    OMPI_CC: gcc
    OMPI_CXX: g++
    OMPI_FC: gfortran
    OMPI_CFLAGS: $CFLAGS
    OMPI_CXXFLAGS: $CXXFLAGS
    OMPI_FCFLAGS: $FCFLAGS -I{{prefix}}/include
    OMPI_CPPFLAGS: $CPPFLAGS
    OMPI_LDFLAGS: $LDFLAGS
    OMPI_F77FLAGS: $FCFLAGS -I{{prefix}}/include
    OMPI_F90FLAGS: $FCFLAGS -I{{prefix}}/include

build:
  dependencies:
    gnu.org/binutils: '*' # needed to compile
  script:
    - ./configure $CONFIGURE_ARGS
    - make --jobs {{ hw.concurrency }} all
    - make --jobs {{ hw.concurrency }} install
    - run: |
        sed -i.bak "s|$PKGX_DIR|\${pcfiledir}/../../../..|g" ompi-c.pc ompi-cxx.pc ompi-fort.pc ompi.pc orte.pc pmix.pc
        rm ./*.bak
      working-directory: '{{prefix}}/lib/pkgconfig'
    - run: |
        sed -i.bak "s|linker_flags=.*|linker_flags=|g" mpic++-wrapper-data.txt mpicc-wrapper-data.txt mpifort-wrapper-data.txt ortecc-wrapper-data.txt
        rm ./*.bak
      working-directory: '{{prefix}}/share/openmpi'
    - install {{prefix}}/lib/*.mod {{prefix}}/include/
  env:
    CXXFLAGS: -std=c++11
    CONFIGURE_ARGS:
      - --disable-debug
      - --disable-dependency-tracking
      - --prefix="{{prefix}}"
      - --libdir="{{prefix}}/lib"
      - --disable-silent-rules
      - --enable-ipv6
      - --enable-mca-no-build=reachable-netlink
      - --sysconfdir="{{prefix}}/etc"
      - --with-libevent="{{deps.libevent.org.prefix}}"
      - --with-sge
      - --disable-dlopen

provides:
  - bin/mpic++
  - bin/mpiCC
  - bin/mpicc
  - bin/mpicxx
  - bin/mpiexec
  - bin/mpif77
  - bin/mpif90
  - bin/mpifort
  - bin/mpirun
  - bin/ompi-clean
  - bin/ompi_info
  - bin/ompi-server
  - bin/opal_wrapper
  - bin/ortecc
  - bin/orte-clean
  - bin/orted
  - bin/orte-info
  - bin/orterun
  - bin/orte-server

test:
  dependencies:
    freedesktop.org/pkg-config: '*'
  script:
    - mpicc hello.c -o hello
    - ./hello
    - mpirun ./hello
    - mpifort hellof.f90 -o hellof
    - ./hellof
    - mpirun ./hellof
    - mpifort hellousempi.f90 -o hellousempi
    - ./hellousempi
    - mpirun ./hellousempi
    - mpifort hellousempif08.f90 -o hellousempif08
    - ./hellousempif08
    - mpirun ./hellousempif08
    - pkg-config --modversion ompi
  env:
    linux/x86-64: # GHA hosts run as root
      OMPI_ALLOW_RUN_AS_ROOT: 1
      OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1
