]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
check if the linker supports a flag instead of just checking for GNU ld
authorJohn (J5) Palmieri <johnp@redhat.com>
Tue, 4 Mar 2008 18:09:07 +0000 (13:09 -0500)
committerJohn (J5) Palmieri <johnp@redhat.com>
Tue, 4 Mar 2008 18:09:07 +0000 (13:09 -0500)
* configure.in: move AM_PROG_LIBTOOL to the top
  (ld_supports_flag): new function for checking if the linker supports
  a given flag

ChangeLog
configure.in

index 7a083f54caa7983b91f76b1b4134b3b7bf50fee6..28497bc8e7307cbd389d97a22261ab764319704c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-04  John (J5) Palmieri  <johnp@redhat.com>
+
+       * check if the linker supports a flag instead of just checking for GNU
+         ld
+       * configure.in: move AM_PROG_LIBTOOL to the top
+         (ld_supports_flag): new function for checking if the linker supports
+         a given flag
+
 2008-03-04  John (J5) Palmieri  <johnp@redhat.com>
 
        * add a changelog for Benjamin Reed's git patch RANT: Change Logs are
index bb28708c65f0555c6c0306f6622b9a410c912a15..1caf7d923a370b8fa7af400db70e01dd963cf402 100644 (file)
@@ -60,6 +60,7 @@ AC_PROG_CXX
 AC_ISC_POSIX
 AC_HEADER_STDC
 AC_C_INLINE
+AM_PROG_LIBTOOL
 
 AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests],[enable unit test code]),enable_tests=$enableval,enable_tests=$USE_MAINTAINER_MODE)
 AC_ARG_ENABLE(ansi, AS_HELP_STRING([--enable-ansi],[enable -ansi -pedantic gcc flags]),enable_ansi=$enableval,enable_ansi=no)
@@ -144,6 +145,36 @@ cc_supports_flag() {
   return $rc
 }
 
+ld_supports_flag() {
+  AC_MSG_CHECKING([whether $LD supports "$@"])
+  AC_TRY_LINK([
+    int one(void) { return 1; }
+    int two(void) { return 2; }
+  ], [ two(); ] , [_ac_ld_flag_supported=yes], [_ac_ld_flag_supported=no])
+
+  if test "$_ac_ld_flag_supported" = "yes"; then
+    rm -f conftest.c
+    touch conftest.c
+    if $CC -c conftest.c; then
+      ld_out=`$LD $@ -o conftest conftest.o 2>&1`
+      ld_ret=$?
+      if test $ld_ret -ne 0 ; then
+        _ac_ld_flag_supported=no
+      elif echo "$ld_out" | egrep 'option ignored|^usage:|unrecognized option|illegal option' >/dev/null ; then
+        _ac_ld_flag_supported=no
+      fi
+    fi
+    rm -f conftest.c conftest.o conftest
+  fi
+
+  AC_MSG_RESULT($_ac_ld_flag_supported)
+  if test "$_ac_ld_flag_supported" = "yes" ; then
+    return 0
+  else
+    return 1
+  fi
+}
+
 if test "x$GCC" = "xyes"; then
   changequote(,)dnl
   case " $CFLAGS " in
@@ -214,7 +245,7 @@ if test "x$GCC" = "xyes"; then
   *[\ \        ]-fPIC[\ \      ]*) ;;
   *) if cc_supports_flag -fPIC; then
         PIC_CFLAGS="-fPIC"
-        if [ "x$with_gnu_ld" = "xyes" ]; then
+        if ld_supports_flag -z,relro; then
            PIC_LDFLAGS="-Wl,-z,relro"
         fi
      fi
@@ -225,7 +256,7 @@ if test "x$GCC" = "xyes"; then
   *[\ \        ]-fPIE[\ \      ]*) ;;
   *) if cc_supports_flag -fPIE; then
         PIE_CFLAGS="-fPIE"
-        if [ "x$with_gnu_ld" = "xyes" ]; then
+        if ld_supports_flag -z,relro; then
            PIE_LDFLAGS="-pie -Wl,-z,relro"
         else
            PIE_LDFLAGS="-pie"
@@ -280,28 +311,7 @@ AC_SUBST(PIC_LDFLAGS)
 AC_SUBST(PIE_CFLAGS)
 AC_SUBST(PIE_LDFLAGS)  
 
-# Check for -Wl,--gc-sections
-AC_MSG_CHECKING([for ld that supports "-Wl,--gc-sections"])
-AC_TRY_LINK([
-  int one(void) { return 1; }
-  int two(void) { return 2; }
-  ], [ two(); ] , [ac_gcsections=yes], [ac_gcsections=no])
-
-if test "$ac_gcsections" = "yes"; then
-  rm -f conftest.c
-  touch conftest.c
-  if $CC -c conftest.c; then
-    ld_out=`$LD --gc-sections -o conftest conftest.o 2>&1`
-    ld_ret=$?
-    if test $ld_ret -ne 0 ; then
-      ac_gcsections=no
-    elif echo "$ld_out" | egrep 'option ignored|^usage:|illegal option' >/dev/null ; then
-      ac_gcsections=no
-    fi
-  fi
-  rm -f conftest.c conftest.o conftest
-fi
-if test "$ac_gcsections" = "yes"; then
+if ld_supports_flag --gc-sections; then
   SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
   CFLAGS="-ffunction-sections -fdata-sections $CFLAGS"
 fi
@@ -316,8 +326,6 @@ case $target_os in
        CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS" ;;
 esac
     
-AM_PROG_LIBTOOL
-
 changequote(,)dnl
 # compress spaces in flags
 CFLAGS=`echo "$CFLAGS" | sed -e 's/ +/ /g'`