diff -r -c postgres.orig/src/Makefile.global.in postgres/src/Makefile.global.in
*** postgres.orig/src/Makefile.global.in	Fri Sep 15 10:41:03 2006
--- postgres/src/Makefile.global.in	Fri Sep 15 11:00:08 2006
***************
*** 345,357 ****
  ifeq ($(enable_shared), no)
  libpq += $(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt, $(LIBS)) \
  	$(LDAP_LIBS_FE) $(PTHREAD_LIBS)
- else
- # On AIX even shared libraries do not remember their required libs,
- # so again add in what libpq depends on.
- ifeq ($(PORTNAME), aix)
- libpq += $(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt, $(LIBS)) \
- 	$(LDAP_LIBS_FE) $(PTHREAD_LIBS)
- endif
  endif
  
  # This macro is for use by client executables (not libraries) that use libpq.
--- 345,350 ----
diff -r -c postgres.orig/src/Makefile.shlib postgres/src/Makefile.shlib
*** postgres.orig/src/Makefile.shlib	Fri Sep 15 10:41:03 2006
--- postgres/src/Makefile.shlib	Fri Sep 15 14:23:06 2006
***************
*** 96,103 ****
  soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
  
  ifeq ($(PORTNAME), aix)
!   shlib			= lib$(NAME)$(DLSUFFIX)
! #   SHLIB_LINK		+= -lc
  endif
  
  ifeq ($(PORTNAME), darwin)
--- 96,102 ----
  soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
  
  ifeq ($(PORTNAME), aix)
!   shlib			= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
  endif
  
  ifeq ($(PORTNAME), darwin)
***************
*** 298,303 ****
--- 297,305 ----
  $(shlib): lib$(NAME).a
  	$(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
  	$(COMPILER) $(LDFLAGS_NO_L) $(LDFLAGS_SL) -o $@ $< -Wl,-bE:lib$(NAME)$(EXPSUFF) $(SHLIB_LINK)
+ 	rm -f $<
+ 	$(AR) $(AROPT) $< $@
+ 	touch $@
  	
  endif # PORTNAME == aix
  
***************
*** 349,354 ****
--- 351,359 ----
  endif
  
  ifeq ($(enable_shared), yes)
+ ifeq ($(PORTNAME), aix)
+ install-lib-shared: install-lib-static
+ else
  install-lib-shared: $(shlib)
  	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
  ifneq ($(PORTNAME), cygwin)
***************
*** 365,370 ****
--- 370,376 ----
  endif
  endif # not win32
  endif # not cygwin
+ endif # aix
  endif # enable_shared
  
  
diff -r -c postgres.orig/src/interfaces/ecpg/test/Makefile.regress postgres/src/interfaces/ecpg/test/Makefile.regress
*** postgres.orig/src/interfaces/ecpg/test/Makefile.regress	Fri Sep 15 10:41:02 2006
--- postgres/src/interfaces/ecpg/test/Makefile.regress	Fri Sep 15 15:07:53 2006
***************
*** 3,9 ****
  override CFLAGS += $(PTHREAD_CFLAGS) 
  
  override LDFLAGS := -L../../ecpglib -L../../pgtypeslib -L../../../libpq $(LDFLAGS)
! override LIBS := -lpgtypes -lecpg -lpq $(LIBS) $(PTHREAD_LIBS)
  
  ECPG = ../../preproc/ecpg -I$(srcdir)/../../include
  
--- 3,9 ----
  override CFLAGS += $(PTHREAD_CFLAGS) 
  
  override LDFLAGS := -L../../ecpglib -L../../pgtypeslib -L../../../libpq $(LDFLAGS)
! override LIBS := -lpgtypes -lecpg -lpq $(LIBS) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)
  
  ECPG = ../../preproc/ecpg -I$(srcdir)/../../include
  
diff -r -c postgres.orig/src/makefiles/Makefile.aix postgres/src/makefiles/Makefile.aix
*** postgres.orig/src/makefiles/Makefile.aix	Fri Sep 15 10:41:03 2006
--- postgres/src/makefiles/Makefile.aix	Fri Sep 15 14:37:56 2006
***************
*** 5,10 ****
--- 5,18 ----
  RANLIB= touch
  AROPT = crs
  
+ # -blibpath must contain ALL directories where we should look for libraries
+ libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(subst -L , -L,$(strip $(LDFLAGS)))))|sed -e's/ //g'):/usr/lib:/lib
+ ifeq ($(host_os), aix3.2.5)
+ 	rpath = -L$(rpathdir)
+ else
+ 	rpath = -Wl,-blibpath:$(rpathdir)$(libpath)
+ endif
+ 
  DLSUFFIX = .so
  ifeq ($(host_os), aix3.2.5)
  ifneq ($(GCC), yes)
