--- /opt/local/var/macports/sources/rsync.macports.org/release/ports/databases/postgresql83/Portfile
+++ /opt/local/var/macports/sources/rsync.macports.org/release/ports/databases/postgresql83/Portfile
@@ -63,6 +63,34 @@ livecheck.regex	(8.3.\[0-9\]+)
 
 set contribs	"adminpack dblink fuzzystrmatch lo uuid-ossp pg_buffercache pg_trgm pgcrypto tsearch2 vacuumlo xml2"
 
+pre-build {
+	if {[variant_isset universal]} {
+		copy ${portpath}/files/ld.sh ${worksrcpath}/ld.sh
+
+		if {![info exists universal_archs]} {
+			set universal_archs {i386 x86_64 ppc ppc64}
+		}
+
+		set out [open "${worksrcpath}/ld.sh" "a"]
+		foreach arch $universal_archs {
+			puts ${out} "/usr/bin/ld -r -arch ${arch} -o \${output_name}.${arch} \${newargs}"
+		}
+		#
+		puts -nonewline ${out} "/usr/bin/lipo -create "
+		foreach arch $universal_archs {
+			puts -nonewline ${out} "\${output_name}.${arch} "
+		}
+		#
+		puts ${out} "-output \${output_name}"
+		close ${out}
+		system "chmod +x ${worksrcpath}/ld.sh"
+
+		system "cd ${worksrcpath}/src && mv Makefile.global Makefile.global.orig && sed 's#LD =.*#LD = ${worksrcpath}/ld.sh#' Makefile.global.orig > Makefile.global"
+
+		system "cd ${worksrcpath} && patch -p0 < ${portpath}/files/patch_pg_config_h"
+	}
+}
+
 post-build {
 	foreach contrib ${contribs} {
 		system "cd ${worksrcpath}/contrib/${contrib}/ && ${build.cmd}"
@@ -101,6 +129,10 @@ variant tcl description {add Tcl support} {
 	configure.env-append		TCLSH=${prefix}/bin/tclsh
 }
 
+variant gcc42 description {compile with gcc42} {
+	configure.cc	/usr/bin/gcc-4.2
+}
+
 post-install {
 	ui_msg "\nTo use the postgresql server, install the postgresql83-server port"
 }
--- /dev/null
+++ /opt/local/var/macports/sources/rsync.macports.org/release/ports/databases/postgresql83/files/ld.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+newargs=""
+output_flag=0
+output_name=""
+
+for arg in $@
+do
+	if [ "$output_flag" -eq "1" ]
+	then
+		output_flag=2
+		output_name=$arg
+
+	elif [ $arg == "-o" ] && [ "$output_flag" -eq "0" ]
+	then
+		output_flag=1
+
+	elif `echo $arg | grep -E -e "^-o" > /dev/null` && [ "$output_flag" -eq "0" ]
+	then
+		output_name=`echo $arg | sed "s/^-o//"`
+		output_flag=2
+
+	else
+		newargs+="$arg "
+	fi
+done
+
--- /dev/null
+++ /opt/local/var/macports/sources/rsync.macports.org/release/ports/databases/postgresql83/files/patch_pg_config_h
@@ -0,0 +1,15 @@
+--- src/include/pg_config.h.orig	2008-12-16 21:32:17.000000000 +0100
++++ src/include/pg_config.h	2008-12-16 21:33:05.000000000 +0100
+@@ -642,7 +642,11 @@
+ #define SIZEOF_SIZE_T 8
+
+ /* The size of a `unsigned long', as computed by sizeof. */
+-#define SIZEOF_UNSIGNED_LONG 8
++#if defined (__LP64__)
++  #define SIZEOF_UNSIGNED_LONG 8
++#else
++  #define SIZEOF_UNSIGNED_LONG 4
++#endif
+
+ /* Define to 1 if you have the ANSI C header files. */
+ #define STDC_HEADERS 1

