# -*- 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
PortGroup     compiler_blacklist_versions 1.0

name          ldas-tools-framecpp
version       2.5.8
revision      2
categories    science
platforms     darwin
maintainers   nomaintainer

description   Suite of LDAS tools
long_description ${description}

homepage      https://wiki.ligo.org/DASWG/LDASTools
master_sites  https://software.igwn.org/lscsoft/source/

checksums     rmd160 575d7c502f5f9555538da2b8c832f04af59ffda2 \
              sha256 4a0dd81baa9df2cd2d1691a4101ac4bf9a81dcbbd2d6f30e33a2c8ec0a7fe138

depends_build  port:pkgconfig
depends_lib    port:ldas-tools-al \
               path:lib/libssl.dylib:openssl \
               port:zlib \
               port:bzip2

configure.args --disable-warnings-as-errors \
               --disable-silent-rules \
               --with-optimization=high \
               --disable-tcl \
               --disable-python \
               --without-doxygen \
               --without-dot \
               --disable-latex

if {${configure.cxx_stdlib} eq "libstdc++" } {
    configure.args-append --disable-cxx11
}

# requires clang from Xcode5 or higher to build
compiler.blacklist-append {clang < 500.2.75} llvm-gcc-4.2 gcc-4.2

use_parallel_build yes

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    known_fail  yes
    pre-fetch {
        ui_error "${name} only runs on Mac OS X 10.7 or greater."
        return -code error "incompatible Mac OS X version"
    }
}

#------------------------------------------------------------------------

livecheck.type   regex
livecheck.url    ${master_sites}
livecheck.regex  {ldas-tools-framecpp-(\d+(?:\.\d+)*).tar.gz}

#========================================================================
# Create subports for each supported Python version
#========================================================================
foreach v {27} {
  set python.version       ${v}
  set python.branch        [string range ${python.version} 0 end-1].[string index ${python.version} end]
  set python.bin           ${prefix}/bin/python${python.branch}
  set python.prefix        ${frameworks_dir}/Python.framework/Versions/${python.branch}
  set python.site_packages "${python.prefix}/lib/python${python.branch}/site-packages"
  set python.pkgname       LDAStools

  subport py${v}-${name} {
    categories-prepend    python
    description           Python ${python.version} bindings for ${description}
    long_description      ${long_description} This package provides Python \
                          ${python.version} bindings, modules, and scripts.

    depends_build-append      port:swig-python
    depends_lib-append        port:${name}
    depends_lib-append        port:py${python.version}-ldas-tools-al
    depends_lib-append        port:python${python.version}

    configure.python          ${python.bin}
    configure.args-replace    PYTHON=false PYTHON=${python.prefix}/bin/python${python.version}
    configure.args-replace    --disable-python --enable-python
    configure.args-append     SWIG_CPPFLAGS="-I${python.prefix}/include"

    destroot.args-append      pythondir="${python.site_packages}" \
                              pyexecdir="${python.site_packages}" \
                              pkgpythondir="${python.site_packages}/${python.pkgname}" \
                              pkgpyexecdir="${python.site_packages}/${python.pkgname}" \
                              -C ${worksrcpath}/swig/python

    post-destroot {
      if {${subport} eq "py27-${name}"} {
        foreach script [glob -tails -nocomplain -directory ${destroot}${python.prefix}/bin *] {
          file link -symbolic ${destroot}${prefix}/bin/${script} ../Library/Frameworks/Python.framework/Versions/${python.version}/bin/${script}
        }
      }
    }

    livecheck.type        none
  }
}