diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index a2613ebfc16e14a0243630debf37a047704bf792..732d74156866e9684c904eb1f7f966b7239c7dc0 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.50 2001/04/15 03:25:07 tgl Exp $
+#    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.51 2001/05/07 20:43:28 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -194,6 +194,24 @@ ifeq ($(PORTNAME), osf)
   LINK.shared		= $(LD) -shared -expect_unresolved '*'
 endif
 
+ifeq ($(PORTNAME), sco)
+  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
+  ifndef cplusplus
+    ifeq ($(GCC), yes)
+      LINK.shared	= $(CC) -shared
+    else
+      LINK.shared	= $(CC) -G
+    endif
+  else
+    ifeq ($(GXX), yes)
+      LINK.shared	= $(CXX) -shared
+    else
+      LINK.shared	= $(CXX) -G
+    endif
+  endif
+  LINK.shared		+= -Wl,-z,text -Wl,-h,$(soname)
+endif
+
 ifeq ($(PORTNAME), svr4)
   shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
   LINK.shared		= $(LD) -G
diff --git a/src/makefiles/Makefile.sco b/src/makefiles/Makefile.sco
index 810f75947e2c30a2e339a0f15d1d518b6ed7570d..a2fedb22f0d6d5069c4f8a4ea2f219a47e5baff8 100644
--- a/src/makefiles/Makefile.sco
+++ b/src/makefiles/Makefile.sco
@@ -1,9 +1,18 @@
-override CFLAGS += -dy
-export_dynamic = -W l,-Bexport
 AROPT = cr
+export_dynamic = -Wl,-Bexport
+shlib_symbolic = -Wl,-Bsymbolic
 
 DLSUFFIX = .so
+ifeq ($(GCC), yes)
+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 $@ $<
diff --git a/src/template/sco b/src/template/sco
index 8b3a7bf0b724f4a703f3e71f8a619eba2b4ea17c..ce38e57d59b786f04091b7569b7c3085ba8bdf32 100644
--- a/src/template/sco
+++ b/src/template/sco
@@ -1,2 +1,6 @@
-CFLAGS=
-CC="$CC -b elf"
+if test "$GCC" = yes; then
+  CFLAGS=-02
+else
+  CFLAGS=-O
+  CC="$CC -b elf"
+fi