Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement a generic resource; use it as ancestor to specific ones
[simgrid.git] / acmacro / compiler-flags.m4
1 dnl SG_COMPILE_FLAGS
2 dnl Turn on many useful compiler warnings
3 dnl For now, only sets extra flags on GCC
4
5
6 dnl Copyright (C) 2004, 2005, 2007. Martin Quinson. All rights reserved.
7
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.
11
12
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)
17
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)
21
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
25     case $CC in 
26       *gcc)
27       if test "$CFLAGS" = "-g -O2" ; then
28         CFLAGS="-g3"
29       fi
30       if test "$CXXFLAGS" = "-g -O2" ; then
31         CXXFLAGS="-g3"
32       fi
33       if test "$GCJFLAGS" = "-g -O2" ; then
34         CXXFLAGS="-g3"
35       fi;;
36     esac
37
38   if test "x$enable_compile_warnings" = "xyes" ; then
39     AC_MSG_CHECKING(the warning flags for this compiler)
40     warnCFLAGS=
41     if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
42       case " $CFLAGS " in
43       *-Wall*) ;;
44       *) warnCFLAGS="-Wall -Wunused" ;;
45       esac
46
47       ## -W is not all that useful.  And it cannot be controlled
48       ## with individual -Wno-xxx flags, unlike -Wall
49       
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 -Wno-format-nonliteral \
56         -Werror \
57         | sed 's/ +/ /g'`
58         # -Wno-unused-variable  -Wno-unused-label
59       fi
60     fi
61     AC_MSG_RESULT($warnCFLAGS)
62     # placed before since gcc remembers the last one on conflict
63     CFLAGS="$warnCFLAGS $CFLAGS"
64   fi
65   
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)
69     optCFLAGS=
70     if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
71         case " $CFLAGS " in
72         *-O*) ;;
73         *) optCFLAGS="$optCFLAGS -O3" ;;
74         esac
75         optCFLAGS="$optCFLAGS -finline-functions -funroll-loops -fno-strict-aliasing"
76         # now that surf uses advanced maths in lagrangian, -ffast-math do break things
77       
78         GCC_VER=`gcc --version | head -n 1 | sed 's/^[^0-9]*\([^ ]*\).*$/\1/'`
79         GCC_VER_MAJ=`echo $GCC_VER | sed 's/^\(.\).*$/\1/'`
80         if test "x$target_cpu" = "xpowerpc" && test "x$GCC_VER_MAJ" == "x3" ; then
81           # avoid gcc bug #12828, which apeared in 3.x branch and is fixed in 3.4.0
82           # but the check would be too complicated to get 3.4. 
83           # Instead, rule out any 3.x compiler.
84           
85           # Note that the flag didn't exist before gcc 3.0
86           optCFLAGS="$optCFLAGS -fno-loop-optimize"
87         fi
88         dnl A C_MSG_WARN(GCC_VER_MAJ=$GCC_VER_MAJ)
89     fi
90     AC_MSG_RESULT($optCFLAGS)
91     # Take it only if CFLAGS not explicitly set. Unless the flag was explicitly given
92     if test "x$cflags_set" != "xyes" ; then  
93       CFLAGS="$optCFLAGS $CFLAGS"
94     fi
95   fi
96
97   if test x$lt_cv_prog_gnu_ld = xyes ; then
98     LD_DYNAMIC_FLAGS=-Wl,--export-dynamic
99   else
100     LD_DYNAMIC_FLAGS=
101   fi
102   AC_SUBST(LD_DYNAMIC_FLAGS) 
103   
104 ])