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

github.setup        spacepy spacepy 0.2.2 release-
name                py-spacepy
github.tarball_from releases
platforms           darwin
license             PSF
maintainers         {mojca @mojca} openmaintainer

description         SpacePy Tools for Space Science Applications
long_description    ${description}

homepage            https://spacepy.github.io

checksums           rmd160  3a9b2c386388dc553a74d2c45b38238e511d8e9e \
                    sha256  72a66f46b3308d531b548b3d9ab38d19c3eca369d8670ac8548040cb86910f0f \
                    size    18460896

python.versions     27 35 36 37 38 39

if {${name} ne ${subport}} {
    # TODO: figure out which ones are build dependencies and which ones are runtime
    # sudo apt-get install python-dev python-numpy build-essential \
    # python-scipy python-matplotlib python-networkx python-h5py \
    # python-f2py gfortran ncurses-dev
    depends_lib-append \
                    port:cdf \
                    port:py${python.version}-h5py \
                    port:py${python.version}-matplotlib \
                    port:py${python.version}-networkx \
                    port:py${python.version}-numpy \
                    port:py${python.version}-scipy

    # TODO: use the compilers portgroup
    if {${os.major} > 9} {
        depends_build-append \
                    port:gcc9
        configure.env-append \
                    F77=${prefix}/bin/gfortran-mp-9 \
                    F90=${prefix}/bin/gfortran-mp-9
        build.env-append \
                    F77=${prefix}/bin/gfortran-mp-9 \
                    F90=${prefix}/bin/gfortran-mp-9
    } else {
        # https://trac.macports.org/ticket/51388
        depends_build-append \
                    port:gcc5
        configure.env-append \
                    F77=${prefix}/bin/gfortran-mp-5 \
                    F90=${prefix}/bin/gfortran-mp-5
        build.env-append \
                    F77=${prefix}/bin/gfortran-mp-5 \
                    F90=${prefix}/bin/gfortran-mp-5
    }

    # ffnet not found; required for LANLstar.
    #   - see http://ffnet.sourceforge.net/install.html
    # f2py failed; IRBEM will not be available.

    configure.env-append \
                    PATH=$env(PATH):${python.prefix}/bin
    build.env-append \
                    PATH=$env(PATH):${python.prefix}/bin

    post-destroot {
        set destdocdir ${destroot}${prefix}/share/doc/${subport}
        xinstall -d -m 0755 ${destdocdir}
        file copy ${worksrcpath}/Doc/build/latex/SpacePy.pdf ${destdocdir}
    }

    livecheck.type  none
}
