Compiling libpq with iOS SDK 4.2

I'm trying to compile again the libpq for arm and i386 with the iOS SDK 4.2.

I did last year for SDK3.x without any problems.

Now, when I want to create the fat binary file with two files, I'm getting this error:

specifed architecture type (arm) for file (/Users/montx/mylibs_sdk42/libpq.arm) does not match its cputype (7) and cpusubtype (3) (should be cputype (12) and cpusubtype (0))

I'm compiling again because my compiled files doesn't work with the latest iOS4.2

Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
fcntl$UNIX2003 called from function pg_set_noblock in image GlobalScan.
If you are encountering this problem running a simulator binary within gdb, make sure you 'set start-with-shell off' first.

Here is the complete script. Drop the bash script in the postgres directory and build. In your project include $POSTGRESDIR/src/include and $POSTGRESDIR/src/interfaces/libpq to get the headers necessary. Note this works for Postgres 8. Haven't tested it on Postgres 9.