From 763943176a1e0a0c954414ba9da07742ad791656 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 24 Mar 2022 16:00:54 +0100 Subject: [PATCH] Refactor DLSUFFIX handling Move DLSUFFIX 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 of all users to locally set CPPFLAGS. --- config/python.m4 | 4 +++- configure | 13 ++++++++++++- configure.ac | 5 +++++ 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, 39 insertions(+), 39 deletions(-) diff --git a/config/python.m4 b/config/python.m4 index 52f34070dd..e500873ff3 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 e066cbe2c8..519cef76a9 100755 --- a/configure +++ b/configure @@ -743,6 +743,7 @@ BITCODE_CFLAGS CFLAGS_VECTORIZE CFLAGS_UNROLL_LOOPS PERMIT_DECLARATION_AFTER_STATEMENT +DLSUFFIX LLVM_BINPATH LLVM_CXXFLAGS LLVM_CFLAGS @@ -5219,11 +5220,19 @@ fi # fi unset CFLAGS unset CXXFLAGS +DLSUFFIX=".so" + # # Read the template # . "$srcdir/src/template/$template" || exit + + +cat >>confdefs.h <<_ACEOF +#define DLSUFFIX "$DLSUFFIX" +_ACEOF + # C[XX]FLAGS are selected so: # If the user specifies something in the environment, that is used. # else: If the template file set something, that is used. @@ -10560,7 +10569,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 078381e568..79ae882133 100644 --- a/configure.ac +++ b/configure.ac @@ -397,11 +397,16 @@ AS_IF([test "$with_llvm" = yes], [ unset CFLAGS unset CXXFLAGS +DLSUFFIX=".so" + # # Read the template # . "$srcdir/src/template/$template" || exit +AC_SUBST(DLSUFFIX) +AC_DEFINE_UNQUOTED([DLSUFFIX], ["$DLSUFFIX"], [Define to the file name extension of dynamically-loadable modules.])dnl + # C[XX]FLAGS are selected so: # If the user specifies something in the environment, that is used. # else: If the template file set something, that is used. diff --git a/src/Makefile.global.in b/src/Makefile.global.in index bbdc1c4bda..0726b2020f 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 a895ebac5f..a9a603e639 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 f552b95ca9..ceffb807fb 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 050da78080..3774f33e0e 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 49b94f0ac7..7a3225b27c 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 635fbb2181..9e2ca83993 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 d3cb765976..4bb6fc5e1e 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 be53b7b94d..10f53c708c 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 ba3695dd57..84f26b49b8 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 81089d6257..6afa9a06a1 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 b17598f058..4fc81c1584 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 75db21ba14..0e77616b0f 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 7e18770d89..25e036bd8d 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 645f73aa2b..1ffec9d169 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 6f9cb1d45d..421b735e40 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 6f9cb1d45d..421b735e40 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 62a6c01c3a..5496edcafc 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 e72cb2db0e..17d6819644 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 1e7274bc33..3f42e2f8b6 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 50fff80c53..5105a74c78 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 1380d16548..1895f067a8 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 b40361c84c..88b82d9268 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 a21ea9bef9..ef5476d034 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, -- 2.35.1