diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 2d7cc4a0e1f79d203005afdc078ca3a8689119ba..8021d206011f3b9bafa0aadeeebc28355c34f727 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.31 2000/10/31 19:55:18 petere Exp $
+#    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.32 2000/11/04 16:35:54 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -88,13 +88,13 @@ ifeq ($(enable_shared), yes)
 
 # Try to keep the sections in some kind of order, folks...
 
-# XXX fix Makefile.aix
-ifneq ($(PORTNAME), aix)
-  ifndef cplusplus
-    override CFLAGS	+= $(CFLAGS_SL)
-  else
-    override CXXFLAGS	+= $(CFLAGS_SL)
+ifndef cplusplus
+  override CFLAGS	+= $(CFLAGS_SL)
+else
+  ifndef CXXFLAGS_SL
+    CXXFLAGS_SL = $(CFLAGS_SL)
   endif
+  override CXXFLAGS	+= $(CXXFLAGS_SL)
 endif
 
 
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
index bb9c8f255c5ea075ec50da4a174a55e1d0d5dd1f..80d949d2e6e03ab8b7b3a81aa898f63f196922fc 100644
--- a/src/makefiles/Makefile.aix
+++ b/src/makefiles/Makefile.aix
@@ -9,13 +9,12 @@ AROPT = crs
 DLSUFFIX = .so
 ifneq ($(GCC), yes)
   ifeq ($(host_os), aix3.2.5)
-    CFLAGS_SL = -e _nostart
+    LDFLAGS_SL = -e _nostart
   endif
   ifeq ($(host_os), aix4.1)
-    CFLAGS_SL = -bnoentry
+    LDFLAGS_SL = -bnoentry
   endif
 endif
-CFLAGS_SL += -lc
 
 
 EXPSUFF= .exp
@@ -35,4 +34,4 @@ $(POSTGRES_IMP):
 
 %$(DLSUFFIX): %.o %$(EXPSUFF)
 	@echo Making shared library $@ from $*.o, $*$(EXPSUFF), and installed postgres.imp
-	$(CC) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(libdir)/$(POSTGRES_IMP) -Wl,-bE:$*$(EXPSUFF) -o $@ $*.o $(LDFLAGS) $(CFLAGS_SL)
+	$(CC) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(libdir)/$(POSTGRES_IMP) -Wl,-bE:$*$(EXPSUFF) -o $@ $*.o $(LDFLAGS) $(LDFLAGS_SL) -lc
diff --git a/src/makefiles/Makefile.hpux b/src/makefiles/Makefile.hpux
index a3eb0ec1cd666b3a86a2860a6e1a15a420abc282..f76874932e58858cdaeb9997a0bfb3cf5e217680 100644
--- a/src/makefiles/Makefile.hpux
+++ b/src/makefiles/Makefile.hpux
@@ -38,6 +38,11 @@ CFLAGS_SL = -fPIC
 else
 CFLAGS_SL = +z
 endif
+ifeq ($(GXX), yes)
+CXXFLAGS_SL = -fPIC
+else
+CXXFLAGS_SL = +z
+endif
 
 # Rule for building shared libs (currently used only for regression test
 # shlib ... should go away, since this is not really enough knowledge)
diff --git a/src/makefiles/Makefile.solaris b/src/makefiles/Makefile.solaris
index cf0645006276e30bb7af028f78837f45bd5bef55..e8d23c948f208b64b2edb694c1211078da6e7258 100644
--- a/src/makefiles/Makefile.solaris
+++ b/src/makefiles/Makefile.solaris
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/src/makefiles/Makefile.solaris,v 1.4 2000/10/27 23:59:39 petere Exp $
+# $Header: /cvsroot/pgsql/src/makefiles/Makefile.solaris,v 1.5 2000/11/04 16:35:55 petere Exp $
 
 AROPT = crs
 
@@ -16,6 +16,11 @@ CFLAGS_SL = -fPIC
 else
 CFLAGS_SL = -KPIC
 endif
+ifeq ($(GXX), yes)
+CXXFLAGS_SL = -fPIC
+else
+CXXFLAGS_SL = -KPIC
+endif
 
 %.so: %.o
 	$(LD) -G -Bdynamic -o $@ $<
diff --git a/src/makefiles/Makefile.sunos4 b/src/makefiles/Makefile.sunos4
index 0b8542b4f2f168fc2b23b5b28954e08c3b63af06..00bf9064ef9ad45573ceff772966eab412f8a402 100644
--- a/src/makefiles/Makefile.sunos4
+++ b/src/makefiles/Makefile.sunos4
@@ -6,6 +6,11 @@ CFLAGS_SL = -fPIC
 else
 CFLAGS_SL = -PIC
 endif
+ifeq ($(GXX), yes)
+CXXFLAGS_SL = -fPIC
+else
+CXXFLAGS_SL = -PIC
+endif
 
 %.so: %.o
 	$(LD) -dc -dp -Bdynamic -o $@ $<
diff --git a/src/makefiles/Makefile.unixware b/src/makefiles/Makefile.unixware
index 709e2b5c6fe99cfe20f62f5eae0ae8482cacf5fc..e78621d97568202bab7a5fdc45ed3bdc04c99801 100644
--- a/src/makefiles/Makefile.unixware
+++ b/src/makefiles/Makefile.unixware
@@ -7,6 +7,11 @@ CFLAGS_SL = -fpic
 else
 CFLAGS_SL = -K PIC
 endif
+ifeq ($(GXX), yes)
+CXXFLAGS_SL = -fpic
+else
+CXXFLAGS_SL = -K PIC
+endif
 
 %.so: %.o
 	$(LD) -G -Bdynamic -o $@ $<