summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Conway2004-10-20 02:12:07 +0000
committerNeil Conway2004-10-20 02:12:07 +0000
commit5b46bebd605486dc4f9c9d5b06f8281944054862 (patch)
tree0999b2f12826926fe888fee1e2e18f9308dec919
parent3ad962235dfb78e189854f11bd3843b532f0c692 (diff)
When using GCC, change the default CFLAGS to:
-O2 -Wall -Wmissing-prototypes -Wpointer-arith Check whether the version of GCC we are using supports any of: -Wdeclaration-after-statement -Wendif-labels -Wold-style-definition And add the supported flags to CFLAGS.
-rw-r--r--config/c-compiler.m442
-rwxr-xr-xconfigure166
-rw-r--r--configure.in14
-rw-r--r--src/Makefile.global.in3
4 files changed, 170 insertions, 55 deletions
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index dbacc927ca..67d783594d 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -121,35 +121,19 @@ AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1,
fi
fi])# PGAC_C_FUNCNAME_SUPPORT
-
-# PGAC_PROG_CC_NO_STRICT_ALIASING
-# -------------------------------
-# Find out how to turn off strict aliasing in the C compiler.
-AC_DEFUN([PGAC_PROG_CC_NO_STRICT_ALIASING],
-[AC_CACHE_CHECK([how to turn off strict aliasing in $CC],
- pgac_cv_prog_cc_no_strict_aliasing,
-[pgac_save_CFLAGS=$CFLAGS
-if test "$GCC" = yes; then
- pgac_try="-fno-strict-aliasing"
-else
- # Maybe fill in later...
- pgac_try=
-fi
-
-for pgac_flag in $pgac_try; do
- CFLAGS="$pgac_save_CFLAGS $pgac_flag"
- _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
- [pgac_cv_prog_cc_no_strict_aliasing=$pgac_try
-break])
-done
-
-CFLAGS=$pgac_save_CFLAGS
-])
-
-if test x"$pgac_cv_prog_cc_no_strict_aliasing" != x""; then
- CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
-fi])# PGAC_PROG_CC_NO_STRICT_ALIASING
-
+# PGAC_PROG_CC_CFLAGS_OPT
+# -----------------------
+# Given a string, check if the compiler supports the string as a
+# command-line option. If it does, add the string to CFLAGS.
+AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
+[AC_MSG_CHECKING([if $CC supports $1])
+pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS $1"
+_AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+ AC_MSG_RESULT(yes),
+ [CFLAGS="$pgac_save_CFLAGS"
+ AC_MSG_RESULT(no)])
+])# PGAC_PROG_CC_CFLAGS_OPT
# The below backpatches the following Autoconf change:
#
diff --git a/configure b/configure
index 7ae60e8d39..5eaa809ae8 100755
--- a/configure
+++ b/configure
@@ -2432,23 +2432,61 @@ else
fi
fi
-# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
-echo "$as_me:$LINENO: checking how to turn off strict aliasing in $CC" >&5
-echo $ECHO_N "checking how to turn off strict aliasing in $CC... $ECHO_C" >&6
-if test "${pgac_cv_prog_cc_no_strict_aliasing+set}" = set; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- pgac_save_CFLAGS=$CFLAGS
if test "$GCC" = yes; then
- pgac_try="-fno-strict-aliasing"
+ CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
+
+ # Some versions of GCC support some additional useful warning flags.
+ # Check whether they are supported, and add them to CFLAGS if so.
+ echo "$as_me:$LINENO: checking if $CC supports -Wdeclaration-after-statement" >&5
+echo $ECHO_N "checking if $CC supports -Wdeclaration-after-statement... $ECHO_C" >&6
+pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS -Wdeclaration-after-statement"
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
else
- # Maybe fill in later...
- pgac_try=
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+CFLAGS="$pgac_save_CFLAGS"
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
fi
+rm -f conftest.$ac_objext conftest.$ac_ext
-for pgac_flag in $pgac_try; do
- CFLAGS="$pgac_save_CFLAGS $pgac_flag"
- cat >conftest.$ac_ext <<_ACEOF
+ echo "$as_me:$LINENO: checking if $CC supports -Wold-style-definition" >&5
+echo $ECHO_N "checking if $CC supports -Wold-style-definition... $ECHO_C" >&6
+pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS -Wold-style-definition"
+cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
@@ -2478,23 +2516,109 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
- pgac_cv_prog_cc_no_strict_aliasing=$pgac_try
-break
+ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
+CFLAGS="$pgac_save_CFLAGS"
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
fi
rm -f conftest.$ac_objext conftest.$ac_ext
-done
-CFLAGS=$pgac_save_CFLAGS
+ echo "$as_me:$LINENO: checking if $CC supports -Wendif-labels" >&5
+echo $ECHO_N "checking if $CC supports -Wendif-labels... $ECHO_C" >&6
+pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS -Wendif-labels"
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+CFLAGS="$pgac_save_CFLAGS"
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+
+
+ # Disable strict-aliasing rules; needed for gcc 3.3+
+ echo "$as_me:$LINENO: checking if $CC supports -fno-strict-aliasing" >&5
+echo $ECHO_N "checking if $CC supports -fno-strict-aliasing... $ECHO_C" >&6
+pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS -fno-strict-aliasing"
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+CFLAGS="$pgac_save_CFLAGS"
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
fi
-echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_no_strict_aliasing" >&5
-echo "${ECHO_T}$pgac_cv_prog_cc_no_strict_aliasing" >&6
+rm -f conftest.$ac_objext conftest.$ac_ext
-if test x"$pgac_cv_prog_cc_no_strict_aliasing" != x""; then
- CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
fi
# supply -g if --enable-debug
diff --git a/configure.in b/configure.in
index 4030794ef4..39ec6d026b 100644
--- a/configure.in
+++ b/configure.in
@@ -250,8 +250,18 @@ else
fi
fi
-# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
-PGAC_PROG_CC_NO_STRICT_ALIASING
+if test "$GCC" = yes; then
+ CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
+
+ # Some versions of GCC support some additional useful warning flags.
+ # Check whether they are supported, and add them to CFLAGS if so.
+ PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
+ PGAC_PROG_CC_CFLAGS_OPT([-Wold-style-definition])
+ PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
+
+ # Disable strict-aliasing rules; needed for gcc 3.3+
+ PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
+fi
# supply -g if --enable-debug
if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 86f44cb2dc..79241363cc 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -184,9 +184,6 @@ endif # not PGXS
CC = @CC@
GCC = @GCC@
CFLAGS = @CFLAGS@
-ifeq ($(GCC), yes)
- CFLAGS += -Wall -Wmissing-prototypes -Wmissing-declarations
-endif
# Kind-of compilers