# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                lalinference
version             4.1.7
revision            0

description         LSC Algorithm Library - Inference
long_description    LIGO Scientific Collaboration Algorithm Library - Inference containing \
                    routines for Bayesian inference data analysis.

checksums           rmd160  39fc353ca7ddceb4ea3f41bfaef3fc094027d3e2 \
                    sha256  82578af17e68240c31da390c80985431af73f8cf2dab052089066f661aa976e2 \
                    size    1017360

depends_lib-append  port:gsl \
                    port:metaio \
                    port:lal \
                    port:lalframe \
                    port:lalmetaio \
                    port:lalsimulation \
                    port:lalburst \
                    port:lalinspiral \
                    port:healpix-c

# add Python dependencies for python subports
if {[string match "py*" ${subport}]} {
    set numbers [regexp -all -inline -- {[0-9]+} ${subport}]
    set v [lindex ${numbers} 0]
    # python, C-library port, and numpy are automatically added below
    depends_lib     port:py${v}-lal \
                    port:py${v}-lalmetaio \
                    port:py${v}-lalsimulation \
                    port:py${v}-lalburst \
                    port:py${v}-lalinspiral \
                    port:py${v}-lalpulsar \
                    port:py${v}-scipy \
                    port:py${v}-lscsoft-glue \
                    port:py${v}-ligo-gracedb \
                    port:py${v}-healpy \
                    port:py${v}-astropy \
                    port:py${v}-matplotlib \
                    port:py${v}-h5py \
                    port:py${v}-shapely
}

# add Octave dependencies for octave subports
if {[string match "octave-*" ${subport}]} {
    # octave, and C-library port are automatically added below
    depends_lib     port:octave-lal \
                    port:octave-lalmetaio \
                    port:octave-lalsimulation \
                    port:octave-lalburst \
                    port:lalinspiral \
                    port:lalpulsar
}

configure.args      --enable-openmp \
                    --disable-help2man

###################################################################
### Everything below this line is common to all LALSuite ports. ###
###################################################################

categories          science
maintainers         nomaintainer
license             GPL-2+

homepage            https://wiki.ligo.org/Computing/DASWG/LALSuite
master_sites        https://software.igwn.org/lscsoft/source/lalsuite
use_xz              yes

depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    port:swig \

# Choose a compiler that supports OpenMP.
compiler.openmp_version 2.5

configure.args-append \
                    --mandir=${prefix}/share/man \
                    --disable-silent-rules \
                    --disable-gcc-flags \
                    --enable-swig-iface \
                    --disable-swig-octave \
                    --disable-swig-python \
                    --disable-python

test.run            yes
test.target         check

# Create subports for each supported Python version
foreach v {312} {
  subport py${v}-${name} {
    set pythonversion   [string index ${v} 0].[string range ${v} 1 end]
    set pythonhome      "${frameworks_dir}/Python.framework/Versions/${pythonversion}"
    set pythondir       "${pythonhome}/lib/python${pythonversion}/site-packages"

    categories-append   python
    description         Python ${pythonversion} bindings for ${description}
    long_description    ${long_description} This package provides Python \
                        ${pythonversion} bindings, modules, and scripts.

    depends_build-append \
                        port:swig-python

    depends_lib-prepend port:python${v} \
                        port:${name} \
                        port:py${v}-numpy

    configure.args-append   PYTHON=${pythonhome}/bin/python${pythonversion}
    configure.args-replace  --disable-python --enable-python
    configure.args-replace  --disable-swig-python --enable-swig-python

    destroot.args-append \
                        pythondir="${pythondir}" \
                        pyexecdir="${pythondir}" \
                        pkgpythondir="${pythondir}/${name}" \
                        pkgpyexecdir="${pythondir}/${name}" \
                        prefix="${pythonhome}"

    # Only install SWIG bindings, Python libraries, and Python scripts
    destroot {
      command_exec destroot "" "-C swig"
      command_exec destroot "" "-C python"
    }

    post-destroot {
      # Remove Python include directory
      # (duplicate of SWIG headers in ${prefix}/include)
      file delete -force ${destroot}${pythonhome}/include

      file delete -force ${destroot}/${pythondir}/ligo/__pycache__

      if {[file exists ${pythondir}/ligo/__init__.py]} {
          file delete -force ${destroot}/${pythondir}/ligo/__init__.py
      }
    }
  }
}

subport octave-${name} {
  set pythonversion     [string index ${v} 0].[string range ${v} 1 end]
  set pythonhome        "${frameworks_dir}/Python.framework/Versions/${pythonversion}"
  set pythondir         "${pythonhome}/lib/python${pythonversion}/site-packages"

  categories-append     octave
  description           Octave ${pythonversion} bindings for ${description}
  long_description      ${long_description} This package provides Octave \
                        bindings, modules, and scripts.

  depends_build-append  port:swig-octave

  depends_lib-prepend   port:octave \
                        port:${name}

  configure.args-replace --disable-swig-octave --enable-swig-octave

  # Only install SWIG bindings, Python libraries, and Python scripts
  destroot {
    command_exec destroot "" "-C swig"
  }

  post-destroot {
    # Remove Octave include directory
    # (duplicate of SWIG headers in ${prefix}/include)
    file delete -force ${destroot}${prefix}/include
  }
}

if {${name} eq ${subport}} {
  livecheck.type        regex
  livecheck.url         ${master_sites}
  livecheck.regex       ${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}
} else {
  livecheck.type        none
}
