# -*- 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
# $Id: Portfile 106227 2013-05-19 21:14:06Z takeshi@macports.org $

PortSystem                  1.0
PortGroup                   cmake 1.0

name                        gnudatalanguage
version                     0.9.3
epoch                       1
categories                  math science
maintainers                 takeshi
license                     GPL-2
platforms                   darwin
description                 a free IDL combatible incremental compiler
long_description \
    A free IDL (Interactive Data Language) compatible \
    incremental compiler (ie. runs IDL programs).
homepage                    http://gnudatalanguage.sourceforge.net/
master_sites                sourceforge:${name}:gdl \
                            ftp://ftp.soest.hawaii.edu/pwessel/gshhs:gshhs
set gdlsrc          gdl-${version}.tar.gz
set srcversion      1.13
set dataversion     2.1.0
set gshhssrc        gshhs_${srcversion}_src.zip
set gshhsdata       gshhs_${dataversion}.zip
distfiles           ${gdlsrc}:gdl
worksrcdir          gdl-${version}

checksums           ${gdlsrc} \
                    md5     f71f869e6c9aa99bbfdb22ecd5c88914 \
                    sha1    a4558643645cc414041d588e375669810780a69a \
                    rmd160  a6eed21d1a328156b794ba7a6a90e1942fa38fd7

depends_lib                 port:zlib \
                            port:gsl \
                            port:ncurses \
                            port:readline \
                            port:plplot \
                            port:netcdf-cxx \
                            port:hdf4 \
                            port:hdf5-18 \
                            port:grib_api \
                            port:libproj4 \
                            port:ImageMagick \
                            port:xorg-libX11 \
                            port:udunits2 \
                            port:fftw-3 \
                            port:fftw-3-single \
                            port:cmsvlib \
                            port:pslib

post-patch {
   # Avoid using heimdal's broken fnmatch.h
   reinplace "s|<\\(fnmatch\.h\\)>|\"/usr/include/\\1\"|" ${worksrcpath}/src/file.cpp
   reinplace "s|\.\./gshhs|gshhs|" ${worksrcpath}/src/gshhs.cpp
}

# Compiliation of gdl.cpp stalls with clang
compiler.blacklist      clang

configure.args-append   -DFFTW=ON \
                        -DFFTWDIR=${prefix} \
                        -DGRIB=ON \
                        -DGRIBDIR=${prefix} \
                        -DGSHHS=OFF \
                        -DGSLDIR=${prefix} \
                        -DHDF5=ON \
                        -DHDF5DIR=${prefix} \
                        -DHDF=ON \
                        -DHDFDIR=${prefix} \
                        -DJASPERDIR=${prefix} \
                        -DJPEGDIR=${prefix} \
                        -DLIBPROJ4=ON \
                        -DLIBPROJ4DIR=${prefix} \
                        -DMAGICK=ON \
                        -DMAGICKDIR=${prefix} \
                        -DImageMagick_INCLUDE_DIRS=${prefix}/include/ImageMagick-6 \
                        -DImageMagick_Magick++_LIBRARY=${prefix}/lib/libMagick++-6.Q16.dylib \
                        -DImageMagick_MagickCore_LIBRARY=${prefix}/lib/libMagickCore-6.Q16.dylib \
                        -DImageMagick_MagickWand_LIBRARY=${prefix}/lib/libMagickWand-6.Q16.dylib \
                        -DMPICH=OFF \
                        -DNCURSESDIR=${prefix} \
                        -DNETCDF=ON \
                        -DNETCDFDIR=${prefix} \
                        -DOPENMP=OFF \
                        -DPLPLOTDIR=${prefix} \
                        -DPSLIB=ON \
                        -DPSLIBDIR=${prefix} \
                        -DPYTHON=OFF \
                        -DPYTHON_MODULE=OFF \
                        -DREADLINE=ON \
                        -DREADLINEDIR=${prefix} \
                        -DUDUNITS=ON \
                        -DUDUNITSDIR=${prefix} \
                        -DUDUNITS_INCLUDE_DIR=${prefix}/include/udunits2 \
                        -DWXWIDGETS=OFF \
                        -DX11DIR=${prefix} \
                        -DZLIBDIR=${prefix} \
                        -DCMAKE_OSX_DEPLOYMENT_TARGET=""

test.run                    yes
test.target                 check

use_parallel_build          yes

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 ChangeLog HACKING NEWS MAP_INSTALL TODO \
        ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/testsuite ${destroot}${prefix}/share/${name}/
    if {[variant_isset python25] || [variant_isset python26] || [variant_isset python27]} {
        xinstall -m 644 ${worksrcpath}/PYTHON.txt ${destroot}${prefix}/share/doc/${name}
        file copy ${worksrcpath}/src/py ${destroot}${prefix}/share/${name}/
    }
    if {[variant_isset gshhs]} {
        xinstall -d ${destroot}${prefix}/share/gnudatalanguage/gshhs
        foreach f [glob ${workpath}/gshhs/*.b] {
            xinstall -m 644 ${f} ${destroot}${prefix}/share/gnudatalanguage/gshhs
        }
    }
}

variant mpich description {build with support for MPICH (experimental)} {
    depends_lib-append      port:mpich
    configure.args-delete   -DMPICH=OFF
    configure.args-append   -DMPICH=ON \
                            -DMPICHDIR=${prefix}/lib/mpich
} 

variant wxWidgets description {build with support for widgets (experimental, not functional yet)} {
    supported_archs         ppc i386
    depends_lib-append      port:wxWidgets
    configure.args-delete   -DWXWIDGETS=OFF \
    configure.args-append   -DWXWIDGETS=ON \
                            -DWXWIDGETSDIR=${prefix}
    # http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
    #configure.env-append    LDFLAGS=\"-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib\"
}

if {[variant_isset python25] || [variant_isset python26] || [variant_isset python27]} {
    configure.args-delete   -DPYTHON=OFF
    configure.args-append   -DPYTHON=ON
}

variant python requires python26 description {Legacy compatibility variant} {}

variant python25 conflicts python26 python27 description {build with support for calling Python (2.5) from GDL (using numpy)} {
    depends_lib-append      port:py25-numpy 
    configure.args-append   -DPYTHONDIR=${frameworks_dir}/Python.framework/Versions/2.5 \
                            -DPYTHONVERSION=2.5
}

variant python26 conflicts python25 python27 description {build with support for calling Python (2.6) from GDL (using numpy)} {
    depends_lib-append      port:py26-numpy 
    configure.args-append   -DPYTHONDIR=${frameworks_dir}/Python.framework/Versions/2.6 \
                            -DPYTHONVERSION=2.6
}

variant python27 conflicts python25 python26 description {build with support for calling Python (2.7) from GDL (using numpy)} {
    depends_lib-append      port:py27-numpy 
    configure.args-append   -DPYTHONDIR=${frameworks_dir}/Python.framework/Versions/2.7 \
                            -DPYTHONVERSION=2.7
}

if {[variant_isset gcc44] || [variant_isset gcc45] || [variant_isset gcc46] || [variant_isset gcc47]} {
    configure.args-delete   -DOPENMP=OFF
    configure.args-append   -DOPENMP=ON
}

variant openmp requires gcc44 description {Legacy compatibility variant} {}

variant gcc44 conflicts gcc45 gcc46 gcc47 description {enabling of the support for OpenMP with gcc44} {
    configure.compiler      macports-gcc-4.4
    depends_lib-append    port:gcc44
# Detecting CXX compiler ABI info fails without this
    configure.args-append   -D
}

variant gcc45 conflicts gcc44 gcc46 gcc47 description {enabling of the support for OpenMP with gcc45} {
    configure.compiler      macports-gcc-4.5
    depends_lib-append    port:gcc45
# Detecting CXX compiler ABI info fails without this
    configure.args-append   -D
}

variant gcc46 conflicts gcc44 gcc45 gcc47 description {enabling of the support for OpenMP with gcc46} {
    configure.compiler      macports-gcc-4.6
    depends_lib-append    port:gcc46
# Detecting CXX compiler ABI info fails without this
    configure.args-append   -D
}

variant gcc47 conflicts gcc44 gcc45 gcc46 description {enabling of the support for OpenMP with gcc47} {
    configure.compiler      macports-gcc-4.7
    depends_lib-append    port:gcc47
}

variant gshhs description {build with support for GSHHS} {
    distfiles-append        ${gshhssrc}:gshhs \
                            ${gshhsdata}:gshhs
    checksums-append \
                    ${gshhssrc} \
                    md5     714b729d90381a3b1b1df70b78b05f6e \
                    sha1    7cfb92dafd86b197c65ad6f6aaf797f6cd0ce55a \
                    rmd160  a397b3cc50d9e3a0a9736044deabd567059698b5 \
                    ${gshhsdata} \
                    md5     30d336f86228e2e2861a2ba91efa0857 \
                    sha1    fe14a1dcc7b863fb59ea00d9975b2499b669bd79 \
                    rmd160  f4ecd162cd4e60f3b03d02d22ab143184d026f34
    extract.only    ${gdlsrc}
    post-extract {
        system "cd ${workpath}; \
                unzip ${distpath}/${gshhssrc} gshhs/gshhs.h; \
                unzip ${distpath}/${gshhsdata}"
    }
    configure.args-delete   -DGSHHS=OFF
    configure.args-append   -DGSHHS=ON \
                            -DGSHHSDIR=${workpath}/gshhs
}

livecheck.regex             /gdl-(\[0-9.\]+)${extract.suffix}
