diff -r -c pgsql.orig/src/Makefile.global.in pgsql/src/Makefile.global.in
*** pgsql.orig/src/Makefile.global.in	2006-09-19 08:35:52.000000000 +0200
--- pgsql/src/Makefile.global.in	2006-09-19 12:19:15.000000000 +0200
***************
*** 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 pgsql.orig/src/makefiles/Makefile.aix pgsql/src/makefiles/Makefile.aix
*** pgsql.orig/src/makefiles/Makefile.aix	2006-09-19 08:35:52.000000000 +0200
--- pgsql/src/makefiles/Makefile.aix	2006-09-19 12:19:15.000000000 +0200
***************
*** 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)
diff -r -c pgsql.orig/src/Makefile.shlib pgsql/src/Makefile.shlib
*** pgsql.orig/src/Makefile.shlib	2006-09-19 08:35:52.000000000 +0200
--- pgsql/src/Makefile.shlib	2006-09-19 12:19:15.000000000 +0200
***************
*** 96,103 ****
  soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
  
  ifeq ($(PORTNAME), aix)
!   shlib			= lib$(NAME)$(DLSUFFIX)
! #   SHLIB_LINK		+= -lc
  endif
  
  ifeq ($(PORTNAME), darwin)
--- 96,103 ----
  soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
  
  ifeq ($(PORTNAME), aix)
!   shlib			= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
!   haslibarule   = yes
  endif
  
  ifeq ($(PORTNAME), darwin)
***************
*** 295,303 ****
  else # PORTNAME == aix
  
  # AIX case
! $(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)
  	
  endif # PORTNAME == aix
  
--- 295,307 ----
  else # PORTNAME == aix
  
  # AIX case
! $(shlib) lib$(NAME).a: $(OBJS)
! 	$(LINK.static) lib$(NAME).a $^
! 	$(RANLIB) lib$(NAME).a
  	$(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
! 	$(COMPILER) $(LDFLAGS_NO_L) $(LDFLAGS_SL) -o $(shlib) lib$(NAME).a -Wl,-bE:lib$(NAME)$(EXPSUFF) $(SHLIB_LINK)
! 	rm -f lib$(NAME).a
! 	$(AR) $(AROPT) lib$(NAME).a $(shlib)
  	
  endif # PORTNAME == aix
  
***************
*** 350,355 ****
--- 354,360 ----
  
  ifeq ($(enable_shared), yes)
  install-lib-shared: $(shlib)
+ ifneq ($(PORTNAME), aix)		# we don't install $(shlib) on AIX
  	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
  ifneq ($(PORTNAME), cygwin)
  ifneq ($(PORTNAME), win32)
***************
*** 365,370 ****
--- 370,376 ----
  endif
  endif # not win32
  endif # not cygwin
+ endif # not aix
  endif # enable_shared
  
  
diff -r -c pgsql.orig/src/test/regress/pg_regress.c pgsql/src/test/regress/pg_regress.c
*** pgsql.orig/src/test/regress/pg_regress.c	2006-09-19 08:35:54.000000000 +0200
--- pgsql/src/test/regress/pg_regress.c	2006-09-19 12:19:15.000000000 +0200
***************
*** 512,517 ****
--- 512,518 ----
  		 * dlopen'ed ones)  Feel free to account for others as well.
  		 */
  		add_to_path("LD_LIBRARY_PATH", ':', libdir);
+ 		add_to_path("LIBPATH", ':', libdir);
  		add_to_path("DYLD_LIBRARY_PATH", ':', libdir);
  #if defined(WIN32) || defined(__CYGWIN__)
  		add_to_path("PATH", ';', libdir);
diff -r -c pgsql.orig/src/interfaces/ecpg/test/pg_regress.sh pgsql/src/interfaces/ecpg/test/pg_regress.sh
*** pgsql.orig/src/interfaces/ecpg/test/pg_regress.sh	2006-09-19 08:35:52.000000000 +0200
--- pgsql/src/interfaces/ecpg/test/pg_regress.sh	2006-09-19 12:19:15.000000000 +0200
***************
*** 332,337 ****
--- 332,344 ----
      fi
      export LD_LIBRARY_PATH
  
+     if [ -n "$LIBPATH" ]; then
+         LIBPATH="$libdir:$LIBPATH"
+     else
+         LIBPATH=$libdir
+     fi
+     export LIBPATH
+ 
      if [ -n "$DYLD_LIBRARY_PATH" ]; then
          DYLD_LIBRARY_PATH="$libdir:$DYLD_LIBRARY_PATH"
      else
diff -r -c pgsql.orig/src/interfaces/ecpg/test/compat_informix/Makefile pgsql/src/interfaces/ecpg/test/compat_informix/Makefile
*** pgsql.orig/src/interfaces/ecpg/test/compat_informix/Makefile	2006-09-19 08:35:52.000000000 +0200
--- pgsql/src/interfaces/ecpg/test/compat_informix/Makefile	2006-09-19 15:08:03.000000000 +0200
***************
*** 7,13 ****
  ECPG += -C INFORMIX
  ECPG_NOIND  = $(ECPG) -r no_indicator
  override LDFLAGS += -L../../compatlib
! override LIBS += $(LIBS) -lecpg_compat
  
  TESTS = test_informix test_informix.c \
          test_informix2 test_informix2.c \
--- 7,13 ----
  ECPG += -C INFORMIX
  ECPG_NOIND  = $(ECPG) -r no_indicator
  override LDFLAGS += -L../../compatlib
! override LIBS += -lecpg_compat $(LIBS)
  
  TESTS = test_informix test_informix.c \
          test_informix2 test_informix2.c \
diff -r -c pgsql.orig/src/interfaces/ecpg/test/Makefile.regress pgsql/src/interfaces/ecpg/test/Makefile.regress
*** pgsql.orig/src/interfaces/ecpg/test/Makefile.regress	2006-09-19 08:35:52.000000000 +0200
--- pgsql/src/interfaces/ecpg/test/Makefile.regress	2006-09-19 15:05:17.000000000 +0200
***************
*** 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 := -lecpg -lpgtypes $(LIBS) $(PTHREAD_LIBS) $(libpq)
  
  ECPG = ../../preproc/ecpg -I$(srcdir)/../../include
  
