# -*- 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           compilers 1.0
PortGroup           github 1.0
PortGroup           makefile 1.0

github.setup        flatironinstitute finufft 2.1.0 v

categories          math science
license             Apache-2
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Flatiron Institute Non-uniform Fast Fourier Transform library, FINUFFT
long_description    This is a lightweight CPU library to compute the three standard types \
                    of non-uniform FFT to a specified precision, in one, two or three dimensions.

checksums           rmd160  5ff2866405e3b30ce65f4474f888cbcbdbcdeff9 \
                    sha256  52f25f0ace06a6dd514a29e728ad31e317b76631912bf0bc53cbf06355e24ad7 \
                    size    2292702
github.tarball_from archive

depends_build-append \
                    port:pkgconfig
depends_lib-append  port:fftw-3 \
                    port:fftw-3-single

compiler.cxx_standard 2014
compiler.openmp_version 2.5
compilers.setup     require_fortran

patchfiles-append   patch-makefile.diff

post-patch {
    reinplace "s,@CC@,${configure.cc}," ${worksrcpath}/makefile
    reinplace "s,@CXX@,${configure.cxx}," ${worksrcpath}/makefile
    reinplace "s,@FC@,${configure.fc}," ${worksrcpath}/makefile
    reinplace "s,@PREFIX@,${prefix}," ${worksrcpath}/makefile

    if {[string match *clang* ${configure.compiler}]} {
        reinplace "s,@LOMP@,-L${prefix}/lib/libomp -lomp," ${worksrcpath}/makefile
        reinplace "s,-fcx-limited-range,," ${worksrcpath}/makefile
    } else {
        reinplace "s,@LOMP@,-lgomp," ${worksrcpath}/makefile
    }
}

build.target        fortran lib

destroot {
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    move ${worksrcpath}/lib/libfinufft.dylib ${destroot}${prefix}/lib
    move ${worksrcpath}/lib-static/libfinufft.a ${destroot}${prefix}/lib
    move ${worksrcpath}/include/finufft ${destroot}${prefix}/include
    foreach file [glob -type f "${worksrcpath}/include/finufft*"] {
        xinstall ${file} ${destroot}${prefix}/include
    }
    move ${worksrcpath}/docs ${destroot}${prefix}/share/doc/${name}
}

test.run            yes
test.target         test