--- Portfile.orig	2015-05-13 16:26:39.000000000 -0500
+++ Portfile	2015-05-13 21:01:43.000000000 -0500
@@ -4,8 +4,7 @@
 PortGroup       muniversal 1.0
 
 name            ghostscript
-version         9.10
-revision        2
+version         9.16
 categories      print
 license         AGPL-3
 maintainers     takanori openmaintainer
@@ -18,31 +17,30 @@
 homepage        http://www.cs.wisc.edu/~ghost/
 master_sites    http://downloads.ghostscript.com/public/:source \
                 sourceforge:gs-fonts:fonts \
-                sourceforge:mapping-for-pdf.adobe:misc
-set mrversion   20091116
+                https://github.com/adobe-type-tools/mapping-resources-pdf/archive/:misc
+
+# Note: this needs to be manually updated for new upstream commits
+set mappingresources_commit \
+                3128b3872aa14a4c066d5cbcdde66a3b6bba0982
+
 distfiles       ${distname}.tar.gz:source \
                 ghostscript-fonts-other-6.0.tar.gz:fonts \
-                mappingresources4pdf_2unicode_${mrversion}.tar.Z:misc \
-                mappingresources4pdf_other_${mrversion}.tar.Z:misc
+                ${mappingresources_commit}.zip:misc
 patchfiles      patch-base_unix-dll.mak.diff \
                 patch-base_stdpre.h.diff
 
 checksums           ${distname}.tar.gz \
-                    md5     5f0c0a2670b08466a4050ddbd1f3de63 \
-                    sha1    29d6538ae77565c09f399b06455e94e7bcd83d01 \
-                    rmd160  b04fb3adeb207dfcba2dc1db99a8ef6e11d0e211 \
+                    md5     829319325bbdb83f5c81379a8f86f38f \
+                    sha1    cc06fbf8244b9e8d0694cee5bf3be5bdd444b888 \
+                    rmd160  9c483b93ccd106bae6db36b3335fae4e91177aec \
                     ghostscript-fonts-other-6.0.tar.gz \
                     md5     1a643ae62ef166562e4d422b1a601272 \
                     sha1    da62dfcb9c10d96743c7e30c1eebe7166489798c \
                     rmd160  ab60dbf71e7d91283a106c3df381cadfe173082f \
-                    mappingresources4pdf_2unicode_${mrversion}.tar.Z \
-                    md5     59267a7d0b818267c8ce85d1dbc4479a \
-                    sha1    aaf44cb1e5dd2043c932e641b0e41432aee2ca0d \
-                    rmd160  bc1b86e6a5f0e022f88070195eb3e01e167114a7 \
-                    mappingresources4pdf_other_${mrversion}.tar.Z \
-                    md5     202fa0a291fc1f5b50cfa239106c1b92 \
-                    sha1    fc4eabff932c1623f7ee0a34085e79a44d51d0e5 \
-                    rmd160  1e2ea9af6be8b60c9a54963e542fa06ceb2daccd
+                    ${mappingresources_commit}.zip \
+                    md5     474705024ad12c5f9566b51fc8c645ba \
+                    sha1    ecab5f607db89e1cdce2eb4d180eb563be666875 \
+                    rmd160  1bb3b507ec48b559e4388553391ebece2468dc73
 
 depends_lib     port:expat \
                 port:fontconfig \
@@ -53,6 +51,7 @@
                 port:libidn \
                 port:libpaper \
                 port:libpng \
+                port:openjpeg \
                 port:tiff \
                 port:zlib
 #               port:lcms2
@@ -61,20 +60,27 @@
 depends_build   port:pkgconfig
 depends_run     port:perl5
 
+extract.only    ${distname}.tar.gz
+
 post-extract {
+    system "cd ${workpath} && unzip ${distpath}/${mappingresources_commit}.zip"
+    system "cd ${workpath} && unzip ${workpath}/mapping-resources-pdf-${mappingresources_commit}/mappingresources4pdf_2unicode.zip"
+    system "cd ${workpath} && unzip ${workpath}/mapping-resources-pdf-${mappingresources_commit}/mappingresources4pdf_other.zip"
+
 #   MacPorts's lcms2 is 2.4 and it doesn't support cmsPluginTHR() yet.
 #   foreach d {freetype jbig2dec jpeg lcms2 libpng tiff zlib} 
-    foreach d {freetype jbig2dec jpeg       libpng tiff zlib} {
+    foreach d {freetype jbig2dec jpeg       libpng openjpeg tiff zlib} {
         move "${worksrcpath}/${d}" "${worksrcpath}/${d}_local"
     }
 
     #move ${workpath}/MappingOther/Adobe-CNS1-ETen-B5 ${workpath}/MappingOther/Adobe-CNS1-ETenms-B5
-    eval copy -force [glob ${workpath}/ToUnicode/*]    ${worksrcpath}/Resource/CMap
-    eval copy -force [glob ${workpath}/MappingOther/*] ${worksrcpath}/Resource/CMap
+    eval copy -force [glob ${workpath}/mappingresources4pdf_2unicode/*]    ${worksrcpath}/Resource/CMap
+    eval copy -force [glob ${workpath}/mappingresources4pdf_other/*] ${worksrcpath}/Resource/CMap
 }
 
 post-patch {
     reinplace "s|__PREFIX__|${prefix}|" ${worksrcpath}/base/unix-dll.mak
+    reinplace "s|ZLIBDIR=src|ZLIBDIR=${prefix}/include|" configure.ac configure
 
     # Ensure that MacPorts perl is used
     fs-traverse f ${worksrcpath} {
@@ -87,10 +93,6 @@
 use_autoreconf yes
 autoreconf.args -fv
 
-# Make included OpenJPEG uses its own headers rather than the system ones
-configure.cppflags-delete       "-I${prefix}/include"
-configure.cppflags-append       "-isystem${prefix}/include"
-
 configure.args  --disable-compile-inits \
                 --disable-cups \
                 --disable-dbus \
