summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2008-05-18 20:13:12 +0000
committerTom Lane2008-05-18 20:13:12 +0000
commite85c667dd4ec3940a71f5d81c00f474f29812a61 (patch)
treefbc1eefd3bcc294370ea486b6c0821a7c2910f1e
parent7f55030d45d7e4b762a1a2deb9512c58f721e75f (diff)
Make another try at using -Wl,--as-needed to suppress linking of unnecessary
shared libraries. We've tried this before and had problems with libreadline not linking properly on some platforms, but that seems to be a libreadline bug that may have been fixed by now. In any case, it's early enough in the 8.4 devel cycle that we can afford to have some transient breakage while we work out any portability problems. On Darwin, we try -Wl,-dead_strip_dylibs, which seems to be the equivalent incantation there.
-rw-r--r--config/c-compiler.m416
-rwxr-xr-xconfigure110
-rw-r--r--configure.in10
3 files changed, 136 insertions, 0 deletions
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 56e21408ed..b43bcfbca4 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -110,3 +110,19 @@ _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
[CFLAGS="$pgac_save_CFLAGS"
AC_MSG_RESULT(no)])
])# PGAC_PROG_CC_CFLAGS_OPT
+
+
+
+# PGAC_PROG_CC_LDFLAGS_OPT
+# ------------------------
+# Given a string, check if the compiler supports the string as a
+# command-line option. If it does, add the string to LDFLAGS.
+AC_DEFUN([PGAC_PROG_CC_LDFLAGS_OPT],
+[AC_MSG_CHECKING([if $CC supports $1])
+pgac_save_LDFLAGS=$LDFLAGS
+LDFLAGS="$pgac_save_LDFLAGS $1"
+AC_LINK_IFELSE([AC_LANG_PROGRAM()],
+ AC_MSG_RESULT(yes),
+ [LDFLAGS="$pgac_save_LDFLAGS"
+ AC_MSG_RESULT(no)])
+])# PGAC_PROG_CC_LDFLAGS_OPT
diff --git a/configure b/configure
index f71fcd642d..20d1f5b4a9 100755
--- a/configure
+++ b/configure
@@ -4318,6 +4318,116 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
+# If compiler will take -Wl,--as-needed then add that to LDFLAGS.
+# This is much easier than trying to filter LIBS to the minimum for each
+# executable. (Note that shared libraries won't use this switch, though.)
+# On Darwin it's spelled -Wl,-dead_strip_dylibs, but don't try that elsewhere
+if test "$PORTNAME" != "darwin"; then
+ { echo "$as_me:$LINENO: checking if $CC supports -Wl,--as-needed" >&5
+echo $ECHO_N "checking if $CC supports -Wl,--as-needed... $ECHO_C" >&6; }
+pgac_save_LDFLAGS=$LDFLAGS
+LDFLAGS="$pgac_save_LDFLAGS -Wl,--as-needed"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_link") 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest$ac_exeext &&
+ $as_test_x conftest$ac_exeext; then
+ { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ LDFLAGS="$pgac_save_LDFLAGS"
+ { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+ conftest$ac_exeext conftest.$ac_ext
+
+else
+ { echo "$as_me:$LINENO: checking if $CC supports -Wl,-dead_strip_dylibs" >&5
+echo $ECHO_N "checking if $CC supports -Wl,-dead_strip_dylibs... $ECHO_C" >&6; }
+pgac_save_LDFLAGS=$LDFLAGS
+LDFLAGS="$pgac_save_LDFLAGS -Wl,-dead_strip_dylibs"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_link") 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest$ac_exeext &&
+ $as_test_x conftest$ac_exeext; then
+ { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ LDFLAGS="$pgac_save_LDFLAGS"
+ { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+ conftest$ac_exeext conftest.$ac_ext
+
+fi
+
# Create compiler version string
if test x"$GCC" = x"yes" ; then
cc_string="GCC `${CC} --version | sed q`"
diff --git a/configure.in b/configure.in
index 73eccaf36f..e199cc6ed3 100644
--- a/configure.in
+++ b/configure.in
@@ -450,6 +450,16 @@ fi
AC_PROG_CPP
AC_SUBST(GCC)
+# If compiler will take -Wl,--as-needed then add that to LDFLAGS.
+# This is much easier than trying to filter LIBS to the minimum for each
+# executable. (Note that shared libraries won't use this switch, though.)
+# On Darwin it's spelled -Wl,-dead_strip_dylibs, but don't try that elsewhere
+if test "$PORTNAME" != "darwin"; then
+ PGAC_PROG_CC_LDFLAGS_OPT([-Wl,--as-needed])
+else
+ PGAC_PROG_CC_LDFLAGS_OPT([-Wl,-dead_strip_dylibs])
+fi
+
# Create compiler version string
if test x"$GCC" = x"yes" ; then
cc_string="GCC `${CC} --version | sed q`"