--- Portfile.orig	2012-04-30 00:10:28.000000000 +0200
+++ Portfile	2012-04-30 00:12:06.000000000 +0200
@@ -5,11 +5,13 @@
 
 name                gmt4
 version             4.5.8
+revision            1
 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  \
@@ -27,32 +29,34 @@
                     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} \
+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}
+patchfiles          patch-bugfixes-r9794.diff \
+                    patch-bugfixes-r9816.diff \
+                    patch-gmt_shore_c.diff
+
+checksums           ${dfile_gmt_gpl} \
                     md5     8a3fa928bcb8a82ebaed68d62ba8f1ba \
                     sha1    823783c1abc9a7e0493c35661e516d4f607fff17 \
                     rmd160  faa58f8c35a4e00f5a9515066b90e08a940cb0d6 \
-                    ${gshhs} \
-                    md5     db98bff37adc0d51fdf0ffa3834d45ad \
-                    sha1    786d58b9a335d3bacb37f40f21ee3bfbb424cd10 \
-                    rmd160  aa744b2fdcdf849cc5c4abce97f1d29f4cdc20a4
+                    ${dfile_gmt_nogpl} \
+                    md5     b929d3287cf7bb67f52bc29b6903b1b4 \
+                    sha1    d383d480d46229ba142d64c55a4ede4fb14f0196 \
+                    rmd160  e420fa50d388227eb4147ef3a363459c8720408f
 
 worksrcdir          GMT${version}
 
-depends_lib         port:netcdf
+depends_lib         port:netcdf \
+                    port:gshhg-gmt-nc4
 
 destroot.target     install-all
 use_parallel_build  no
 universal_variant   no
-
-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"
-}
+default_variants    +gdal
 
 configure.pre_args          --prefix=${prefix}/lib/${name}
 configure.args              --datarootdir=${prefix}/share/${name} \
@@ -67,10 +71,15 @@
 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
     ln -s ../../share/${name} ${destroot}${prefix}/lib/${name}/share
+    # add location of files from port gshhg-gmt-nc4 to coastline.conf:
+    system "echo ${prefix}/share/gshhg-gmt-nc4 \
+        > ${destroot}${prefix}/share/${name}/conf/coastline.conf"
 }
 
 variant octave description {compiles Octave interface} {
@@ -87,6 +96,11 @@
     configure.args-append   --enable-triangle
 }
 
+variant xgrid description {enable xGridEdit} {
+    depends_lib-append      lib:libXaw:xorg-libXaw
+    configure.args-append   --enable-xgrid
+}
+
 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]+)}
+livecheck.url       ${homepage}/gmt/gmt_home.html
+livecheck.regex     {Current version[^0-9]*([0-9]+\.[0-9]+\.[0-9]+)}
