--- Portfile.orig	2013-11-09 22:46:43.000000000 +0100
+++ Portfile	2013-11-09 22:47:30.000000000 +0100
@@ -2,93 +2,107 @@
 # $Id: Portfile 113113 2013-11-09 09:43:06Z takeshi@macports.org $
 
 PortSystem          1.0
+PortGroup           cmake 1.0
 
 name                gmt5
-version             5.0.0b
-revision            2
+version             5.1.0
 categories          science
 platforms           darwin
-maintainers         eprofs.de:florian takeshi
-license             LGPL-3
-description         the generic mapping tools
-long_description GMT is an open source collection of ~65 tools  \
+maintainers         eprofs.de:florian \
+                    takeshi
+license             GPL-3
+description         The Generic Mapping Tools
+long_description GMT is an open source collection of ~120 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           \
-    artificially illuminated surfaces and 3-D perspective views.
+    producing PostScript illustrations ranging from simple x-y  \
+    plots via contour maps to artificially illuminated surfaces \
+    and 3D perspective views.
+
 conflicts           gmt
-homepage            http://www.soest.hawaii.edu/gmt5
-master_sites        ftp://ftp.soest.hawaii.edu/gmt5          \
-                    ftp://ibis.grdl.noaa.gov/pub/gmt5        \
-                    ftp://ftp.iris.washington.edu/pub/gmt5   \
-                    ftp://ftp.iag.usp.br/pub/gmt5            \
-                    ftp://ftp.geologi.uio.no/pub/gmt5        \
-                    ftp://gd.tuwien.ac.at/pub/gmt5           \
-                    ftp://ftp.scc.u-tokai.ac.jp/pub/gmt5     \
-                    ftp://mirror.geosci.usyd.edu.au/pub/gmt5 \
-                    ftp://gmt.mirror.ac.za/pub/gmt5
+homepage            http://gmt.soest.hawaii.edu/
+master_sites        ftp://ftp.soest.hawaii.edu/gmt          \
+                    ftp://ibis.grdl.noaa.gov/pub/gmt        \
+                    ftp://ftp.iris.washington.edu/pub/gmt   \
+                    ftp://ftp.iag.usp.br/pub/gmt            \
+                    ftp://ftp.geologi.uio.no/pub/gmt        \
+                    ftp://gd.tuwien.ac.at/pub/gmt           \
+                    ftp://ftp.scc.u-tokai.ac.jp/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     c5b78de5edab4c42a8a08e7fcfa976b4 \
-                    sha1    73b16b25e59fa1cd74bfc01bdeb8170924cbda0c \
-                    rmd160  175a752b6a4027454a1163f638f2deb0abf62082 \
-                    ${gshhs} \
-                    md5     db98bff37adc0d51fdf0ffa3834d45ad \
-                    sha1    786d58b9a335d3bacb37f40f21ee3bfbb424cd10 \
-                    rmd160  aa744b2fdcdf849cc5c4abce97f1d29f4cdc20a4
+distname            gmt-${version}
+distfiles           ${distname}-src${extract.suffix}
+checksums           md5     da741319c883a3dbaf27ec7eaf66c166 \
+                    sha1    3a68ac1ea273070822cc7f993a57983ec3da9b7f \
+                    rmd160  8c00d9eda5e0f9f2723caad0887df0b9e88a1f26
+
+depends_lib         port:dcw-gmt \
+                    port:ghostscript \
+                    port:gshhg-gmt-nc4 \
+                    port:netcdf \
 
-worksrcdir          GMT${version}
+default_variants    +gdal +pcre +nonfree
 
-depends_lib         port:netcdf \
-                    port:pcre
+# CMake out-of-source build:
+worksrcdir          build
 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"
-}
-
-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 \
-                            --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 ../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
-}
-
-variant octave description {compiles Octave interface} {
-    depends_lib-append      path:bin/octave:octave
-    configure.args-append   --enable-octave
+    file mkdir ${worksrcpath}
+}
+
+# Mimic CMake's default FLAGS:
+if {[variant_isset debug]} {
+    configure.optflags      -O0
+} else {
+    configure.optflags      -O3
+}
+
+configure.cflags-append     -fstrict-aliasing
+configure.args-append       -DDCW_ROOT=${prefix} \
+                            -DGSHHG_ROOT=${prefix} \
+                            -DNETCDF_ROOT=${prefix} \
+                            -DFFTW3_ROOT=off \
+                            -DGDAL_ROOT=off \
+                            -DPCRE_ROOT=off \
+                            -DFLOCK=on \
+                            -DGMT_INSTALL_MODULE_LINKS=off \
+                            -DGMT_INSTALL_TRADITIONAL_FOLDERNAMES=off \
+                            -DLICENSE_RESTRICTED=GPL
+
+# Location of sources relative to ${worksrcpath}:
+configure.post_args         ../${distname}
+
+variant fftw3 description {Use FFTW-3 library} {
+    depends_lib-append      port:fftw-3-single
+    configure.args-delete   -DFFTW3_ROOT=off
+    configure.args-append   -DFFTW3_ROOT=${prefix}
 }
 
-variant gdal description {Experimental GDAL import support} {
+variant gdal description {GDAL import support} {
     depends_lib-append      port:gdal
-    configure.args-append   --enable-gdal
+    configure.args-delete   -DGDAL_ROOT=off
+    configure.args-append   -DGDAL_ROOT=${prefix}
 }
 
-variant triangle description {use J. Shewchuk's fast, non-GPL triangulation routine} {
-    configure.args-append   --enable-triangle
+variant pcre description {PCRE regular expression support} {
+    depends_lib-append      port:pcre
+    configure.args-delete   -DPCRE_ROOT=off
+    configure.args-append   -DPCRE_ROOT=${prefix}
 }
 
-livecheck.type      regex
-livecheck.url       http://www.soest.hawaii.edu/gmt5/gmt/gmt_home.html
-livecheck.regex     {Current version is [^0-9 ]*([0-9]+\.[0-9]+\.[0-9a-z]+)}
+variant lgpl conflicts nonfree description {disallow use of GPL code, license will be LGPL} {
+    license-delete          GPL-3
+    license-append          LGPL-3
+    configure.args-delete   -DLICENSE_RESTRICTED=GPL
+    configure.args-append   -DLICENSE_RESTRICTED=LGPL
+}
 
+variant nonfree conflicts lgpl description {enable nonfree code, libraries and binaries \
+    will not be redistributable} {
+    license-delete          GPL-3
+    license-append          Restrictive
+    configure.args-delete   -DLICENSE_RESTRICTED=GPL
+    configure.args-append   -DLICENSE_RESTRICTED=no
+}
+
+livecheck.type      regex
+livecheck.url       ${homepage}
+livecheck.regex     {(?i)gmt-(5\.[0-9]+\.[0-9a-z]+)<\/a>}
