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=$enableval,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 # AC PROG CC tests whether -g is accepted.
17 # Cool, but it also tries to set -O2 and -g.
18 # I don't want it with gcc, but -O3 and -g2, and optimization only when asked by user
21 if test "$CFLAGS" = "-g -O2" ; then
24 if test "$CXXFLAGS" = "-g -O2" ; then
27 if test "$GCJFLAGS" = "-g -O2" ; then
32 if test "x$enable_compile_warnings" = "xyes" ; then
33 AC_MSG_CHECKING(the warning flags for this compiler)
35 if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
38 *) warnCFLAGS="-Wall -Wunused" ;;
41 ## -W is not all that useful. And it cannot be controlled
42 ## with individual -Wno-xxx flags, unlike -Wall
44 ## -Wformat=2 chokes on the snprintf replacement because the format is passed to real sprintf
45 ## -Wshadow chokes on try{ try{} } constructs
46 if test "x$enable_compile_warnings" = "xyes"; then
47 warnCFLAGS=`echo $warnCFLAGS -Wmissing-prototypes -Wmissing-declarations \
48 -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings \
49 -Wno-unused-function -Wno-strict-aliasing \
52 # -Wno-unused-variable -Wno-unused-label
55 AC_MSG_RESULT($warnCFLAGS)
56 # placed before since gcc remembers the last one on conflict
57 CFLAGS="$warnCFLAGS $CFLAGS"
60 if test "x$enable_compile_optimizations" = "xyes" ||
61 test "x$enable_compile_optimizations" = "xauto" ; then
62 AC_MSG_CHECKING(the optimization flags for this compiler)
64 if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
67 *) optCFLAGS="$optCFLAGS -O3" ;;
69 optCFLAGS="$optCFLAGS -finline-functions -ffast-math -funroll-loops -fno-strict-aliasing"
71 GCC_VER=`gcc --version | head -n 1 | sed 's/^[^0-9]*\([^ ]*\).*$/\1/'`
72 GCC_VER_MAJ=`echo $GCC_VER | sed 's/^\(.\).*$/\1/'`
73 if test "x$target_cpu" = "xpowerpc" && test "x$GCC_VER_MAJ" == "x3" ; then
74 # avoid gcc bug #12828, which apeared in 3.x branch and is fixed in 3.4.0
75 # but the check would be too complicated to get 3.4.
76 # Instead, rule out any 3.x compiler.
78 # Note that the flag didn't exist before gcc 3.0
79 optCFLAGS="$optCFLAGS -fno-loop-optimize"
81 dnl A C_MSG_WARN(GCC_VER_MAJ=$GCC_VER_MAJ)
83 AC_MSG_RESULT($optCFLAGS)
84 # Take it only if CFLAGS not explicitly set. Unless the flag was explicitly given
85 if test "x$cflags_set" != "xyes" ; then
86 CFLAGS="$optCFLAGS $CFLAGS"
90 if test x$lt_cv_prog_gnu_ld = xyes ; then
91 LD_DYNAMIC_FLAGS=-Wl,--export-dynamic
95 AC_SUBST(LD_DYNAMIC_FLAGS)