--- Portfile.orig	2016-03-03 04:01:55.000000000 -0700
+++ Portfile	2016-03-15 03:22:27.000000000 -0700
@@ -4,6 +4,7 @@
 PortSystem 1.0
 PortGroup select 1.0
 PortGroup compiler_blacklist_versions 1.0
+PortGroup muniversal 1.0
 
 #remember to update the -doc and -server as well
 name			postgresql95
@@ -62,18 +63,6 @@
 compiler.blacklist-append {clang < 421}
 notes "To use the postgresql server, install the ${name}-server port"
 
-if {[variant_isset universal]} {
-    configure.cflags-append	-DAC_APPLE_UNIVERSAL_BUILD
-    post-configure {
-        system "cd ${worksrcpath}/src/include \
-                && ed - pg_config.h < ${filespath}/pg95_config.h.ed \
-                && touch stamp-h"
-        system "cd ${worksrcpath}/src/interfaces/ecpg/include \
-                && ed - ecpg_config.h < ${filespath}/ecpg_config.h.ed \
-                && touch stamp-h"
-    }
-}
-
 build.type		gnu
 build.target
 
@@ -89,14 +78,15 @@
 # prepare the contrib modules
 set contribs {}
 
-post-build {
-# remove a Linux-specific contrib before continuing
+if { ![variant_isset universal] } {
+    post-build {
+        # remove a Linux-specific contrib before continuing
     file delete -force ${worksrcpath}/contrib/sepgsql
-# remove perl-specific contrib, if no perl variant
+        # remove perl-specific contrib, if no perl variant
     if {![variant_isset perl]} {
         file delete -force ${worksrcpath}/contrib/hstore_plperl
     }
-# remove python-specific contrib, if no python27 variant
+        # remove python-specific contrib, if no python27 variant
     if {![variant_isset python27]} {
         file delete -force ${worksrcpath}/contrib/hstore_plpython
         file delete -force ${worksrcpath}/contrib/ltree_plpython
@@ -110,20 +100,69 @@
 	foreach contrib ${contribs} {
 		system "cd ${worksrcpath}/contrib/${contrib}/ && ${build.cmd}"
 	}
+    }
+} else {
+    post-build {
+        foreach arch ${universal_archs_to_use} {
+            # remove a Linux-specific contrib before continuing
+            file delete -force ${worksrcpath}-${arch}/contrib/sepgsql
+            # remove perl-specific contrib, if no perl variant
+            if {![variant_isset perl]} {
+                file delete -force ${worksrcpath}-${arch}/contrib/hstore_plperl
+            }
+            # remove python-specific contrib, if no python27 variant
+            if {![variant_isset python27]} {
+                file delete -force ${worksrcpath}-${arch}/contrib/hstore_plpython
+                file delete -force ${worksrcpath}-${arch}/contrib/ltree_plpython
+            }
+            set contribdirs [glob -nocomplain -type d ${worksrcpath}-${arch}/contrib/*]
+            foreach d [lsort $contribdirs] {
+                if { [file exists $d/Makefile] } {
+                    lappend contribs [file tail $d]
+                }
+            }
+            foreach contrib ${contribs} {
+                system "cd ${worksrcpath}-${arch}/contrib/${contrib}/ && ${build.cmd}"
+            }
+        }
+    }
 }
 
-post-destroot {
+if { ![variant_isset universal] } {
+    post-destroot {
 	foreach contrib ${contribs} {
 		system "echo contrib: \"${contrib}\""
 		system "cd ${worksrcpath}/contrib/${contrib}/ && \
 			${destroot.cmd} install ${destroot.destdir} && touch DONE"
 	}
-	system "cd ${destroot}${prefix}/bin && ln -sf ${libdir}/bin/psql psql95"
-	file delete -force ${destroot}${prefix}/share/doc/postgresql \
-		${destroot}${prefix}/share/man
 		
+        # remove architecture flags from global Makefile
 	reinplace -E "s#-arch\[\[:space:\]\]+\[\[:alnum:\]_\]+##g" \
 	    ${destroot}${prefix}/lib/${name}/pgxs/src/Makefile.global
+    }
+} else {
+    merger-post-destroot {
+        foreach arch ${universal_archs_to_use} {
+            foreach contrib ${contribs} {
+                system "echo contrib: \"${contrib}\""
+                system "cd ${worksrcpath}-${arch}/contrib/${contrib}/ && \
+			${destroot.cmd} install ${destroot.destdir}-${arch} && touch DONE"
+            }
+
+            # remove architecture flags from global Makefile
+            reinplace -E "s#-arch\[\[:space:\]\]+\[\[:alnum:\]_\]+##g" \
+                ${destroot}-${arch}${prefix}/lib/${name}/pgxs/src/Makefile.global
+
+            reinplace "s#${worksrcpath}-${arch}#${worksrcpath}#g" \
+                ${destroot}-${arch}${prefix}/lib/${name}/pgxs/src/Makefile.global
+        }
+    }
+}
+
+post-destroot {
+	system "cd ${destroot}${prefix}/bin && ln -sf ${libdir}/bin/psql psql95"
+	file delete -force ${destroot}${prefix}/share/doc/postgresql \
+		${destroot}${prefix}/share/man
 	
 	reinplace -E "s#^CFLAGS =#CFLAGS +=#g" \
 	    ${destroot}${prefix}/lib/${name}/pgxs/src/Makefile.global
