# -*- 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 55372 2009-08-09 23:22:23Z takeshi@macports.org $

PortSystem                  1.0

name                        gnudatalanguage
version                     0.9rc2
revision                    2
categories                  math science
maintainers                 takeshi
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
distname                    gdl-${version}

checksums                   md5    4ae52c19cdd6f4684b8e0b6ce8a9902c         \
                            sha1   f2c87e0a6cecc9dab1e98232cf154d0c78771aa9 \
                            rmd160 79a92daa6167ed45bedc06668dd86682ee2758cb

depends_build               port:autoconf port:libtool port:pkgconfig
depends_lib                 port:bzip2 \
                            port:zlib \
                            port:curl \
                            port:freetype \
                            port:gsl \
                            port:hdf4 \
                            port:hdf5-18 \
                            port:szip \
                            port:netcdf \
                            port:ImageMagick \
                            port:jpeg \
                            port:tiff \
                            port:ncurses \
                            port:readline \
                            port:plplot \
                            port:python25 \
                            port:py25-numarray

patch {
   set imflag [lsearch [exec pkg-config --libs-only-l ImageMagick] -lMagickCore]
   if {${imflag}>=0} {
      configure.cppflags-append "-I${prefix}/include/ImageMagick"
   }
   foreach f {configure.in configure} {
       reinplace "s|-L\$with_hdf5/lib/hdf -L\$with_hdf5/lib/hdf5||" \
           ${worksrcpath}/${f}
       reinplace "s|-I\$with_hdf5/include/hdf -I\$with_hdf5/include/hdf5||" \
           ${worksrcpath}/${f}
       reinplace "s|-lproj4|-lproj|g" ${worksrcpath}/${f}
   }
   reinplace "s|AC_CHECK_LIB(proj4|AC_CHECK_LIB(proj|" ${worksrcpath}/configure.in
   if {${imflag}>=0} {
      reinplace "s|AC_CHECK_LIB(Magick|AC_CHECK_LIB(MagickCore|" ${worksrcpath}/configure.in
      reinplace "s|-lMagick\\.|-lMagickCore.|" ${worksrcpath}/configure
      reinplace "s|-lMagick\"|-lMagickCore\"|" ${worksrcpath}/configure
      reinplace "s|LIBS=\"-lMagick  \$LIBS\"|LIBS=\"-lMagickCore  \$LIBS\"|" ${worksrcpath}/configure
   }
   reinplace "s|-L/usr/X11R6/lib64||" ${worksrcpath}/src/Makefile.am
   reinplace "s|lib_proj.h|projects.h|" ${worksrcpath}/src/math_utl.hpp
   foreach d {src src/antlr} {
       reinplace "s|libantlr|libantlr_gdl|g" ${worksrcpath}/${d}/Makefile.am
   }
}
post-patch {
   # Avoid using heimdal's broken fnmatch.h
   reinplace "s|<\\(fnmatch\.h\\)>|\"/usr/include/\\1\"|" ${worksrcpath}/src/file.cpp
   file copy -force ${prefix}/share/libtool/config/ltmain.sh ${worksrcpath}
}

pre-configure {
    system "cd ${worksrcpath}; aclocal"
}
use_autoconf                yes
configure.env-append        LIBS=-lsz
configure.cppflags-append   "-I${prefix}/include/python2.5"
configure.cxxflags-append   -DH5_USE_16_API
configure.args              --with-plplotdir=${prefix} \
                            --with-ncursesdir=${prefix} \
                            --with-readlinedir=${prefix} \
                            --with-gsldir=${prefix} \
                            --with-netcdf=${prefix} \
                            --with-hdf=${prefix} \
                            --with-hdf5=${prefix} \
                            --with-python=${prefix}/Library/Frameworks/Python.framework/Versions/2.5 \
                            --enable-python_version=2.5 \
                            --with-Magick=${prefix} \
                            --disable-dependency-tracking

destroot.destdir            prefix=${destroot}${prefix}
destroot.target             install-strip

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 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}/pro
   xinstall -m 644 -W ${worksrcpath}/src/pro README.txt STATUS UrgentNeed.txt \
      ${destroot}${prefix}/share/${name}/pro
   eval xinstall -m 644 [glob ${worksrcpath}/src/pro/*.pro] \
      ${destroot}${prefix}/share/${name}/pro
   xinstall -m 755 -d ${destroot}${prefix}/share/${name}/pro/dicom
   eval xinstall -m 644 [glob ${worksrcpath}/src/pro/dicom/*.pro] \
      ${destroot}${prefix}/share/${name}/pro/dicom
   xinstall -m 755 -d ${destroot}${prefix}/share/${name}/testsuite
   eval xinstall -m 644 [glob ${worksrcpath}/testsuite/*.pro] \
      ${destroot}${prefix}/share/${name}/testsuite
}

variant proj description {build with proj} {
    depends_lib-append port:proj
    configure.cxx           "g++ -DPJ_LIB__"
    configure.args-append   --with-libproj4=${prefix}
}

if {![variant_isset g95]} {
    default_variants +gcc43
}
variant gcc43 conflicts g95 description {Build using gcc43 (default)} {
    depends_build-append    port:gcc43
    configure.f77           ${prefix}/bin/gfortran-mp-4.3
}
variant g95 conflicts gcc43 description {Build using g95} {
    depends_build-append    port:g95
    configure.f77           ${prefix}/bin/g95
}
