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.
This commit is contained in:
Neil Conway 2004-10-20 02:12:07 +00:00
parent a1bc728cf9
commit 857e210ea9
4 changed files with 175 additions and 60 deletions

View File

@ -1,5 +1,5 @@
# 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
@ -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:
#

170
configure vendored
View File

@ -2432,23 +2432,16 @@ 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"
else
# Maybe fill in later...
pgac_try=
fi
CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
for pgac_flag in $pgac_try; do
CFLAGS="$pgac_save_CFLAGS $pgac_flag"
cat >conftest.$ac_ext <<_ACEOF
# 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"
@ -2478,23 +2471,154 @@ 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 -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"
#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
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
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

View File

@ -1,5 +1,5 @@
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 Developers, please strive to achieve this order:
dnl
@ -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

View File

@ -1,5 +1,5 @@
# -*-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,
@ -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