--- Portfile.orig	2013-01-06 16:50:09.000000000 +0100
+++ Portfile	2013-01-06 23:10:51.000000000 +0100
@@ -4,16 +4,17 @@
 PortSystem          1.0
 
 name                gmt4
-version             4.5.8
+version             4.5.9
 categories          science
 platforms           darwin
-maintainers         takeshi
-license             LGPL-3
-description         the generic mapping tools
+maintainers         eprofs.de:florian \
+                    takeshi
+license             GPL-2
+description         The Generic Mapping Tools
 long_description GMT is an open source collection of ~65 tools  \
     for manipulating geographic and Cartesian data sets and     \
     producing Encapsulated PostScript File (EPS) illustrations  \
-    ranging from simple x-y plots via contour maps to   \
+    ranging from simple x-y plots via contour maps to           \
     artificially illuminated surfaces and 3-D perspective views.
 conflicts           gmt
 homepage            http://gmt.soest.hawaii.edu/
@@ -27,46 +28,49 @@
                     ftp://mirror.geosci.usyd.edu.au/pub/gmt \
                     ftp://gmt.mirror.ac.za/pub/gmt
 use_bzip2           yes
-set gshhsversion    2.2.0
-set gmtsrc          gmt-${version}.tar.bz2
-set gshhs           gshhs-${gshhsversion}.tar.bz2
-distfiles           ${gmtsrc} ${gshhs}
-checksums           ${gmtsrc} \
-                    md5     8a3fa928bcb8a82ebaed68d62ba8f1ba \
-                    sha1    823783c1abc9a7e0493c35661e516d4f607fff17 \
-                    rmd160  faa58f8c35a4e00f5a9515066b90e08a940cb0d6 \
-                    ${gshhs} \
-                    md5     db98bff37adc0d51fdf0ffa3834d45ad \
-                    sha1    786d58b9a335d3bacb37f40f21ee3bfbb424cd10 \
-                    rmd160  aa744b2fdcdf849cc5c4abce97f1d29f4cdc20a4
+set nameprefix      gmt
+distname            ${nameprefix}-${version}
+set dfile_gmt_gpl   ${distname}${extract.suffix}
+set dfile_gmt_nogpl ${nameprefix}-${version}-non-gpl${extract.suffix}
+distfiles           ${dfile_gmt_gpl} \
+                    ${dfile_gmt_nogpl}
+
+checksums           ${dfile_gmt_gpl} \
+                    md5     9f241e97774eadd1fe79f4d7022fcaed \
+                    sha1    711922fd99dcd47ace522f1e46fcafa5beab8c94 \
+                    rmd160  67d36ecf68b9bcd9a38de61e4f1b3e1120c71823 \
+                    ${dfile_gmt_nogpl} \
+                    md5     d61a34a83dc630b464d472c6f0bdfc3a \
+                    sha1    d03651d98a5f010090bceda2bbec09e53a543942 \
+                    rmd160  a562f21b1e474d660cc5b9502543c127fb9fb801
 
 worksrcdir          GMT${version}
 
-depends_lib         port:netcdf
+depends_lib         port:netcdf \
+                    port:gshhg-gmt-nc4
 
-post-extract {
-    # move GSHHS coastlines to worksrcpath
-    system "mv ${workpath}/share/coast ${worksrcpath}/share && rmdir ${workpath}/share"
-    system "mv ${workpath}/{LICENSE.TXT,README.TXT} ${worksrcpath}/share/coast"
-}
+destroot.target     install-all
+use_parallel_build  no
+universal_variant   no
+default_variants    +gdal
 
 configure.pre_args          --prefix=${prefix}/lib/${name}
 configure.args              --datarootdir=${prefix}/share/${name} \
                             --docdir=${prefix}/share/doc/${name} \
                             --mandir=${prefix}/share/doc/${name}/man \
                             --includedir=${prefix}/share/${name}/include \
+                            --with-gshhg-dir=${prefix}/share/gshhg-gmt-nc4 \
+                            --with-nc-config=${prefix}/bin/nc-config \
                             --enable-shared \
                             --enable-flock \
                             --disable-xgrid \
                             --disable-mex
 configure.optflags-delete   -O2
-
-use_parallel_build  no
-universal_variant   no
-destroot.target     install-all
 configure.ldflags-delete    -L${prefix}/lib
 
 post-destroot {
+    ln -s ../lib/${name}/bin/GMT ${destroot}${prefix}/bin/${name}
+    ln -s ../lib/${name}/bin/GMT ${destroot}${prefix}/bin/${nameprefix}
     ln -s ../doc/${name} ${destroot}${prefix}/share/${name}/doc
     ln -s ../../share/doc/${name}/man ${destroot}${prefix}/lib/${name}/man
     ln -s ../../share/${name}/include ${destroot}${prefix}/lib/${name}/include
@@ -87,7 +91,12 @@
     configure.args-append   --enable-triangle
 }
 
-livecheck.type      regex
-livecheck.url       http://gmt.soest.hawaii.edu/gmt/gmt_home.html
-livecheck.regex     {Current version is [^0-9 ]*([0-9]+\.[0-9]+\.[0-9]+)}
+variant xgrid description {enable xGridEdit} {
+    depends_lib-append      lib:libXaw:xorg-libXaw
+    configure.args-delete   --disable-xgrid
+    configure.args-append   --enable-xgrid
+}
 
+livecheck.type      regex
+livecheck.url       ${homepage}/gmt/gmt_home.html
+livecheck.regex     {Current version[^0-9]*([0-9]+\.[0-9]+\.[0-9]+)}
