# -*- 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 91822 2012-04-11 13:15:01Z takeshi@macports.org $

PortSystem                  1.0

name                        gnudatalanguage
version                     0.9.2
epoch                       1
categories                  math science
maintainers                 takeshi igf.fuw.edu.pl:slayoo
license                     GPLv2
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      7178304e6737a8dca910d2c1061ff63c \
                    sha1     0d6fe86e2971637310c6298379616b02f773e956 \
                    rmd160   6913b358de01550256ad38c920cc461e8ef94512

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 {
   # add the CMSVLIB installation path
   reinplace "s|dicom\"|dicom:${prefix}/share/cmsvlib\"|" ${worksrcpath}/src/gdl.cpp
   # Avoid using heimdal's broken fnmatch.h
   reinplace "s|<\\(fnmatch\.h\\)>|\"/usr/include/\\1\"|" ${worksrcpath}/src/file.cpp
   reinplace "s|/usr/X11R6/lib64|${prefix}/lib|" ${worksrcpath}/src/Makefile.am
   reinplace "s| -L/usr/X11R6/lib||" ${worksrcpath}/src/Makefile.am
   reinplace "s|\.\./gshhs|gshhs|" ${worksrcpath}/src/gshhs.cpp
}

use_autoreconf              yes
if {${configure.compiler}=="clang"} {
    configure.compiler llvm-gcc-4.2
}
if {${os.major}>=9 && ${configure.compiler}=="gcc-4.0"} {
    configure.compiler gcc-4.2
}
configure.env-append        LIBS=\"-lpng -lopenjpeg\"
configure.args              --with-plplotdir=${prefix} \
                            --with-ncursesdir=${prefix} \
                            --with-readlinedir=${prefix} \
                            --with-gsldir=${prefix} \
                            --with-netcdf=${prefix} \
                            --with-hdf=${prefix} \
                            --with-hdf5=${prefix} \
                            --with-grib=${prefix} \
                            --with-Magick=${prefix} \
                            --without-wxWidgets \
                            --disable-dependency-tracking \
                            --x-includes=${prefix}/include \
                            --x-libraries=${prefix}/lib \
                            --with-udunits=${prefix} \
                            --with-fftw=${prefix} \
                            --with-libproj4=${prefix} \
                            --with-pslib=${prefix} \
                            --with-python=no \
                            --with-openmp=no
configure.cppflags-delete   -I${prefix}/include
configure.cppflags-append   -I${prefix}/include/udunits2 -I${prefix}/include

test.run                    yes
test.target                 check

destroot.target             install-strip

use_parallel_build          yes

post-destroot {
   xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
   xinstall -m 644 -W ${worksrcpath} AUTHORS COPYING Doxyfile ChangeLog HACKING NEWS MAP_INSTALL PYTHON.txt README TODO ${destroot}${prefix}/share/doc/${name}
   xinstall -m 755 -d ${destroot}${prefix}/share/${name}
   xinstall -m 755 -d ${destroot}${prefix}/share/${name}/py
   eval xinstall -m 644 [glob ${worksrcpath}/src/py/*.py] ${destroot}${prefix}/share/${name}/py
   xinstall -m 755 -d ${destroot}${prefix}/share/${name}/testsuite
   eval xinstall -m 644 [glob ${worksrcpath}/testsuite/*.pro] \
      ${destroot}${prefix}/share/${name}/testsuite
}

variant mpich description {build with support for MPICH (experimental)} {
    depends_lib-append      port:mpich
    configure.args-append   --with-mpich=${prefix} 
} 

variant wxWidgets description {build with support for widgets (experimental, not functional yet)} {
    depends_lib-append      port:wxWidgets
    configure.args-delete   --without-wxWidgets
    configure.args-append   --with-wxWidgets=${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\"
}

variant python description {build with support for calling Python (2.6) from GDL (using numpy)} {
    depends_lib-append      port:python26 \
                            port:py26-numpy 
    configure.args-append   --with-python=${prefix}/Library/Frameworks/Python.framework/Versions/2.6 \
                            --enable-python_version=2.6
}

variant openmp description {enabling of the support for multi-threaded matrix operations using OpenMP} {
    configure.args-delete   --with-openmp=no
    configure.args-append   --with-openmp=yes
    configure.compiler      macports-gcc-4.4
    depends_build-append    port:gcc44
}

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-append   --with-gshhs=${workpath}/gshhs
    configure.cppflags-append   -I${workpath}/gshhs
    post-destroot {
        xinstall -d ${destroot}${prefix}/share/gnudatalanguage/gshhs
        foreach f [glob ${workpath}/gshhs/*.b] {
            xinstall -m 644 ${f} ${destroot}${prefix}/share/gnudatalanguage/gshhs
        }
    }
}
