Refactor DLSUFFIX handling
authorPeter Eisentraut <[email protected]>
Fri, 25 Mar 2022 07:44:31 +0000 (08:44 +0100)
committerPeter Eisentraut <[email protected]>
Fri, 25 Mar 2022 07:56:02 +0000 (08:56 +0100)
Move DLSUFFIX from makefiles into header files for all platforms.
Move the DLSUFFIX assignment from src/makefiles/ to src/templates/,
have configure read it, and then substitute it into Makefile.global
and pg_config.h.  This avoids the need for all makefile rules that
need it to locally set CPPFLAGS.  It also resolves an inconsistent
setup between the two Windows build systems.

Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/2f9861fb-8969-9005-7518-b8e60f2bead9@enterprisedb.com

26 files changed:
config/python.m4
configure
configure.ac
src/Makefile.global.in
src/backend/jit/Makefile
src/backend/utils/fmgr/Makefile
src/backend/utils/fmgr/dfmgr.c
src/bin/pg_upgrade/Makefile
src/include/pg_config.h.in
src/include/port/win32_port.h
src/interfaces/ecpg/test/Makefile
src/makefiles/Makefile.aix
src/makefiles/Makefile.cygwin
src/makefiles/Makefile.darwin
src/makefiles/Makefile.freebsd
src/makefiles/Makefile.hpux
src/makefiles/Makefile.linux
src/makefiles/Makefile.netbsd
src/makefiles/Makefile.openbsd
src/makefiles/Makefile.solaris
src/makefiles/Makefile.win32
src/template/cygwin
src/template/hpux
src/template/win32
src/test/regress/GNUmakefile
src/tools/msvc/Solution.pm

index 52f34070dd808f3bea3b020e4528ef81fbdcf9ca..e500873ff3ce4f777daf0901a5d4623744c21ef2 100644 (file)
@@ -120,7 +120,9 @@ else
    found_shlib=0
    for d in "${python_libdir}" "${python_configdir}" /usr/lib64 /usr/lib
    do
-       # We don't know the platform DLSUFFIX here, so check 'em all.
+       # Note: DLSUFFIX is for loadable modules, not shared
+       # libraries, so cannot be used here portably.  Just
+       # check all known possibilities.
        for e in .so .dll .dylib .sl; do
            if test -e "$d/lib${ldlibrary}$e"; then
                python_libdir="$d"
index e066cbe2c8739705ab08b32fd10affde30a668aa..8b361e211b81f09fbd34705875c177aaa28a0091 100755 (executable)
--- a/configure
+++ b/configure
@@ -734,6 +734,7 @@ autodepend
 PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
+DLSUFFIX
 TAS
 GCC
 CPP
@@ -3033,6 +3034,9 @@ PORTNAME=$template
 need_tas=no
 tas_file=dummy.s
 
+# Default, works for most platforms, override in template file if needed
+DLSUFFIX=".so"
+
 
 
 ##
@@ -7688,6 +7692,12 @@ else
 fi
 
 
+
+cat >>confdefs.h <<_ACEOF
+#define DLSUFFIX "$DLSUFFIX"
+_ACEOF
+
+
 #
 # Set up pkg_config in case we need it below
 #
@@ -10560,7 +10570,9 @@ else
    found_shlib=0
    for d in "${python_libdir}" "${python_configdir}" /usr/lib64 /usr/lib
    do
-       # We don't know the platform DLSUFFIX here, so check 'em all.
+       # Note: DLSUFFIX is for loadable modules, not shared
+       # libraries, so cannot be used here portably.  Just
+       # check all known possibilities.
        for e in .so .dll .dylib .sl; do
            if test -e "$d/lib${ldlibrary}$e"; then
                python_libdir="$d"
index 078381e5680a716452582a87ec027c95a7e2ac60..68ade8f7a64c941349f75b48d721e9d3692b23b4 100644 (file)
@@ -103,6 +103,9 @@ AC_SUBST(PORTNAME)
 need_tas=no
 tas_file=dummy.s
 
+# Default, works for most platforms, override in template file if needed
+DLSUFFIX=".so"
+
 
 
 ##
@@ -721,6 +724,10 @@ else
 fi
 AC_SUBST(TAS)
 
+AC_SUBST(DLSUFFIX)dnl
+AC_DEFINE_UNQUOTED([DLSUFFIX], ["$DLSUFFIX"],
+                   [Define to the file name extension of dynamically-loadable modules.])
+
 #
 # Set up pkg_config in case we need it below
 #
index bbdc1c4bda60349bb7333e4d7ae614a990dc52f9..0726b2020ff64cdd1d6b842d84117a23ce774115 100644 (file)
@@ -545,6 +545,8 @@ WIN32_STACK_RLIMIT=4194304
 # Set if we have a working win32 crashdump header
 have_win32_dbghelp = @have_win32_dbghelp@
 
+DLSUFFIX = @DLSUFFIX@
+
 # Pull in platform-specific magic
 include $(top_builddir)/src/Makefile.port
 
index a895ebac5fb58761ac9b58f1663347c7e0a060cb..a9a603e6392fd4ee7d8ce3853f9eeb3febbf2651 100644 (file)
@@ -15,8 +15,6 @@ subdir = src/backend/jit
 top_builddir = ../../..
 include $(top_builddir)/src/Makefile.global
 
-override CPPFLAGS += -DDLSUFFIX=\"$(DLSUFFIX)\"
-
 OBJS = \
    jit.o
 
index f552b95ca99be14b84521a1838785745e70bd6cb..ceffb807fbb7d8bc429e4527cd30d9ab2a249864 100644 (file)
@@ -17,6 +17,4 @@ OBJS = \
    fmgr.o \
    funcapi.o
 
-override CPPFLAGS += -DDLSUFFIX=\"$(DLSUFFIX)\"
-
 include $(top_srcdir)/src/backend/common.mk
index 050da780804660accf44513993a40636963b0a13..3774f33e0e976fce15f53a09e6e988f0ddfac06a 100644 (file)
@@ -483,11 +483,6 @@ file_exists(const char *name)
 }
 
 
-/* Example format: ".so" */
-#ifndef DLSUFFIX
-#error "DLSUFFIX must be defined to compile this file."
-#endif
-
 /*
  * If name contains a slash, check if the file exists, if so return
  * the name.  Else (no slash) try to expand using search path (see
index 49b94f0ac7992dabf570d053d5711d5d5b4c0fc5..7a3225b27c13acb1dba113c2c31773db50e5cd66 100644 (file)
@@ -25,7 +25,7 @@ OBJS = \
    util.o \
    version.o
 
-override CPPFLAGS := -DDLSUFFIX=\"$(DLSUFFIX)\" -I$(srcdir) -I$(libpq_srcdir) $(CPPFLAGS)
+override CPPFLAGS := -I$(srcdir) -I$(libpq_srcdir) $(CPPFLAGS)
 LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport)
 
 all: pg_upgrade
index 635fbb2181c41a80c20a2e800fb156f1db45a78b..9e2ca83993c9ecd2b52a67a00ac8476d8dfcf9fe 100644 (file)
@@ -42,6 +42,9 @@
 /* Define to the default TCP port number as a string constant. */
 #undef DEF_PGPORT_STR
 
+/* Define to the file name extension of dynamically-loadable modules. */
+#undef DLSUFFIX
+
 /* Define to build with GSSAPI support. (--with-gssapi) */
 #undef ENABLE_GSS
 
index d3cb765976c3a1d1ae4cf1e136d2236e56fc46c3..4bb6fc5e1e36ff9e26266dc57556ee3b3179e0d6 100644 (file)
@@ -529,9 +529,6 @@ typedef unsigned short mode_t;
 #define W_OK 2
 #define R_OK 4
 
-/* Pulled from Makefile.port in MinGW */
-#define DLSUFFIX ".dll"
-
 #endif                         /* _MSC_VER */
 
 #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || \
index be53b7b94dc610255b0e4a7a5e256219113663a8..10f53c708c8cdc8f96bb8b4859e230263f95e617 100644 (file)
@@ -12,7 +12,6 @@ override CPPFLAGS := \
    '-I$(top_srcdir)/src/test/regress' \
    '-DHOST_TUPLE="$(host_tuple)"' \
    '-DSHELLPROG="$(SHELL)"' \
-   '-DDLSUFFIX="$(DLSUFFIX)"' \
    $(CPPFLAGS)
 
 # default encoding for regression tests
index ba3695dd5702e4bce414202b55a873bfbc04c3b5..84f26b49b8703202a2dbd53e6d58282aeabad331 100644 (file)
@@ -14,7 +14,6 @@ else
    rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
 endif
 
-DLSUFFIX = .so
 ifeq ($(host_os), aix3.2.5)
 ifneq ($(GCC), yes)
    LDFLAGS_SL += -e _nostart -H512 -bM:SRE
index 81089d6257bf1a24c9c3b8c17b59257e758912c2..6afa9a06a1b90e9393f7dfb367b69c5eafdf21ae 100644 (file)
@@ -11,7 +11,6 @@ endif
 LIBS:=$(filter-out -lm -lc, $(LIBS))
 
 AROPT = crs
-DLSUFFIX = .dll
 
 override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
 
index b17598f0586e0d19777bc5e66f421f9528592b62..4fc81c1584a6daa12473da89f2725a04c01d0976 100644 (file)
@@ -1,7 +1,5 @@
 AROPT = crs
 
-DLSUFFIX = .so
-
 # env var name to use in place of LD_LIBRARY_PATH
 ld_library_path_var = DYLD_LIBRARY_PATH
 
index 75db21ba14501b6d82068f8e4887ac7787817088..0e77616b0f91be81919793b24c2dea1692fa0ace 100644 (file)
@@ -3,8 +3,6 @@ AROPT = cr
 export_dynamic = -Wl,-export-dynamic
 rpath = -Wl,-R'$(rpathdir)'
 
-DLSUFFIX = .so
-
 # 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
index 7e18770d8969c3b927c8dc3317eda94fa4d46b3d..25e036bd8d50bb7ace8543dec279884eb5765ed8 100644 (file)
@@ -25,12 +25,6 @@ INSTALL_SHLIB_OPTS = -m 555
 
 AROPT = crs
 
-ifeq ($(host_cpu), ia64)
-   DLSUFFIX = .so
-else
-   DLSUFFIX = .sl
-endif
-
 # env var name to use in place of LD_LIBRARY_PATH
 ld_library_path_var = SHLIB_PATH
 
index 645f73aa2b74595b7f7cddd3dbe8d89f0656b49d..1ffec9d16980c882ccae1342af3fcb84a36d8c23 100644 (file)
@@ -5,8 +5,6 @@ export_dynamic = -Wl,-E
 # This allows LD_LIBRARY_PATH to still work when needed.
 rpath = -Wl,-rpath,'$(rpathdir)',--enable-new-dtags
 
-DLSUFFIX = .so
-
 
 # Rule for building a shared library from a single .o file
 %.so: %.o
index 6f9cb1d45d1683545da6fbfad8809f233a475c7b..421b735e407e8a4d7c3bc211298b8a2d418f76ce 100644 (file)
@@ -3,8 +3,6 @@ AROPT = cr
 export_dynamic = -Wl,-E
 rpath = -Wl,-R'$(rpathdir)'
 
-DLSUFFIX = .so
-
 
 # Rule for building a shared library from a single .o file
 %.so: %.o
index 6f9cb1d45d1683545da6fbfad8809f233a475c7b..421b735e407e8a4d7c3bc211298b8a2d418f76ce 100644 (file)
@@ -3,8 +3,6 @@ AROPT = cr
 export_dynamic = -Wl,-E
 rpath = -Wl,-R'$(rpathdir)'
 
-DLSUFFIX = .so
-
 
 # Rule for building a shared library from a single .o file
 %.so: %.o
index 62a6c01c3a39ede4a390e23944e30ed055794802..5496edcafc176882e03670c487ec4efd9634b938 100644 (file)
@@ -9,8 +9,6 @@ else
 rpath = -Wl,-R'$(rpathdir)'
 endif
 
-DLSUFFIX = .so
-
 
 # Rule for building a shared library from a single .o file
 %.so: %.o
index e72cb2db0e5c1725854fae59ebc8dab246ee7048..17d68196442cdd12105f60e05c2fdde4567508d6 100644 (file)
@@ -11,7 +11,6 @@ endif
 override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
 
 AROPT = crs
-DLSUFFIX = .dll
 
 ifneq (,$(findstring backend,$(subdir)))
 ifeq (,$(findstring conversion_procs,$(subdir)))
index 1e7274bc33a5ebe500e1386d34224864789852ea..3f42e2f8b69c227fec0518acb7289558521d821b 100644 (file)
@@ -13,3 +13,5 @@ CFLAGS_SL=""
 # we'd prefer to use --disable-auto-import to match MSVC linking behavior,
 # but support for it in Cygwin is too haphazard
 LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition -Wl,--enable-auto-import"
+
+DLSUFFIX=".dll"
index 50fff80c53012e788c9ba0fe9050cf7339e9cba8..5105a74c78f5f9ac9c5c3b96056e3efd51bb1c6b 100644 (file)
@@ -25,3 +25,10 @@ case $host in
    fi
     ;;
 esac
+
+case $host_cpu in
+  ia64)
+    DLSUFFIX=".so";;
+  *)
+    DLSUFFIX=".sl";;
+esac
index 1380d16548ce494f212bed93d517d7e53cd75548..1895f067a889b52ac9b7fd9c23b548774b56dc72 100644 (file)
@@ -7,3 +7,5 @@ CFLAGS_SL=""
 # pg_toupper() etc. in both libpq and pgport
 # --disable-auto-import is to ensure we get MSVC-like linking behavior
 LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition -Wl,--disable-auto-import"
+
+DLSUFFIX=".dll"
index b40361c84c30fccd2dac3afb397c05d158cb17b5..88b82d9268729d11e71c0aeb3d3147a832d17abe 100644 (file)
@@ -25,8 +25,7 @@ endif
 
 # stuff to pass into build of pg_regress
 EXTRADEFS = '-DHOST_TUPLE="$(host_tuple)"' \
-   '-DSHELLPROG="$(SHELL)"' \
-   '-DDLSUFFIX="$(DLSUFFIX)"'
+   '-DSHELLPROG="$(SHELL)"'
 
 ##
 ## Prepare for tests
index a21ea9bef906b141a1a9b1543918bb783fc19981..ef5476d0347bf8fd2f79bd2c85782363ef31995f 100644 (file)
@@ -216,6 +216,7 @@ sub GenerateFiles
        CONFIGURE_ARGS             => '"' . $self->GetFakeConfigure() . '"',
        DEF_PGPORT                 => $port,
        DEF_PGPORT_STR             => qq{"$port"},
+       DLSUFFIX                   => '".dll"',
        ENABLE_GSS                 => $self->{options}->{gss} ? 1 : undef,
        ENABLE_NLS                 => $self->{options}->{nls} ? 1 : undef,
        ENABLE_THREAD_SAFETY       => 1,