--- /opt/local/var/macports/sources/LocalPorts/sysutils/dpkg/Portfile_fixedwhitespace	2014-01-18 19:07:10.000000000 -0500
+++ Portfile	2014-03-16 20:21:41.000000000 -0400
@@ -4,66 +4,128 @@
 PortSystem          1.0
 
 name                dpkg
-version             1.14.29
-revision            4
+version             1.16.12
+revision            0
 platforms           darwin freebsd
 categories          sysutils archivers
 license             GPL-2+
-maintainers         nomaintainer
+maintainers         gwmail.gwu.edu:egall openmaintainer
 description         Debian package maintenance system
-long_description    ${description}
+long_description    ${name} is the basis of the ${description}. \
+                    Installing this port allows the usage of the \
+                    \`port dpkg\` command.
+
 homepage            http://wiki.debian.org/Teams/Dpkg
 
-master_sites        debian:d/dpkg/
-checksums           md5 4326172a959b5b6484b4bc126e9f628d \
-                    sha1 15a35dd96dac6a99f24844b2eff85f8fad37ab06
+master_sites        debian:d/${name}/
+checksums           md5     b7e9cac52ff7882b088a3058b52081b5 \
+                    sha1    5969bb7f30ade840a56f512571ca5ab56d434af1 \
+                    rmd160  1912afd35b835901e661d2c0df563198de4e8420 \
+                    sha256  af96447758ecbfda51fc57d4b3bc3d208ad6393e71b91c9b52c6687697a208da
+
+use_xz              yes
+extract.asroot      yes
+
+depends_build-append \
+                    port:pkgconfig \
+                    port:autoconf-archive \
+                    port:xorg-util-macros \
+                    port:gnutar \
+                    port:perl5 \
+                    bin:git:git-core \
+                    bin:lzma:xz
 
 # Use MacPorts versions explicitly
-depends_lib         port:gettext \
+depends_lib-append  port:gettext \
                     port:libiconv \
                     port:perl5 \
                     port:coreutils \
                     port:bzip2 \
-                    port:zlib
-
-depends_run         bin:gnutar:gnutar \
-                    bin:lzma:xz
-
+                    port:zlib \
+                    port:ncurses \
+                    port:gnutar \
+                    path:lib/pkgconfig/liblzma.pc:xz
+
+depends_run-append  port:gnutar \
+                    bin:lzma:xz \
+                    bin:perl:perl5 \
+                    port:debianutils
 
+# got to do some underscore-to-hyphen twiddling...
 distname            ${name}_${version}
 worksrcdir          ${name}-${version}
 
-patchfiles          patch-lib_tarfn.c \
-                    patch-main_remove.c \
-                    patch-main_archives.c \
-                    patch-scripts-Makefile \
-                    patch-lib_dpkg.h \
-                    ncurses.diff
-
-configure.env       PERL=${prefix}/bin/perl5
-configure.args      --without-sgml-doc --with-libintl-prefix=${prefix} \
-                    --with-libiconv-prefix=${prefix} --with-admindir=${prefix}/var/db/dpkg \
+configure.perl      ${prefix}/bin/perl5
+configure.pkg_config ${prefix}/bin/pkg-config
+configure.env-append TAR=${prefix}/bin/gnutar
+configure.args-append \
+                    --with-libintl-prefix=${prefix} \
+                    --with-libiconv-prefix=${prefix} \
+                    --with-admindir=${prefix}/var/db/${name} \
+                    --with-logdir=${prefix}/var/log \
                     --mandir=${prefix}/share/man \
-                    --with-zlib --with-bz2 \
-                    --disable-linker-optimisations
+                    --with-zlib \
+                    --with-bz2 \
+                    --with-liblzma \
+                    --disable-linker-optimisations \
+                    --disable-silent-rules \
+                    --disable-start-stop-daemon
+# The start-stop-daemon patch now applies again, but now it leads to build
+# errors, so disabling it with a configure flag again (as done above)
+
+# ccache is trouble
+configure.ccache          no
+
+# Older versions of gcc choke with the -Wvla warning flag
+configure.cflags-delete   -Wvla
+configure.cppflags-delete -Wvla
+configure.ldflags-delete  -Wvla
+
+post-configure {
+    reinplace "s|-Wvla||" ${worksrcpath}/Makefile
+    eval reinplace "s|-Wvla||" [glob ${worksrcpath}/*/Makefile]
+    eval reinplace "s|-Wvla||" [glob ${worksrcpath}/lib/*/Makefile]
+    reinplace "s|-Wvla||" ${worksrcpath}/lib/dpkg/test/Makefile
+    reinplace "s|-Wmissing-declarations||" ${worksrcpath}/dselect/Makefile
+}
+
+compiler.blacklist-append cc gcc-3.3 gcc-4.0 apple-gcc-4.0
 
 build.type          gnu
 
-set vardpkg ${destroot}${prefix}/var/db/dpkg
-destroot.keepdirs ${vardpkg} ${vardpkg}/updates ${vardpkg}/info
+set vardpkg ${destroot}${prefix}/var/db/${name}
+destroot.keepdirs-append \
+                    ${vardpkg} \
+                    ${vardpkg}/updates \
+                    ${vardpkg}/info \
+                    ${destroot}${prefix}/var/log \
+                    ${destroot}${prefix}/etc/${name}
+
+patchfiles-append   patch-configure.ac.diff \
+                    patch-lib_dpkg_dpkg.h.diff \
+                    patch-lib_dpkg_tarfn.c.diff \
+                    patch-src_remove.c.diff \
+                    patch-src_archives.c.diff \
+                    patch-utils_start-stop-daemon.c.diff
+
+patch.args-append   --backup
 
 post-patch {
     set scripts ${worksrcpath}/scripts
-    reinplace s|/etc/dpkg/|${prefix}/etc/dpkg/| \
-            ${scripts}/dpkg-shlibdeps.pl \
-            ${scripts}/dpkg-source.pl
-
-    reinplace s|/etc/alternatives|${prefix}/etc/alternatives|g \
-            ${scripts}/update-alternatives.pl
+    reinplace "s|/etc/${name}/|${prefix}/etc/${name}/|" \
+            ${scripts}/${name}-shlibdeps.pl \
+            ${scripts}/${name}-source.pl
+    reinplace "s|AC_ERROR|AC_MSG_ERROR|" ${worksrcpath}/m4/dpkg-build.m4
+    file copy ${prefix}/share/aclocal/ax_check_gnu_make.m4 ${worksrcpath}/m4
+    file copy ${prefix}/share/aclocal/xorg-macros.m4 ${worksrcpath}/m4
+    system -W ${worksrcpath} "git init"
 }
 
+use_autoreconf      yes
+autoreconf.args     -fvi --warnings=all
+
 pre-destroot {
-    file mkdir ${destroot}${prefix}/share/doc/dpkg
+    file mkdir ${destroot}${prefix}/share/doc/${name}
 }
 
 post-destroot {
@@ -73,16 +135,58 @@
     system "touch ${vardpkg}/available ${vardpkg}/status"
 }
 
+# These platform variants had previously had patches associated
+# with them...
 platform darwin {
     depends_build-append    bin:gnumake:gmake
-    patchfiles-append patch-utils_start-stop-daemon.c bsd/patch-main_help.c
 }
 
 platform freebsd {
     depends_build-append    bin:gmake:gmake
-    patchfiles-append patch-utils_start-stop-daemon.c bsd/patch-main_help.c
 }
 
-livecheck.type      regex
-livecheck.url       http://ftp.debian.org/debian/pool/main/d/dpkg/
+# This variant sometimes hangs while building...
+variant docs description {Build documentation (warning: building documentation takes a long time)} {
+    depends_build-append    port:doxygen \
+                            path:bin/dot:graphviz \
+                            port:fontconfig \
+                            port:freefont-ttf
+    set docdir ${prefix}/share/doc/${name}
+    configure.args-append   --docdir=${docdir} \
+                            --htmldir=${docdir}/html \
+                            --dvidir=${docdir}/dvi \
+                            --pdfdir=${docdir}/pdf \
+                            --psdir=${docdir}/ps
+    build.target-append     doc
+    pre-build {
+        elevateToRoot "doxygen"
+        system -W ${worksrcpath}/doc "${prefix}/bin/doxygen -u"
+    }
+    post-build {
+        system -W ${worksrcpath}/doc "${prefix}/bin/doxygen"
+        dropPrivileges
+        set destroot_docdir ${destroot}${prefix}/share/doc/${name}
+        xinstall -d ${destroot_docdir}
+        copy ${worksrcpath}/doc/doc ${destroot_docdir}
+        copy ${worksrcpath}/doc/html ${destroot_docdir}
+        foreach docfile {coding-style.txt triggers.txt README.feature-removal-schedule frontend.txt README.api} {
+            xinstall -m 644 ${worksrcpath}/doc/${docfile} ${destroot_docdir}
+        }
+    }
+}
+
+# Tests currently fail, this needs to be fixed eventually:
+test.run            yes
+test.target         check
+
+pre-test {
+    elevateToRoot "test"
+}
+post-test {
+    dropPrivileges
+}
+
+# odd-numbered releases are unstable, so ignore them
+livecheck.type      none
+livecheck.url       http://ftp.debian.org/debian/pool/main/d/${name}/
 livecheck.regex     "${name}_(\\d+\\.\\d+(\\.\\d+)*)"
