]> granicus.if.org Git - libatomic_ops/commitdiff
Fix configure to define __PIC__ macro explicitly only if not done by GCC
authorIvan Maidanski <ivmai@mail.ru>
Wed, 28 Mar 2012 03:59:09 +0000 (07:59 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 28 Mar 2012 12:54:27 +0000 (16:54 +0400)
* configure.ac (PICFLAG): Adjust AC_MSG_CHECKING message; report
"none" result if no -fPIC is needed (for Cygwin/MinGW); determine
whether GCC -fPIC option causes __PIC__ macro definition; pass
-D __PIC__ to PICFLAG (instead of CFLAGS) only if not defined
automatically in case -fPIC specified; update comment.

configure.ac

index c76a348d4273d2f62f7d5529397cec47297db420..69aad25724aacddac8aef8735015c65d2411aad2 100644 (file)
@@ -18,24 +18,32 @@ LT_INIT([disable-shared])
 # Checks for functions.
 AC_FUNC_MMAP
 
-# Determine PIC flag, adjust default CFLAGS
+# Determine PIC flag.
 need_asm=false
 PICFLAG=
-AC_MSG_CHECKING(Determining PIC compiler flag)
+AC_MSG_CHECKING(for PIC compiler flag)
 if test "$GCC" = yes; then
   case "$host" in
-    *-*-solaris*)
-      AC_MSG_RESULT(-fPIC)
-      PICFLAG=-fPIC
-      # Workaround: at least GCC 3.4.6 does not define this macro.
-      CFLAGS="-D__PIC__=1 $CFLAGS"
-      ;;
     *-*-cygwin* | *-*-mingw*)
       # Cygwin and Mingw[-w32/64] do not need -fPIC.
+      AC_MSG_RESULT("<none>")
       ;;
     *)
       AC_MSG_RESULT(-fPIC)
       PICFLAG=-fPIC
+      AC_MSG_CHECKING(whether gcc -fPIC causes __PIC__ definition)
+      # Workaround: at least GCC 3.4.6 (Solaris) does not define this macro.
+      old_CFLAGS="$CFLAGS"
+      CFLAGS="$PICFLAG $CFLAGS"
+      AC_TRY_COMPILE([],[
+ #ifndef __PIC__
+ # error
+ #endif
+      ], [ac_cv_pic_macro=yes], [ac_cv_pic_macro=no])
+      CFLAGS="$old_CFLAGS"
+      AC_MSG_RESULT($ac_cv_pic_macro)
+      AS_IF([test "$ac_cv_pic_macro" = yes], [],
+            [PICFLAG="-D__PIC__=1 $PICFLAG"])
       ;;
   esac