From 23119d51a14c046dae35ae5e6ad9e35982d044fd Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 25 Mar 2022 08:44:31 +0100 Subject: [PATCH] Refactor DLSUFFIX handling 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 Discussion: https://www.postgresql.org/message-id/2f9861fb-8969-9005-7518-b8e60f2bead9@enterprisedb.com --- config/python.m4 | 4 +++- configure | 14 +++++++++++++- configure.ac | 7 +++++++ src/Makefile.global.in | 2 ++ src/backend/jit/Makefile | 2 -- src/backend/utils/fmgr/Makefile | 2 -- src/backend/utils/fmgr/dfmgr.c | 5 ----- src/bin/pg_upgrade/Makefile | 2 +- src/include/pg_config.h.in | 3 +++ src/include/port/win32_port.h | 3 --- src/interfaces/ecpg/test/Makefile | 1 - src/makefiles/Makefile.aix | 1 - src/makefiles/Makefile.cygwin | 1 - src/makefiles/Makefile.darwin | 2 -- src/makefiles/Makefile.freebsd | 2 -- src/makefiles/Makefile.hpux | 6 ------ src/makefiles/Makefile.linux | 2 -- src/makefiles/Makefile.netbsd | 2 -- src/makefiles/Makefile.openbsd | 2 -- src/makefiles/Makefile.solaris | 2 -- src/makefiles/Makefile.win32 | 1 - src/template/cygwin | 2 ++ src/template/hpux | 7 +++++++ src/template/win32 | 2 ++ src/test/regress/GNUmakefile | 3 +-- src/tools/msvc/Solution.pm | 1 + 26 files changed, 42 insertions(+), 39 deletions(-) diff --git a/config/python.m4 b/config/python.m4 index 52f34070dd8..e500873ff3c 100644 --- a/config/python.m4 +++ b/config/python.m4 @@ -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" diff --git a/configure b/configure index e066cbe2c87..8b361e211b8 100755 --- 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" diff --git a/configure.ac b/configure.ac index 078381e5680..68ade8f7a64 100644 --- a/configure.ac +++ b/configure.ac @@ -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 # diff --git a/src/Makefile.global.in b/src/Makefile.global.in index bbdc1c4bda6..0726b2020ff 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -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 diff --git a/src/backend/jit/Makefile b/src/backend/jit/Makefile index a895ebac5fb..a9a603e6392 100644 --- a/src/backend/jit/Makefile +++ b/src/backend/jit/Makefile @@ -15,8 +15,6 @@ subdir = src/backend/jit top_builddir = ../../.. include $(top_builddir)/src/Makefile.global -override CPPFLAGS += -DDLSUFFIX=\"$(DLSUFFIX)\" - OBJS = \ jit.o diff --git a/src/backend/utils/fmgr/Makefile b/src/backend/utils/fmgr/Makefile index f552b95ca99..ceffb807fbb 100644 --- a/src/backend/utils/fmgr/Makefile +++ b/src/backend/utils/fmgr/Makefile @@ -17,6 +17,4 @@ OBJS = \ fmgr.o \ funcapi.o -override CPPFLAGS += -DDLSUFFIX=\"$(DLSUFFIX)\" - include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c index 050da780804..3774f33e0e9 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -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 diff --git a/src/bin/pg_upgrade/Makefile b/src/bin/pg_upgrade/Makefile index 49b94f0ac79..7a3225b27c1 100644 --- a/src/bin/pg_upgrade/Makefile +++ b/src/bin/pg_upgrade/Makefile @@ -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 diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 635fbb2181c..9e2ca83993c 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -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 diff --git a/src/include/port/win32_port.h b/src/include/port/win32_port.h index d3cb765976c..4bb6fc5e1e3 100644 --- a/src/include/port/win32_port.h +++ b/src/include/port/win32_port.h @@ -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)) || \ diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile index be53b7b94dc..10f53c708c8 100644 --- a/src/interfaces/ecpg/test/Makefile +++ b/src/interfaces/ecpg/test/Makefile @@ -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 diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix index ba3695dd570..84f26b49b87 100644 --- a/src/makefiles/Makefile.aix +++ b/src/makefiles/Makefile.aix @@ -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 diff --git a/src/makefiles/Makefile.cygwin b/src/makefiles/Makefile.cygwin index 81089d6257b..6afa9a06a1b 100644 --- a/src/makefiles/Makefile.cygwin +++ b/src/makefiles/Makefile.cygwin @@ -11,7 +11,6 @@ endif LIBS:=$(filter-out -lm -lc, $(LIBS)) AROPT = crs -DLSUFFIX = .dll override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT) diff --git a/src/makefiles/Makefile.darwin b/src/makefiles/Makefile.darwin index b17598f0586..4fc81c1584a 100644 --- a/src/makefiles/Makefile.darwin +++ b/src/makefiles/Makefile.darwin @@ -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 diff --git a/src/makefiles/Makefile.freebsd b/src/makefiles/Makefile.freebsd index 75db21ba145..0e77616b0f9 100644 --- a/src/makefiles/Makefile.freebsd +++ b/src/makefiles/Makefile.freebsd @@ -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 diff --git a/src/makefiles/Makefile.hpux b/src/makefiles/Makefile.hpux index 7e18770d896..25e036bd8d5 100644 --- a/src/makefiles/Makefile.hpux +++ b/src/makefiles/Makefile.hpux @@ -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 diff --git a/src/makefiles/Makefile.linux b/src/makefiles/Makefile.linux index 645f73aa2b7..1ffec9d1698 100644 --- a/src/makefiles/Makefile.linux +++ b/src/makefiles/Makefile.linux @@ -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 diff --git a/src/makefiles/Makefile.netbsd b/src/makefiles/Makefile.netbsd index 6f9cb1d45d1..421b735e407 100644 --- a/src/makefiles/Makefile.netbsd +++ b/src/makefiles/Makefile.netbsd @@ -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 diff --git a/src/makefiles/Makefile.openbsd b/src/makefiles/Makefile.openbsd index 6f9cb1d45d1..421b735e407 100644 --- a/src/makefiles/Makefile.openbsd +++ b/src/makefiles/Makefile.openbsd @@ -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 diff --git a/src/makefiles/Makefile.solaris b/src/makefiles/Makefile.solaris index 62a6c01c3a3..5496edcafc1 100644 --- a/src/makefiles/Makefile.solaris +++ b/src/makefiles/Makefile.solaris @@ -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 diff --git a/src/makefiles/Makefile.win32 b/src/makefiles/Makefile.win32 index e72cb2db0e5..17d68196442 100644 --- a/src/makefiles/Makefile.win32 +++ b/src/makefiles/Makefile.win32 @@ -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))) diff --git a/src/template/cygwin b/src/template/cygwin index 1e7274bc33a..3f42e2f8b69 100644 --- a/src/template/cygwin +++ b/src/template/cygwin @@ -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" diff --git a/src/template/hpux b/src/template/hpux index 50fff80c530..5105a74c78f 100644 --- a/src/template/hpux +++ b/src/template/hpux @@ -25,3 +25,10 @@ case $host in fi ;; esac + +case $host_cpu in + ia64) + DLSUFFIX=".so";; + *) + DLSUFFIX=".sl";; +esac diff --git a/src/template/win32 b/src/template/win32 index 1380d16548c..1895f067a88 100644 --- a/src/template/win32 +++ b/src/template/win32 @@ -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" diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile index b40361c84c3..88b82d92687 100644 --- a/src/test/regress/GNUmakefile +++ b/src/test/regress/GNUmakefile @@ -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 diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index a21ea9bef90..ef5476d0347 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -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,