# -*- 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               conflicts_build 1.0
PortGroup               mpi 1.0
PortGroup               github 1.0
PortGroup               wxWidgets 1.0

github.setup            gnudatalanguage gdl 1.1.1 v
revision                0
name                    ${github.author}
epoch                   2

compilers.choose        cc cxx
mpi.setup

categories              math science
maintainers             {takeshi @tenomoto}
license                 GPL-2+
description             a free IDL combatible incremental compiler
long_description        A free IDL (Interactive Data Language) compatible \
                        incremental compiler (i.e. runs IDL programs).

distname                ${github.project}-${github.tag_prefix}${version}

checksums               rmd160  6175c3d407a8c5aa4098bf9283025b1b3cad83e8 \
                        sha256  744ed3abcdc5e1bbf31147a8a0c21c33662f200b6096ee3d3adedd160a3a9662 \
                        size    33813887

compiler.cxx_standard   2011

set proj_ver            9

depends_build-append    path:bin/pkg-config:pkgconfig \
                        path:share/pkgconfig/eigen3.pc:eigen3 \
                        port:qhull

depends_lib-append      port:zlib \
                        port:gsl \
                        port:ncurses \
                        port:expat \
                        port:readline \
                        port:netcdf \
                        port:hdf4 \
                        port:hdf5 \
                        port:ecCodes \
                        port:proj${proj_ver} \
                        port:GraphicsMagick \
                        port:udunits2 \
                        port:fftw-3 \
                        port:fftw-3-single \
                        port:shapelib \
                        port:freetype \
                        port:glpk \
                        port:libgeotiff \
                        port:libaec \
                        port:libpng \
                        port:libjpeg-turbo \
                        port:tiff

conflicts_build         antlr

patchfiles              patch-src-gdlwidget.diff

configure.args-append   -DMAGICK=OFF \
                        -DMPI=OFF \
                        -DOPENMP=OFF \
                        -DPYTHON=OFF \
                        -DPYTHON_MODULE=OFF \
                        -DWXWIDGETS=OFF \
                        -DLIBPROJDIR=${prefix}/lib/proj${proj_ver}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    foreach f {AUTHORS README} {
        file rename ${destroot}${prefix}/share/${name}/${f} \
            ${destroot}${prefix}/share/doc/${name}/
    }
    xinstall -m 644 -W ${worksrcpath} COPYING HACKING NEWS MAP_INSTALL README README.GRIB README.md \
        ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/testsuite ${destroot}${prefix}/share/${name}/
}

pre-configure {
    if {[mpi_variant_isset]} {
        configure.args-replace  -DMPI=OFF \
                                -DMPI=ON
        configure.args-append   -DMPI_CXX_COMPILER=${mpi.cxx} \
                                -DMPI_C_COMPILER=${mpi.cc}
    }
}

variant wxWidgets description {Enable wxWidgets support} {
    wxWidgets.use           wxWidgets-3.2
    depends_lib-append      port:${wxWidgets.port}
    configure.args-replace  -DWXWIDGETS=OFF \
                            -DWXWIDGETS=ON
    configure.args-append   -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig}
}

# https://trac.macports.org/ticket/62087
if {${os.platform} ne "darwin" || ${os.major} >= 16} {
    default_variants        +wxWidgets
}

if {[gcc_variant_isset] || [clang_variant_isset]} {
    configure.args-replace  -DOPENMP=OFF \
                            -DOPENMP=ON
}

if {![variant_isset wxWidgets]} {
    test.run                yes
}
