Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add script file to help compil with windows.
[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" ||
39      test "x$force_compile_warnings" = "xyes"; then
40     AC_MSG_CHECKING(the warning flags for this compiler)
41     warnCFLAGS=
42     if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
43       case " $CFLAGS " in
44       *-Wall*) ;;
45       *) warnCFLAGS="-Wall -Wunused" ;;
46       esac
47
48       ## -W is not all that useful.  And it cannot be controlled
49       ## with individual -Wno-xxx flags, unlike -Wall
50       
51       ## -Wformat=2 chokes on the snprintf replacement because the format is passed to real sprintf
52       ## -Wshadow chokes on try{ try{} } constructs
53       warnCFLAGS=`echo $warnCFLAGS  -Wmissing-prototypes -Wmissing-declarations \
54         -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings \
55         -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral \
56         -Werror \
57         | sed 's/ +/ /g'`
58         # -Wno-unused-variable  -Wno-unused-label
59     fi
60     AC_MSG_RESULT($warnCFLAGS)
61     # placed before since gcc remembers the last one on conflict
62     CFLAGS="$warnCFLAGS $CFLAGS"
63   fi
64   
65   if test "x$enable_compile_optimizations" = "xyes" ||
66      test "x$enable_compile_optimizations" = "xauto" ; then
67     AC_MSG_CHECKING(the optimization flags for this compiler)
68     optCFLAGS=
69     if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
70         case " $CFLAGS " in
71         *-O*) ;;
72         *) optCFLAGS="$optCFLAGS -O3" ;;
73         esac
74         optCFLAGS="$optCFLAGS -finline-functions -funroll-loops -fno-strict-aliasing"
75         # now that surf uses advanced maths in lagrangian, -ffast-math do break things
76       
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.
83           
84           # Note that the flag didn't exist before gcc 3.0
85           optCFLAGS="$optCFLAGS -fno-loop-optimize"
86         fi
87         dnl A C_MSG_WARN(GCC_VER_MAJ=$GCC_VER_MAJ)
88     fi
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"
93     fi
94   else
95     CFLAGS="$CFLAGS -O0"
96   fi
97
98   if test x$lt_cv_prog_gnu_ld = xyes ; then
99     LD_DYNAMIC_FLAGS=-Wl,--export-dynamic
100   else
101     LD_DYNAMIC_FLAGS=
102   fi
103   AC_SUBST(LD_DYNAMIC_FLAGS) 
104   
105 ])