Commit 857e210e authored by Neil Conway's avatar Neil Conway

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.
parent a1bc728c
# Macros to detect C compiler features # Macros to detect C compiler features
# $PostgreSQL: pgsql/config/c-compiler.m4,v 1.12 2004/02/02 04:07:18 tgl Exp $ # $PostgreSQL: pgsql/config/c-compiler.m4,v 1.13 2004/10/20 02:12:07 neilc Exp $
# PGAC_C_SIGNED # PGAC_C_SIGNED
...@@ -121,35 +121,19 @@ AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1, ...@@ -121,35 +121,19 @@ AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1,
fi fi
fi])# PGAC_C_FUNCNAME_SUPPORT fi])# PGAC_C_FUNCNAME_SUPPORT
# PGAC_PROG_CC_CFLAGS_OPT
# PGAC_PROG_CC_NO_STRICT_ALIASING # -----------------------
# ------------------------------- # Given a string, check if the compiler supports the string as a
# Find out how to turn off strict aliasing in the C compiler. # command-line option. If it does, add the string to CFLAGS.
AC_DEFUN([PGAC_PROG_CC_NO_STRICT_ALIASING], AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
[AC_CACHE_CHECK([how to turn off strict aliasing in $CC], [AC_MSG_CHECKING([if $CC supports $1])
pgac_cv_prog_cc_no_strict_aliasing, pgac_save_CFLAGS=$CFLAGS
[pgac_save_CFLAGS=$CFLAGS CFLAGS="$pgac_save_CFLAGS $1"
if test "$GCC" = yes; then _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
pgac_try="-fno-strict-aliasing" AC_MSG_RESULT(yes),
else [CFLAGS="$pgac_save_CFLAGS"
# Maybe fill in later... AC_MSG_RESULT(no)])
pgac_try= ])# PGAC_PROG_CC_CFLAGS_OPT
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
# The below backpatches the following Autoconf change: # The below backpatches the following Autoconf change:
# #
......
...@@ -2432,23 +2432,61 @@ else ...@@ -2432,23 +2432,61 @@ else
fi fi
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 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 else
# Maybe fill in later... echo "$as_me: failed program was:" >&5
pgac_try= cat conftest.$ac_ext >&5
CFLAGS="$pgac_save_CFLAGS"
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi fi
rm -f conftest.$ac_objext conftest.$ac_ext
for pgac_flag in $pgac_try; do echo "$as_me:$LINENO: checking if $CC supports -Wold-style-definition" >&5
CFLAGS="$pgac_save_CFLAGS $pgac_flag" echo $ECHO_N "checking if $CC supports -Wold-style-definition... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF pgac_save_CFLAGS=$CFLAGS
CFLAGS="$pgac_save_CFLAGS -Wold-style-definition"
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure" #line $LINENO "configure"
#include "confdefs.h" #include "confdefs.h"
...@@ -2478,23 +2516,109 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ...@@ -2478,23 +2516,109 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
ac_status=$? ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then (exit $ac_status); }; }; then
pgac_cv_prog_cc_no_strict_aliasing=$pgac_try echo "$as_me:$LINENO: result: yes" >&5
break echo "${ECHO_T}yes" >&6
else else
echo "$as_me: failed program was:" >&5 echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5 cat conftest.$ac_ext >&5
CFLAGS="$pgac_save_CFLAGS"
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi fi
rm -f conftest.$ac_objext conftest.$ac_ext 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 fi
echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_no_strict_aliasing" >&5 rm -f conftest.$ac_objext conftest.$ac_ext
echo "${ECHO_T}$pgac_cv_prog_cc_no_strict_aliasing" >&6
if test x"$pgac_cv_prog_cc_no_strict_aliasing" != x""; then
CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
fi fi
# supply -g if --enable-debug # supply -g if --enable-debug
......
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
dnl $PostgreSQL: pgsql/configure.in,v 1.381 2004/10/15 05:10:59 momjian Exp $ dnl $PostgreSQL: pgsql/configure.in,v 1.382 2004/10/20 02:12:06 neilc Exp $
dnl dnl
dnl Developers, please strive to achieve this order: dnl Developers, please strive to achieve this order:
dnl dnl
...@@ -250,8 +250,18 @@ else ...@@ -250,8 +250,18 @@ else
fi fi
fi fi
# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later. if test "$GCC" = yes; then
PGAC_PROG_CC_NO_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.
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 # supply -g if --enable-debug
if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
......
# -*-makefile-*- # -*-makefile-*-
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.203 2004/10/15 17:10:58 momjian Exp $ # $PostgreSQL: pgsql/src/Makefile.global.in,v 1.204 2004/10/20 02:12:07 neilc Exp $
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# All PostgreSQL makefiles include this file and use the variables it sets, # All PostgreSQL makefiles include this file and use the variables it sets,
...@@ -184,9 +184,6 @@ endif # not PGXS ...@@ -184,9 +184,6 @@ endif # not PGXS
CC = @CC@ CC = @CC@
GCC = @GCC@ GCC = @GCC@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@
ifeq ($(GCC), yes)
CFLAGS += -Wall -Wmissing-prototypes -Wmissing-declarations
endif
# Kind-of compilers # Kind-of compilers
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment