--- Portfile.orig	2009-02-22 06:15:44.000000000 -0500
+++ Portfile	2009-03-17 02:49:12.000000000 -0400
@@ -1,10 +1,11 @@
 # $Id: Portfile 47122 2009-02-22 11:15:44Z ryandesign@macports.org $
 
 PortSystem              1.0
+PortGroup               muniversal 1.0
 
 name                    glib2
 set my_name             glib
-version                 2.18.3
+version                 2.20.0
 set branch              [join [lrange [split ${version} .] 0 1] .]
 categories              devel
 maintainers             ryandesign
@@ -27,15 +28,20 @@
     ftp://ftp.gtk.org/pub/${my_name}/${branch}/
 
 checksums \
-    md5     f13996a7bd57525d796a6593f26a7771 \
-    sha1    293f639fb85ea47347eb34e122327c60ef7606e4 \
-    rmd160  cf43fbba04250becaabdb7b7f55bcdec584f019e
+    md5     05188e560dbd8bddd568e24ce10dd003 \
+    sha1    4d653ef39fd1ebe7b64217fd824dfb1bbbde7007 \
+    rmd160  fc343fab4712d20b527ee690dcbf67ff52b3f6fc
 
+# ${prefix}/include/glib-2.0/glib/gi18n.h requires -I${prefix}/opt/local/include to find libintl.h
+# See http://trac.macports.org/changeset/27148
 patchfiles \
     patch-glib-2.0.pc.in.diff \
-    patch-gutils.c.diff \
-    patch-gi18n.h.diff \
-    patch-which.diff
+    patch-gi18n.h.diff
+
+if { ${os.major} < 9 } {
+    # Prior to Leopard, which returns 0 even if it can not find the program.
+    patchfiles-append patch-which.diff
+}
 
 depends_build \
     port:pkgconfig
@@ -46,13 +52,6 @@
     path:bin/perl:perl5 \
     bin:python:python_select
 
-configure.ldflags-append \
-    -bind_at_load
-
-configure.cflags-append \
-    -funroll-loops \
-    -fstrict-aliasing
-
 configure.args \
     --enable-static
 
@@ -62,20 +61,14 @@
 post-patch {
     reinplace "s|data_dirs = \"/usr|data_dirs = \"${prefix}/share:/usr|g" ${worksrcpath}/glib/gutils.c
     reinplace "s|path = \"/bin|path = \"${prefix}/bin:/bin|g" ${worksrcpath}/glib/gutils.c ${worksrcpath}/glib/gspawn.c
+
+    # Allow endian.h to be found.
+    #reinplace "s|endian.h|machine/endian.h|g" ${worksrcpath}/configure
 }
 
 platform darwin {
     patchfiles-append \
-        patch-child-test.c.diff \
-        patch-configure.diff
-}
-
-platform powerpc {
-    if {[variant_isset universal]} {
-        post-configure {
-            reinplace {s|^#define G_ATOMIC_POWERPC 1$|#undef G_ATOMIC_POWERPC|} ${worksrcpath}/config.h
-        }
-    }
+        patch-child-test.c.diff
 }
 
 test.run                yes
@@ -93,8 +86,88 @@
     }
 }
 
-platform darwin 9 {
-    patchfiles-append patch-glib_gutils.h.diff
+if {[variant_isset universal]} {
+    # When cross-compiling, use --config-cache to answer questions configure can't determine without running a program.
+    # When cross-compiling, configure script does not find correct value of NM,
+    #     so replicate NM value found when not cross-compiling.
+    pre-configure {
+        global merger_configure_args merger_configure_env
+
+        if { ${os.arch}=="i386" } {
+            # Determine if any cross-compiling is required.
+            set need_cross  "no"
+            foreach arch ${universal_archs_to_use} {
+                if { ${arch}=="ppc64" || (${os.major} >= 10 && ${arch}=="ppc") } {
+                    set need_cross "yes"
+                }
+            }
+
+            # Find an architecture whose binaries will run on this platform.
+            set run_arch ""
+            foreach arch ${universal_archs_to_use} {
+                if { ${arch}=="i386" || ${arch}=="x86_64" || (${os.major} < 10 && ${arch}=="ppc") } {
+                    set run_arch ${arch}
+                    break
+                }
+            }
+
+            if { ${need_cross}=="yes" && ${run_arch}=="" } {
+                ui_msg "When building a universal binary of ${name}, put i386 first in universal_archs in ${prefix}/etc/macports/macports.conf" 
+ 		return -code error "incompatible universal_archs value" 
+            }
+
+            if { ${os.major} >= 10 } { set merger_configure_args(ppc)  --config-cache }
+            set merger_configure_args(ppc64)  --config-cache
+            if { ${os.major} >= 10 } {
+                set merger_configure_env(ppc)  "NM='/usr/bin/nm -p' GLIB_GENMARSHAL=${workpath}/${run_arch}/gobject/glib-genmarshal"
+            } else {
+                set merger_configure_env(ppc)  "NM='/usr/bin/nm -p'"
+            }
+            set merger_configure_env(ppc64)    "NM='/usr/bin/nm -p' GLIB_GENMARSHAL=${workpath}/${run_arch}/gobject/glib-genmarshal"
+        } else {
+            # Determine if any cross-compiling is required.
+            set need_cross  "no"
+            foreach arch ${universal_archs_to_use} {
+                if { ${arch}=="i386" || ${arch}=="x86_64" } {
+                    set need_cross "yes"
+                }
+            }
+
+            # Find an architecture whose binaries will run on this platform.
+            set run_arch ""
+            foreach arch ${universal_archs_to_use} {
+                if { ${arch}=="ppc" || ${arch}=="ppc64" } {
+                    set run_arch ${arch}
+                    break
+                }
+            }
+
+            if { ${need_cross}=="yes" && ${run_arch}=="" } {
+                ui_msg "When building a universal binary of ${name}, put ppc first in universal_archs in ${prefix}/etc/macports/macports.conf" 
+ 		return -code error "incompatible universal_archs value"
+            }
+            array set merger_configure_args {
+                i386    --config-cache
+                x86_64  --config-cache
+            }
+            set merger_configure_env(i386)    "NM='/usr/bin/nm -p' GLIB_GENMARSHAL=${workpath}/${run_arch}/gobject/glib-genmarshal"
+            set merger_configure_env(x86_64)  "NM='/usr/bin/nm -p' GLIB_GENMARSHAL=${workpath}/${run_arch}/gobject/glib-genmarshal"
+        }
+    }
+
+    post-extract {
+        # Answers to questions configure can't determine without running a program.
+        copy ${filespath}/config.cache ${worksrcpath}
+    }
+
+    pre-destroot {
+        global merger_dont_diff
+
+        # These tests must be done in pre-destroot to ensure universal_archs_to_use has the correct values.
+        if { [llength ${universal_archs_to_use}] > 2 } {
+            set merger_dont_diff ${prefix}/lib/glib-2.0/include/glibconfig.h
+        }
+    }
 }
 
 livecheck.check         regex
