Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Substitution of the word "resource" by "model" in every surf
[simgrid.git] / acmacro / compiler-flags.m4
1
2
3 dnl SG_COMPILE_FLAGS
4 dnl Turn on many useful compiler warnings
5 dnl For now, only sets extra flags on GCC
6
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)
11
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)
15
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
19     case $CC in 
20       *gcc)
21       if test "$CFLAGS" = "-g -O2" ; then
22         CFLAGS="-g3"
23       fi
24       if test "$CXXFLAGS" = "-g -O2" ; then
25         CXXFLAGS="-g3"
26       fi
27       if test "$GCJFLAGS" = "-g -O2" ; then
28         CXXFLAGS="-g3"
29       fi;;
30     esac
31
32   if test "x$enable_compile_warnings" = "xyes" ; then
33     AC_MSG_CHECKING(the warning flags for this compiler)
34     warnCFLAGS=
35     if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
36       case " $CFLAGS " in
37       *-Wall*) ;;
38       *) warnCFLAGS="-Wall -Wunused" ;;
39       esac
40
41       ## -W is not all that useful.  And it cannot be controlled
42       ## with individual -Wno-xxx flags, unlike -Wall
43       
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  \
50         -Werror \
51         | sed 's/ +/ /g'`
52         # -Wno-unused-variable  -Wno-unused-label
53       fi
54     fi
55     AC_MSG_RESULT($warnCFLAGS)
56     # placed before since gcc remembers the last one on conflict
57     CFLAGS="$warnCFLAGS $CFLAGS"
58   fi
59   
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)
63     optCFLAGS=
64     if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
65         case " $CFLAGS " in
66         *-O*) ;;
67         *) optCFLAGS="$optCFLAGS -O3" ;;
68         esac
69         optCFLAGS="$optCFLAGS -finline-functions -ffast-math -funroll-loops -fno-strict-aliasing"
70       
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.
77           
78           # Note that the flag didn't exist before gcc 3.0
79           optCFLAGS="$optCFLAGS -fno-loop-optimize"
80         fi
81         dnl A C_MSG_WARN(GCC_VER_MAJ=$GCC_VER_MAJ)
82     fi
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"
87     fi
88   fi
89
90   if test x$lt_cv_prog_gnu_ld = xyes ; then
91     LD_DYNAMIC_FLAGS=-Wl,--export-dynamic
92   else
93     LD_DYNAMIC_FLAGS=
94   fi
95   AC_SUBST(LD_DYNAMIC_FLAGS) 
96   
97 ])