From 62ca50ad7ad05fbbc053a4e3687a6e4edb711049 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 21 Oct 2019 12:32:36 -0400 Subject: [PATCH] Select CFLAGS_SL at configure time, not in platform-specific Makefiles. Move the platform-dependent logic that sets CFLAGS_SL from src/makefiles/Makefile.foo to src/template/foo, so that the value is determined at configure time and thus is available while running configure's tests. On a couple of platforms this might save a few microseconds of build time by eliminating a test that make otherwise has to do over and over. Otherwise it's pretty much a wash for build purposes; in particular, this makes no difference to anyone who might be overriding CFLAGS_SL via a make option. This patch in itself does nothing with the value and thus should not change any behavior, though you'll probably have to re-run configure to get a correctly updated Makefile.global. We'll use the new configure variable in a follow-on patch. Per gripe from Kyotaro Horiguchi. Back-patch to all supported branches, because the follow-on patch is a portability bug fix. Discussion: https://postgr.es/m/20191010.144533.263180400.horikyota.ntt@gmail.com --- configure | 5 ++++- configure.in | 5 ++++- src/Makefile.global.in | 1 + src/makefiles/Makefile.cygwin | 1 - src/makefiles/Makefile.freebsd | 2 -- src/makefiles/Makefile.hpux | 5 ----- src/makefiles/Makefile.linux | 2 -- src/makefiles/Makefile.netbsd | 2 -- src/makefiles/Makefile.openbsd | 2 -- src/makefiles/Makefile.sco | 6 +----- src/makefiles/Makefile.solaris | 6 +----- src/makefiles/Makefile.unixware | 6 +----- src/makefiles/Makefile.win32 | 1 - src/template/aix | 5 +++++ src/template/cygwin | 3 +++ src/template/darwin | 3 +++ src/template/freebsd | 3 +++ src/template/hpux | 7 +++++++ src/template/linux | 3 +++ src/template/netbsd | 3 +++ src/template/openbsd | 4 ++++ src/template/sco | 9 +++++++++ src/template/solaris | 9 +++++++++ src/template/unixware | 9 +++++++++ src/template/win32 | 3 +++ 25 files changed, 73 insertions(+), 32 deletions(-) diff --git a/configure b/configure index 48edbf168e..dd82036551 100755 --- a/configure +++ b/configure @@ -725,6 +725,7 @@ autodepend TAS GCC CPP +CFLAGS_SL CFLAGS_VECTOR SUN_STUDIO_CC OBJEXT @@ -5054,7 +5055,6 @@ fi fi -CFLAGS_VECTOR=$CFLAGS_VECTOR # supply -g if --enable-debug @@ -5093,6 +5093,9 @@ fi # the automatic additions. CFLAGS="$CFLAGS $user_CFLAGS" +# 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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler still works" >&5 $as_echo_n "checking whether the C compiler still works... " >&6; } diff --git a/configure.in b/configure.in index bf293910fc..bb1a9b29c0 100644 --- a/configure.in +++ b/configure.in @@ -491,7 +491,7 @@ elif test "$PORTNAME" = "hpux"; then PGAC_PROG_CC_CFLAGS_OPT([+Olibmerrno]) fi -AC_SUBST(CFLAGS_VECTOR, $CFLAGS_VECTOR) +AC_SUBST(CFLAGS_VECTOR) # supply -g if --enable-debug if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then @@ -528,6 +528,9 @@ fi # the automatic additions. CFLAGS="$CFLAGS $user_CFLAGS" +# 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 AC_MSG_CHECKING([whether the C compiler still works]) AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])], diff --git a/src/Makefile.global.in b/src/Makefile.global.in index e85440e51a..fe9f0440c7 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -241,6 +241,7 @@ CC = @CC@ GCC = @GCC@ SUN_STUDIO_CC = @SUN_STUDIO_CC@ CFLAGS = @CFLAGS@ +CFLAGS_SL = @CFLAGS_SL@ CFLAGS_VECTOR = @CFLAGS_VECTOR@ CFLAGS_SSE42 = @CFLAGS_SSE42@ diff --git a/src/makefiles/Makefile.cygwin b/src/makefiles/Makefile.cygwin index 2d57b4b089..df22d9fd99 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 5008c96b3f..8e5bc9c6ec 100644 --- a/src/makefiles/Makefile.freebsd +++ b/src/makefiles/Makefile.freebsd @@ -7,8 +7,6 @@ endif 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 84a1cc3542..cc9ca10a87 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 f4f091caef..c6d0546e4d 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 43841c1597..c2a3cce4f0 100644 --- a/src/makefiles/Makefile.netbsd +++ b/src/makefiles/Makefile.netbsd @@ -9,8 +9,6 @@ endif 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 d8fde49d5c..0c5a7b4eb3 100644 --- a/src/makefiles/Makefile.openbsd +++ b/src/makefiles/Makefile.openbsd @@ -7,8 +7,6 @@ endif 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.sco b/src/makefiles/Makefile.sco index 993861570a..49c6693f14 100644 --- a/src/makefiles/Makefile.sco +++ b/src/makefiles/Makefile.sco @@ -2,11 +2,7 @@ AROPT = cr export_dynamic = -Wl,-Bexport DLSUFFIX = .so -ifeq ($(GCC), yes) -CFLAGS_SL = -fpic -else -CFLAGS_SL = -K PIC -endif + # 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 e459de30cf..a05c0e0d3d 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.unixware b/src/makefiles/Makefile.unixware index a52717b268..3d177b76e9 100644 --- a/src/makefiles/Makefile.unixware +++ b/src/makefiles/Makefile.unixware @@ -17,11 +17,7 @@ endif CFLAGS += $(PTHREAD_CFLAGS) DLSUFFIX = .so -ifeq ($(GCC), yes) -CFLAGS_SL = -fpic -else -CFLAGS_SL = -K PIC -endif + ifeq ($(GCC), yes) SO_FLAGS = -shared else diff --git a/src/makefiles/Makefile.win32 b/src/makefiles/Makefile.win32 index 0c534f365a..8cc0a80db6 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 230d4613f3..f7954123e1 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 @@ -13,6 +15,9 @@ if test "$GCC" != yes ; then esac 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 b6ea0ded52..79a108145f 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 c05adca0bf..f4d4e9d7cf 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 772e2f1a5f..fea03fc14b 100644 --- a/src/template/freebsd +++ b/src/template/freebsd @@ -1 +1,4 @@ # src/template/freebsd + +# 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 79d3475664..50fff80c53 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 3eb5ad2428..09ab6af86c 100644 --- a/src/template/linux +++ b/src/template/linux @@ -3,6 +3,9 @@ # Force _GNU_SOURCE on; plperl is broken with Perl 5.8.0 otherwise 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 198697723d..d97f995c74 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 e69de29bb2..365268c489 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/sco b/src/template/sco index 9a736da8be..e216f1e7aa 100644 --- a/src/template/sco +++ b/src/template/sco @@ -1 +1,10 @@ +# src/template/sco + CC="$CC -b elf" + +# Extra CFLAGS for code that will go into a shared library +if test "$GCC" = yes ; then + CFLAGS_SL="-fpic" +else + CFLAGS_SL="-K PIC" +fi diff --git a/src/template/solaris b/src/template/solaris index e07b9a0a8d..f88b1cdad3 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/unixware b/src/template/unixware index d08fca1e6b..006c4abe49 100644 --- a/src/template/unixware +++ b/src/template/unixware @@ -1,3 +1,5 @@ +# src/template/unixware + if test "$GCC" != yes; then # The -Kno_host is for a bug in the compiler. See -hackers # discussion on 7-8/Aug/2003. @@ -37,5 +39,12 @@ __EOF__ fi +# Extra CFLAGS for code that will go into a shared library +if test "$GCC" = yes ; then + CFLAGS_SL="-fpic" +else + CFLAGS_SL="-K PIC" +fi + # Unixware's ldap library reportedly needs these too EXTRA_LDAP_LIBS="-llber -lresolv" diff --git a/src/template/win32 b/src/template/win32 index 7da9719acb..1380d16548 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 -- 2.50.1