# -*- 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 68102 2010-05-27 02:58:03Z takeshi@macports.org $

PortSystem                  1.0

name                        gnudatalanguage
version                     0.9rc4
revision                    2
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/
# cmsvlib homepage http://www.physics.wisc.edu/~craigm/idl/cmsave.html
master_sites                sourceforge::gdl \
                            http://www.physics.wisc.edu/~craigm/idl/down/:cmsvlib
set gdl gdl-${version}.tar.gz
set cmsvlib cmsvlib.tar.gz
distfiles                   ${gdl}:gdl \
                            ${cmsvlib}:cmsvlib
worksrcdir                  gdl-${version}

# checksums for cmsvlib 20090505
checksums                   ${gdl} md5     dcef0d75308a13856a799d12755c80a3 \
                            ${gdl} sha1    ffd133b9bc213613c89952f341defb447a87bf1d \
                            ${gdl} rmd160  504f072d4dbf30403a2e9e0ed18223537619f01a \
                            ${cmsvlib} md5     23ce60315ba271735f73b15ff14e171a \
                            ${cmsvlib} sha1    f9992dd40812e7bee81dd6933010ebdcb78af723 \
                            ${cmsvlib} rmd160  bd0c4f777afb4dfc7e63a0188f385ccf19a7e18a

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

patch {
   # both patches are included in the GDL CVS version - will not be needed for >0.9rc4
   reinplace "s|lib_LIBRARIES|noinst_LIBRARIES|" ${worksrcpath}/src/antlr/Makefile.am
   reinplace "s|GDLLexer lexer(istr, \"\")|GDLLexer lexer(istr, \"\", GDLParser::NONE)|" ${worksrcpath}/src/widget.cpp;
   # add the CMSVLIB installation path
   reinplace {s|dicom"|dicom" GDLDATADIR "/lib/cmsvlib"|} ${worksrcpath}/src/gdl.cpp
   # Avoid using heimdal's broken fnmatch.h
   reinplace "s|<\\(fnmatch\.h\\)>|\"/usr/include/\\1\"|" ${worksrcpath}/src/file.cpp
}

pre-configure {
    system "cd ${worksrcpath}; aclocal"
}

use_autoconf                yes
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} \
                            --disable-dependency-tracking \
                            --x-includes=${prefix}/include \
                            --x-libraries=${prefix}/lib \
                            --with-udunits=${prefix} \
                            --with-fftw=${prefix} \
                            --with-libproj4=${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 INSTALL NEWS MAP_INSTALL PYTHON.txt README README_GRIB 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
# install cmsvlib
   xinstall -m 755 -d ${destroot}${prefix}/share/${name}/lib/cmsvlib
   eval xinstall -m 644 [glob ${workpath}/*.pro] ${destroot}${prefix}/share/${name}/lib/cmsvlib/
   xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}/cmsvlib
   xinstall -m 644 ${workpath}/LICENSE.RSI ${destroot}${prefix}/share/doc/${name}/cmsvlib/
   eval xinstall -m 644 [glob ${workpath}/*.html] ${destroot}${prefix}/share/doc/${name}/cmsvlib/
   eval xinstall -m 644 [glob ${workpath}/savefmt.*] ${destroot}${prefix}/share/doc/${name}/cmsvlib/
}

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-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 numarray - obsolete)} {
    depends_lib-append      port:python26 \
                            port:py26-numarray 
    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.3
    depends_build-append    port:gcc43
}
