Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
We would like to check the availability of some funky C++ function (for gtnets)
[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   if test "x$cflags_set" != "xyes" ; then 
17     # if user didn't specify CFLAGS explicitely
18     
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
21     saveCFLAGS="$CFLAGS"
22     CFLAGS=
23     case " $saveCFLAGS " in
24     *-g*) CFLAGS="-g" ;; 
25     esac
26     case " $saveCFLAGS " in
27     *-O2*) test "x$CC" = xgcc || CFLAGS="$CFLAGS -O2" ;; 
28     esac
29     
30     # damn AC PROG CC, why did you set -O??
31     CFLAGS="-g"
32   fi
33
34   if test "x$enable_compile_warnings" = "xyes" ; then
35     AC_MSG_CHECKING(the warning flags for this compiler)
36     warnCFLAGS=
37     if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
38       case " $CFLAGS " in
39       *-Wall*) ;;
40       *) warnCFLAGS="-Wall -Wunused" ;;
41       esac
42
43       ## -W is not all that useful.  And it cannot be controlled
44       ## with individual -Wno-xxx flags, unlike -Wall
45       
46       ## -Wformat=2 chokes on the snprintf replacement because the format is passed to real sprintf
47       ## -Wshadow chokes on try{ try{} } constructs
48       if test "x$enable_compile_warnings" = "xyes"; then
49         warnCFLAGS=`echo $warnCFLAGS  -Wmissing-prototypes -Wmissing-declarations \
50         -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings \
51         -Wno-unused-function  \
52         -Werror \
53         | sed 's/ +/ /g'`
54         # -Wno-unused-variable  -Wno-unused-label
55       fi
56     fi
57     AC_MSG_RESULT($warnCFLAGS)
58     # placed before since gcc remembers the last one on conflict
59     CFLAGS="$warnCFLAGS $CFLAGS"
60   fi
61   
62   if test "x$enable_compile_optimizations" = "xyes" ||
63      test "x$enable_compile_optimizations" = "xauto" ; then
64     AC_MSG_CHECKING(the optimization flags for this compiler)
65     optCFLAGS=
66     if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
67         case " $CFLAGS " in
68         *-O*) ;;
69         *) optCFLAGS="$optCFLAGS -O3" ;;
70         esac
71         optCFLAGS="$optCFLAGS -finline-functions -ffast-math -funroll-loops -fno-strict-aliasing"
72       
73         GCC_VER=`gcc --version | head -n 1 | sed 's/^[^0-9]*\([^ ]*\).*$/\1/'`
74         GCC_VER_MAJ=`echo $GCC_VER | sed 's/^\(.\).*$/\1/'`
75         if test "x$target_cpu" = "xpowerpc" && test "x$GCC_VER_MAJ" == "x3" ; then
76           # avoid gcc bug #12828, which apeared in 3.x branch and is fixed in 3.4.0
77           # but the check would be too complicated to get 3.4. 
78           # Instead, rule out any 3.x compiler.
79           
80           # Note that the flag didn't exist before gcc 3.0
81           optCFLAGS="$optCFLAGS -fno-loop-optimize"
82         fi
83         dnl A C_MSG_WARN(GCC_VER_MAJ=$GCC_VER_MAJ)
84     fi
85     AC_MSG_RESULT($optCFLAGS)
86     # Take it only if CFLAGS not explicitly set. Unless the flag was explicitly given
87     if test "x$cflags_set" != "xyes" ; then  
88       CFLAGS="$optCFLAGS $CFLAGS"
89     fi
90   fi
91
92   if test x$lt_cv_prog_gnu_ld = xyes ; then
93     LD_DYNAMIC_FLAGS=-Wl,--export-dynamic
94   else
95     LD_DYNAMIC_FLAGS=
96   fi
97   AC_SUBST(LD_DYNAMIC_FLAGS) 
98   
99 ])