# -*- 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           cmake 1.1
PortGroup           compilers 1.0
PortGroup           github 1.0
PortGroup           linear_algebra 1.0
PortGroup           mpi 1.0

github.setup        liuyangzhuan ButterflyPACK 3.2.0 v
name                bpack
revision            0
categories          math science
license             BSD
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         ButterflyPACK is a mathematical software \
                    for rapidly solving large-scale dense linear systems \
                    that exhibit off-diagonal rank-deficiency
long_description    {*}${description}
homepage            https://portal.nersc.gov/project/sparse/butterflypack
checksums           rmd160  0e0e4314363137e12905f03753c87b79dbb6d9eb \
                    sha256  0f1570947f0a7c0e130bbec3abbb2fa275ae453dc3f428e7a3a2265fecafe1ae \
                    size    381791382
github.tarball_from archive

depends_build-append \
                    path:bin/pkg-config:pkgconfig
depends_lib-append  port:scalapack \
                    port:zfp

if {${os.platform} eq "darwin" && ${os.arch} eq "powerpc"} {
    mpi.setup       require require_fortran \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 -gcc6 \
                    -clang -fortran
} else {
    mpi.setup       require require_fortran \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 -gcc6
}

# https://github.com/liuyangzhuan/ButterflyPACK/issues/14
patchfiles          patch-examples.diff \
                    patch-includes.diff

compiler.cxx_standard   2011
compiler.openmp_version 4.0
compilers.allow_arguments_mismatch yes

pre-configure {
    # Need to set these explicitly: https://github.com/liuyangzhuan/ButterflyPACK/issues/17
    configure.args-append \
                    -DMPIEXEC_EXECUTABLE=${prefix}/bin/${mpi.exec} \
                    -DMPI_C_COMPILER=${prefix}/bin/${mpi.cc} \
                    -DMPI_Fortran_COMPILER=${prefix}/bin/${mpi.f90}
    if {[variant_isset openblas]} {
        configure.args-append  \
                    -DTPL_BLAS_LIBRARIES=${prefix}/lib/libopenblas.dylib \
                    -DTPL_LAPACK_LIBRARIES=${prefix}/lib/libopenblas.dylib
    } elseif {[variant_isset accelerate]} {
        # See also: https://github.com/liuyangzhuan/ButterflyPACK/issues/18
        configure.args-append  \
                    -DTPL_BLAS_LIBRARIES=vecLibFort \
                    -DTPL_LAPACK_LIBRARIES=vecLibFort
    }
}

configure.args-append \
                    -DBUILD_SHARED_LIBS=ON \
                    -Denable_doc=OFF \
                    -Denable_mpi=ON \
                    -Denable_openmp=ON \
                    -DCMAKE_INSTALL_INCLUDEDIR=include/${name}
