2 dnl Turn on many useful compiler warnings
3 dnl For now, only sets extra flags on GCC
6 dnl Copyright (C) 2004, 2005, 2007. Martin Quinson. All rights reserved.
8 dnl This file is part of the SimGrid project. This is free software:
9 dnl You can redistribute and/or modify it under the terms of the
10 dnl GNU LGPL (v2.1) licence.
13 AC_DEFUN([SG_COMPILE_FLAGS],[
14 AC_ARG_ENABLE(compile-warnings,
15 AS_HELP_STRING([--enable-compile-warnings], [use compiler warnings (default=no, unless in maintainer mode)]),
16 enable_compile_warnings=$enableval,enable_compile_warnings=no)
18 AC_ARG_ENABLE(compile-optimizations,
19 AS_HELP_STRING([--disable-compile-optimizations], [use compiler optimizations (default=yes, unless if CFLAGS is explicitly set)]),
20 enable_compile_optimizations=$enableval,enable_compile_optimizations=auto)
22 # AC PROG CC tests whether -g is accepted.
23 # Cool, but it also tries to set -O2 and -g.
24 # I don't want it with gcc, but -O3 and -g2, and optimization only when asked by user
27 if test "$CFLAGS" = "-g -O2" ; then
30 if test "$CXXFLAGS" = "-g -O2" ; then
33 if test "$GCJFLAGS" = "-g -O2" ; then
38 if test "x$enable_compile_warnings" = "xyes" ; then
39 AC_MSG_CHECKING(the warning flags for this compiler)
41 if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
44 *) warnCFLAGS="-Wall -Wunused" ;;
47 ## -W is not all that useful. And it cannot be controlled
48 ## with individual -Wno-xxx flags, unlike -Wall
50 ## -Wformat=2 chokes on the snprintf replacement because the format is passed to real sprintf
51 ## -Wshadow chokes on try{ try{} } constructs
52 if test "x$enable_compile_warnings" = "xyes"; then
53 warnCFLAGS=`echo $warnCFLAGS -Wmissing-prototypes -Wmissing-declarations \
54 -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings \
55 -Wno-unused-function -Wno-strict-aliasing \
58 # -Wno-unused-variable -Wno-unused-label
61 AC_MSG_RESULT($warnCFLAGS)
62 # placed before since gcc remembers the last one on conflict
63 CFLAGS="$warnCFLAGS $CFLAGS"
66 if test "x$enable_compile_optimizations" = "xyes" ||
67 test "x$enable_compile_optimizations" = "xauto" ; then
68 AC_MSG_CHECKING(the optimization flags for this compiler)
70 if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
73 *) optCFLAGS="$optCFLAGS -O3" ;;
75 optCFLAGS="$optCFLAGS -finline-functions -ffast-math -funroll-loops -fno-strict-aliasing"
77 GCC_VER=`gcc --version | head -n 1 | sed 's/^[^0-9]*\([^ ]*\).*$/\1/'`
78 GCC_VER_MAJ=`echo $GCC_VER | sed 's/^\(.\).*$/\1/'`
79 if test "x$target_cpu" = "xpowerpc" && test "x$GCC_VER_MAJ" == "x3" ; then
80 # avoid gcc bug #12828, which apeared in 3.x branch and is fixed in 3.4.0
81 # but the check would be too complicated to get 3.4.
82 # Instead, rule out any 3.x compiler.
84 # Note that the flag didn't exist before gcc 3.0
85 optCFLAGS="$optCFLAGS -fno-loop-optimize"
87 dnl A C_MSG_WARN(GCC_VER_MAJ=$GCC_VER_MAJ)
89 AC_MSG_RESULT($optCFLAGS)
90 # Take it only if CFLAGS not explicitly set. Unless the flag was explicitly given
91 if test "x$cflags_set" != "xyes" ; then
92 CFLAGS="$optCFLAGS $CFLAGS"
96 if test x$lt_cv_prog_gnu_ld = xyes ; then
97 LD_DYNAMIC_FLAGS=-Wl,--export-dynamic
101 AC_SUBST(LD_DYNAMIC_FLAGS)