4 dnl Turn on many useful compiler warnings
5 dnl For now, only sets extra flags on GCC
7 AC_DEFUN([SG_COMPILE_FLAGS],[
8 AC_ARG_ENABLE(compile-warnings,
9 AS_HELP_STRING([--enable-compile-warnings], [use compiler warnings (default=no, unless in maintainer mode)]),
10 enable_compile_warnings=$withval,enable_compile_warnings=no)
12 AC_ARG_ENABLE(compile-optimizations,
13 AS_HELP_STRING([--disable-compile-optimizations], [use compiler optimizations (default=yes, unless if CFLAGS is explicitly set)]),
14 enable_compile_optimizations=$enableval,enable_compile_optimizations=auto)
16 if test "x$cflags_set" != "xyes" ; then
17 # if user didn't specify CFLAGS explicitely
19 # AC PROG CC tests whether -g is accepted.
20 # Cool, but it also tries to set -O2. I don't want it with gcc
23 case " $saveCFLAGS " in
26 case " $saveCFLAGS " in
27 *-O2*) test "x$CC" = xgcc || CFLAGS="$CFLAGS -O2" ;;
30 # damn AC PROG CC, why did you set -O??
34 if test "x$enable_compile_warnings" = "xyes" ; then
35 AC_MSG_CHECKING(the warning flags for this compiler)
37 if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
40 *) warnCFLAGS="-Wall -Wunused" ;;
43 ## -W is not all that useful. And it cannot be controlled
44 ## with individual -Wno-xxx flags, unlike -Wall
45 if test "x$enable_compile_warnings" = "xyes"; then
46 warnCFLAGS=`echo $warnCFLAGS -Wmissing-prototypes -Wmissing-declarations \
47 -Wshadow -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings \
48 -Wno-unused-variable -Wno-unused-function -Wno-unused-label \
53 AC_MSG_RESULT($warnCFLAGS)
54 # placed before since gcc remembers the last one on conflict
55 CFLAGS="$warnCFLAGS $CFLAGS"
58 if test "x$enable_compile_optimizations" = "xyes" ||
59 test "x$enable_compile_optimizations" = "xauto" ; then
60 AC_MSG_CHECKING(the optimization flags for this compiler)
62 if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
65 *) optCFLAGS="$optCFLAGS -O3" ;;
67 optCFLAGS="$optCFLAGS -finline-functions -ffast-math -funroll-loops -fno-strict-aliasing"
69 if test "x$target_cpu" = "xpowerpc" ; then
70 # avoid gcc bug #12828, which is fixed in 3.4.0, but this version
71 # isn't propagated enough to desserve an extra check
72 optCFLAGS="$optCFLAGS -fno-loop-optimize"
75 AC_MSG_RESULT($optCFLAGS)
76 # Take it only if CFLAGS not explicitly set. Unless the flag was explicitly given
77 if test "x$cflags_set" != "xyes" ; then
78 CFLAGS="$optCFLAGS $CFLAGS"