diff --git a/configure b/configure
index 02a905b..1d664a4 100755
--- a/configure
+++ b/configure
@@ -728,6 +728,7 @@ autodepend
 TAS
 GCC
 CPP
+CFLAGS_SL
 BITCODE_CXXFLAGS
 BITCODE_CFLAGS
 CFLAGS_VECTOR
@@ -6579,7 +6580,6 @@ fi
 
 fi
 
-CFLAGS_VECTOR=$CFLAGS_VECTOR
 
 
 # Determine flags used to emit bitcode for JIT inlining. Need to test
@@ -6899,9 +6899,10 @@ CXXFLAGS="$CXXFLAGS $user_CXXFLAGS"
 BITCODE_CFLAGS="$BITCODE_CFLAGS $user_BITCODE_CFLAGS"
 BITCODE_CXXFLAGS="$BITCODE_CXXFLAGS $user_BITCODE_CXXFLAGS"
 
-BITCODE_CFLAGS=$BITCODE_CFLAGS
 
-BITCODE_CXXFLAGS=$BITCODE_CXXFLAGS
+
+
+# The template file must set up CFLAGS_SL; we don't support user override
 
 
 # Check if the compiler still works with the final flag settings
diff --git a/configure.in b/configure.in
index 88d3a59..50f4b26 100644
--- a/configure.in
+++ b/configure.in
@@ -547,7 +547,7 @@ elif test "$PORTNAME" = "hpux"; then
   PGAC_PROG_CXX_CFLAGS_OPT([+Olibmerrno])
 fi
 
-AC_SUBST(CFLAGS_VECTOR, $CFLAGS_VECTOR)
+AC_SUBST(CFLAGS_VECTOR)
 
 # Determine flags used to emit bitcode for JIT inlining. Need to test
 # for behaviour changing compiler flags, to keep compatibility with
@@ -607,8 +607,11 @@ CXXFLAGS="$CXXFLAGS $user_CXXFLAGS"
 BITCODE_CFLAGS="$BITCODE_CFLAGS $user_BITCODE_CFLAGS"
 BITCODE_CXXFLAGS="$BITCODE_CXXFLAGS $user_BITCODE_CXXFLAGS"
 
-AC_SUBST(BITCODE_CFLAGS, $BITCODE_CFLAGS)
-AC_SUBST(BITCODE_CXXFLAGS, $BITCODE_CXXFLAGS)
+AC_SUBST(BITCODE_CFLAGS)
+AC_SUBST(BITCODE_CXXFLAGS)
+
+# The template file must set up CFLAGS_SL; we don't support user override
+AC_SUBST(CFLAGS_SL)
 
 # Check if the compiler still works with the final flag settings
 # (note, we're not checking that for CXX, which is optional)
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 2d21068..05b6638 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -258,6 +258,7 @@ GCC = @GCC@
 SUN_STUDIO_CC = @SUN_STUDIO_CC@
 CXX = @CXX@
 CFLAGS = @CFLAGS@
+CFLAGS_SL = @CFLAGS_SL@
 CFLAGS_VECTOR = @CFLAGS_VECTOR@
 CFLAGS_SSE42 = @CFLAGS_SSE42@
 CFLAGS_ARMV8_CRC32C = @CFLAGS_ARMV8_CRC32C@
diff --git a/src/makefiles/Makefile.cygwin b/src/makefiles/Makefile.cygwin
index f274d80..81089d6 100644
--- a/src/makefiles/Makefile.cygwin
+++ b/src/makefiles/Makefile.cygwin
@@ -12,7 +12,6 @@ LIBS:=$(filter-out -lm -lc, $(LIBS))
 
 AROPT = crs
 DLSUFFIX = .dll
-CFLAGS_SL =
 
 override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
 
diff --git a/src/makefiles/Makefile.freebsd b/src/makefiles/Makefile.freebsd
index c462e2f..75db21b 100644
--- a/src/makefiles/Makefile.freebsd
+++ b/src/makefiles/Makefile.freebsd
@@ -5,8 +5,6 @@ rpath = -Wl,-R'$(rpathdir)'
 
 DLSUFFIX = .so
 
-CFLAGS_SL = -fPIC -DPIC
-
 # extra stuff for $(with_temp_install)
 # we need this to get LD_LIBRARY_PATH searched ahead of the compiled-in
 # rpath, if no DT_RUNPATH is present in the executable. The conditions
diff --git a/src/makefiles/Makefile.hpux b/src/makefiles/Makefile.hpux
index c871fb0..7e18770 100644
--- a/src/makefiles/Makefile.hpux
+++ b/src/makefiles/Makefile.hpux
@@ -30,11 +30,6 @@ ifeq ($(host_cpu), ia64)
 else
    DLSUFFIX = .sl
 endif
-ifeq ($(GCC), yes)
-   CFLAGS_SL = -fPIC
-else
-   CFLAGS_SL = +Z
-endif
 
 # env var name to use in place of LD_LIBRARY_PATH
 ld_library_path_var = SHLIB_PATH
diff --git a/src/makefiles/Makefile.linux b/src/makefiles/Makefile.linux
index ac58fe4..645f73a 100644
--- a/src/makefiles/Makefile.linux
+++ b/src/makefiles/Makefile.linux
@@ -7,8 +7,6 @@ rpath = -Wl,-rpath,'$(rpathdir)',--enable-new-dtags
 
 DLSUFFIX = .so
 
-CFLAGS_SL = -fPIC
-
 
 # Rule for building a shared library from a single .o file
 %.so: %.o
diff --git a/src/makefiles/Makefile.netbsd b/src/makefiles/Makefile.netbsd
index 15695fb..6f9cb1d 100644
--- a/src/makefiles/Makefile.netbsd
+++ b/src/makefiles/Makefile.netbsd
@@ -5,8 +5,6 @@ rpath = -Wl,-R'$(rpathdir)'
 
 DLSUFFIX = .so
 
-CFLAGS_SL = -fPIC -DPIC
-
 
 # Rule for building a shared library from a single .o file
 %.so: %.o
diff --git a/src/makefiles/Makefile.openbsd b/src/makefiles/Makefile.openbsd
index 15695fb..6f9cb1d 100644
--- a/src/makefiles/Makefile.openbsd
+++ b/src/makefiles/Makefile.openbsd
@@ -5,8 +5,6 @@ rpath = -Wl,-R'$(rpathdir)'
 
 DLSUFFIX = .so
 
-CFLAGS_SL = -fPIC -DPIC
-
 
 # Rule for building a shared library from a single .o file
 %.so: %.o
diff --git a/src/makefiles/Makefile.solaris b/src/makefiles/Makefile.solaris
index a7f5652..62a6c01 100644
--- a/src/makefiles/Makefile.solaris
+++ b/src/makefiles/Makefile.solaris
@@ -10,11 +10,7 @@ rpath = -Wl,-R'$(rpathdir)'
 endif
 
 DLSUFFIX = .so
-ifeq ($(GCC), yes)
-CFLAGS_SL = -fPIC
-else
-CFLAGS_SL = -KPIC
-endif
+
 
 # Rule for building a shared library from a single .o file
 %.so: %.o
diff --git a/src/makefiles/Makefile.win32 b/src/makefiles/Makefile.win32
index 3dea11e..8a7d6ff 100644
--- a/src/makefiles/Makefile.win32
+++ b/src/makefiles/Makefile.win32
@@ -12,7 +12,6 @@ override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
 
 AROPT = crs
 DLSUFFIX = .dll
-CFLAGS_SL =
 
 ifneq (,$(findstring backend,$(subdir)))
 ifeq (,$(findstring conversion_procs,$(subdir)))
diff --git a/src/template/aix b/src/template/aix
index 999cd35..cec240d 100644
--- a/src/template/aix
+++ b/src/template/aix
@@ -1,3 +1,5 @@
+# src/template/aix
+
 # Set default options if using xlc.  This formerly included -qsrcmsg, but that
 # option elicits internal compiler errors from xlc v16.1.0.  Note: configure
 # will add -qnoansialias if the compiler accepts it, even if user specifies a
@@ -17,6 +19,9 @@ if test "$GCC" != yes ; then
   FORCE_DISABLE_RESTRICT=yes
 fi
 
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL=""
+
 # Native memset() is faster, tested on:
 # 	AIX 5.1 and 5.2, XLC 6.0 (IBM's cc)
 # 	AIX 5.3 ML3, gcc 4.0.1
diff --git a/src/template/cygwin b/src/template/cygwin
index b6ea0de..79a1081 100644
--- a/src/template/cygwin
+++ b/src/template/cygwin
@@ -2,6 +2,9 @@
 
 SRCH_LIB="/usr/local/lib"
 
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL=""
+
 # --allow-multiple-definition is required to link pg_dump because it finds
 # pg_toupper() etc. in both libpq and pgport
 # we'd prefer to use --disable-auto-import to match MSVC linking behavior,
diff --git a/src/template/darwin b/src/template/darwin
index c05adca..f4d4e9d 100644
--- a/src/template/darwin
+++ b/src/template/darwin
@@ -16,6 +16,9 @@ if test x"$PG_SYSROOT" != x"" ; then
   fi
 fi
 
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL=""
+
 # Select appropriate semaphore support.  Darwin 6.0 (macOS 10.2) and up
 # support System V semaphores; before that we have to use named POSIX
 # semaphores, which are less good for our purposes because they eat a
diff --git a/src/template/freebsd b/src/template/freebsd
index a82d5a4..41fa4a1 100644
--- a/src/template/freebsd
+++ b/src/template/freebsd
@@ -4,3 +4,6 @@
 if test x"$PREFERRED_SEMAPHORES" = x"" ; then
   PREFERRED_SEMAPHORES=UNNAMED_POSIX
 fi
+
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL="-fPIC -DPIC"
diff --git a/src/template/hpux b/src/template/hpux
index 79d3475..50fff80 100644
--- a/src/template/hpux
+++ b/src/template/hpux
@@ -8,6 +8,13 @@ if test "$GCC" != yes ; then
   CFLAGS="+O2"
 fi
 
+# Extra CFLAGS for code that will go into a shared library
+if test "$GCC" = yes ; then
+  CFLAGS_SL="-fPIC"
+else
+  CFLAGS_SL="+Z"
+fi
+
 # Pick right test-and-set (TAS) code.  We need out-of-line assembler
 # when not using gcc.
 case $host in
diff --git a/src/template/linux b/src/template/linux
index e392908..ec3302c 100644
--- a/src/template/linux
+++ b/src/template/linux
@@ -9,6 +9,9 @@ fi
 # This is also required for ppoll(2), and perhaps other things
 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
 
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL="-fPIC"
+
 # If --enable-profiling is specified, we need -DLINUX_PROFILE
 PLATFORM_PROFILE_FLAGS="-DLINUX_PROFILE"
 
diff --git a/src/template/netbsd b/src/template/netbsd
index 1986977..d97f995 100644
--- a/src/template/netbsd
+++ b/src/template/netbsd
@@ -1,2 +1,5 @@
 # src/template/netbsd
 # tools/thread/thread_test must be run
+
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL="-fPIC -DPIC"
diff --git a/src/template/openbsd b/src/template/openbsd
index e69de29..365268c 100644
--- a/src/template/openbsd
+++ b/src/template/openbsd
@@ -0,0 +1,4 @@
+# src/template/openbsd
+
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL="-fPIC -DPIC"
diff --git a/src/template/solaris b/src/template/solaris
index e07b9a0..f88b1cd 100644
--- a/src/template/solaris
+++ b/src/template/solaris
@@ -1,3 +1,12 @@
+# src/template/solaris
+
+# Extra CFLAGS for code that will go into a shared library
+if test "$GCC" = yes ; then
+  CFLAGS_SL="-fPIC"
+else
+  CFLAGS_SL="-KPIC"
+fi
+
 if test "$SUN_STUDIO_CC" = yes ; then
   CC="$CC -Xa"			# relaxed ISO C mode
   CFLAGS="-v"			# -v is like gcc -Wall
diff --git a/src/template/win32 b/src/template/win32
index 7da9719..1380d16 100644
--- a/src/template/win32
+++ b/src/template/win32
@@ -1,5 +1,8 @@
 # src/template/win32
 
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL=""
+
 # --allow-multiple-definition is required to link pg_dump because it finds
 # pg_toupper() etc. in both libpq and pgport
 # --disable-auto-import is to ensure we get MSVC-like linking behavior
