diff --git a/doc/FAQ_AIX b/doc/FAQ_AIX
index 74a1fd576880e4d15efbfc002a623aa6af2265c5..8d6d346ed8be9c1c13c4370845d993878f6aaf14 100644
--- a/doc/FAQ_AIX
+++ b/doc/FAQ_AIX
@@ -1,5 +1,5 @@
 From: Zeugswetter Andreas <ZeugswetterA@spardat.at>
-Fri Feb  1 17:24:51 NFT 2002
+Fri Sep 27 12:33:36 MSZ 2002
 
 On AIX 4.3.2 PostgreSQL compiled with the native IBM compiler xlc 
 (vac.C 5.0.1) passes all regression tests.
@@ -22,6 +22,9 @@ which you can safely ignore.
 Compiling PostgreSQL with gcc (2.95.3) on AIX also works.
 Use the configure flags: --with-CC=gcc
 
+You need libm.a that is in the fileset bos.adt.libm (try following command)
+$ lslpp -l bos.adt.libm
+
 Since the mktime() function does not work on AIX for dates before
 1970, all localtime formatted datetimes will not use summer time for
 dates before 1970.
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index bf746a463388379c07fc0f3e9d111bfabc7b8e25..eaf341855f732895eaa63f65c0168cc3c34a2c6e 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -6,7 +6,7 @@
 # Copyright (c) 1998, Regents of the University of California
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.64 2002/09/05 18:28:46 petere Exp $
+#    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.65 2002/10/09 16:21:54 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -77,7 +77,7 @@ soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
 
 ifeq ($(PORTNAME), aix)
   shlib			:= lib$(NAME)$(DLSUFFIX)
-  SHLIB_LINK		+= -lc
+#   SHLIB_LINK		+= -lc
 endif
 
 ifeq ($(PORTNAME), darwin)
@@ -267,8 +267,8 @@ else # PORTNAME == aix
 # AIX case
 $(shlib): lib$(NAME).a
 	$(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
-	$(COMPILER) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) $(LDFLAGS_SL) -Wl,-bnoentry
-
+	$(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
+	
 endif # PORTNAME == aix
 
 else # PORTNAME == win
diff --git a/src/backend/Makefile b/src/backend/Makefile
index df445615ae0fe39ddada66c70203f19d7c28c046..5cdfecac543637a2220c81ba45072cf4b07ce12a 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.87 2002/09/05 18:28:46 petere Exp $
+# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.88 2002/10/09 16:21:54 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -53,6 +53,25 @@ libpostgres.a: postgres.def
 
 endif # win
 
+ifeq ($(PORTNAME), aix)
+
+postgres: $(POSTGRES_IMP)
+	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
+
+$(POSTGRES_IMP): $(OBJS)
+	$(LD) $(LDREL) $(LDOUT) SUBSYS.o $^
+ifeq ($(host_os), aix3.2.5)
+	$(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
+else
+ifneq (,$(findstring aix4.1, $(host_os)))
+	$(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
+else
+	$(MKLDEXPORT) SUBSYS.o . > $@
+endif
+endif
+	@rm -f SUBSYS.o
+
+endif # aix
 
 # Parallel make trickery
 $(OBJS): $(DIRS:%=%-recursive) ;
diff --git a/src/backend/port/aix/mkldexport.sh b/src/backend/port/aix/mkldexport.sh
index ccf09887393bc9126192fa8bf1e7bfd4bbfb8fe3..5eca61be605d051d2ee27943ed9ad8c9e3539cee 100755
--- a/src/backend/port/aix/mkldexport.sh
+++ b/src/backend/port/aix/mkldexport.sh
@@ -47,7 +47,7 @@ else
 		# for the base executable (AIX 4.2 and up)
 		echo '#! .'
 	else
-		echo '#!' $2/$OBJNAME
+		echo '#!' $2
 	fi
 fi
 $NM -BCg $1 | \
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
index 0044a8f3ca26e0182ba65a79a519a61712015214..bb0c2fd58b81ce9ef03820215cfb74cebbf24fc2 100644
--- a/src/makefiles/Makefile.aix
+++ b/src/makefiles/Makefile.aix
@@ -7,12 +7,12 @@ MK_NO_LORDER= true
 AROPT = crs
 
 DLSUFFIX = .so
-ifneq ($(GCC), yes)
 ifeq ($(host_os), aix3.2.5)
-	LDFLAGS_SL = -e _nostart
-else
-	LDFLAGS_SL = -bnoentry
+ifneq ($(GCC), yes)
+	LDFLAGS_SL = -e _nostart -H512 -bM:SRE
 endif
+else
+	LDFLAGS_SL = -Wl,-bnoentry -Wl,-H512 -Wl,-bM:SRE
 endif
 
 
@@ -23,24 +23,11 @@ POSTGRES_IMP= postgres$(IMPSUFF)
 
 MKLDEXPORT=$(top_srcdir)/src/backend/port/aix/mkldexport.sh
 
-$(POSTGRES_IMP):
-	@echo Making $@
-ifeq ($(host_os), aix3.2.5)
-	$(MKLDEXPORT) postgres $(bindir) > $@
-else
-ifneq (,$(findstring aix4.1, $(host_os)))
-	$(MKLDEXPORT) postgres $(bindir) > $@
-else
-	$(MKLDEXPORT) postgres . > $@
-endif
-endif
-	$(CC) -Wl,-bE:$(top_builddir)/src/backend/$@ -o postgres $(OBJS) $(LDFLAGS) $(LIBS)
-
 %$(EXPSUFF): %.o
 	$(MKLDEXPORT) $*.o > $*$(EXPSUFF)
 
 %$(DLSUFFIX): %.o %$(EXPSUFF)
 	@echo Making shared library $@ from $*.o, $*$(EXPSUFF) and postgres.imp
-	$(CC) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:$*$(EXPSUFF) -o $@ $*.o $(LDFLAGS) $(LIBS) $(LDFLAGS_SL)
+	$(CC) $(LDFLAGS) $(LDFLAGS_SL) -o $@ $*.o -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:$*$(EXPSUFF) $(LIBS)
 
 sqlmansect = 7