Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Got bored during a meeting: fix the copyright notice of several useless files (found...
[simgrid.git] / acmacro / compiler-flags.m4
index 1f27293..0974f53 100644 (file)
+dnl SG_COMPILE_FLAGS
+dnl Turn on many useful compiler warnings
+dnl For now, only sets extra flags on GCC
 
 
-dnl GNOME_COMPILE_WARNINGS
-dnl Turn on many useful compiler warnings
-dnl For now, only works on GCC
-AC_DEFUN([GNOME_COMPILE_WARNINGS],[
-  AC_ARG_ENABLE(compile-warnings, 
-    [  --enable-compile-warnings=[no/minimum/yes]       Turn on compiler warnings.],,enable_compile_warnings=yes)
+dnl Copyright (C) 2004, 2005, 2007. Martin Quinson. All rights reserved.
 
-  AC_MSG_CHECKING(the warning flags for this compiler)
-  warnCFLAGS=
-  if test "x$GCC" = "xyes"; then
-    case " $CFLAGS " in
-    *-Wall*) ;;
-    *) warnCFLAGS="-g -Wall -Wunused" ;;
-    esac
+dnl This file is part of the SimGrid project. This is free software:
+dnl You can redistribute and/or modify it under the terms of the
+dnl GNU LGPL (v2.1) licence.
 
-    ## -W is not all that useful.  And it cannot be controlled
-    ## with individual -Wno-xxx flags, unlike -Wall
-    if test "x$enable_compile_warnings" = "xyes"; then
-      warnCFLAGS="$warnCFLAGS  -Wmissing-prototypes -Wmissing-declarations \
- -finline-functions  -Wshadow -Wpointer-arith -Wchar-subscripts -Wcomment \
- -Wformat=2 -Wno-unused-variable -Wno-unused-function -Wwrite-strings \
- -Werror -O0"
-    fi
-  fi
 
-  AC_MSG_RESULT($warnCFLAGS)
+AC_DEFUN([SG_COMPILE_FLAGS],[
+  AC_ARG_ENABLE(compile-warnings,
+    AS_HELP_STRING([--enable-compile-warnings], [use compiler warnings (default=no, unless in maintainer mode)]),
+    enable_compile_warnings=$enableval,enable_compile_warnings=no)
 
-  AC_ARG_ENABLE(iso-c,
-    [  --enable-iso-c          Try to warn if code is not ISO C ],,
-    enable_iso_c=no)
+  AC_ARG_ENABLE(compile-optimizations,
+    AS_HELP_STRING([--disable-compile-optimizations], [use compiler optimizations (default=yes, unless if CFLAGS is explicitly set)]),
+    enable_compile_optimizations=$enableval,enable_compile_optimizations=auto)
 
-  AC_MSG_CHECKING(the language compliance flags for this compiler)
-  complCFLAGS=
-  if test "x$GCC" = "xyes"; then
-    case " $CFLAGS " in
-    *-ansi*) ;;
-    *) complCFLAGS="$complCFLAGS -ansi" ;;
+    # AC PROG CC tests whether -g is accepted. 
+    # Cool, but it also tries to set -O2 and -g. 
+    # I don't want it with gcc, but -O3 and -g2, and optimization only when asked by user
+    case $CC in 
+      *gcc)
+      if test "$CFLAGS" = "-g -O2" ; then
+        CFLAGS="-g3"
+      fi
+      if test "$CXXFLAGS" = "-g -O2" ; then
+        CXXFLAGS="-g3"
+      fi
+      if test "$GCJFLAGS" = "-g -O2" ; then
+        CXXFLAGS="-g3"
+      fi;;
     esac
 
-    case " $CFLAGS " in
-    *-pedantic*) ;;
-    *) complCFLAGS="$complCFLAGS -pedantic" ;;
-    esac
-  fi
-  AC_MSG_RESULT($complCFLAGS)
-  
-  
-  AC_MSG_CHECKING(the optimization flags for this compiler)
-  optCFLAGS=
-  if test "x$GCC" = "xyes" ; then
-      optCFLAGS="-ffast-math -funroll-loops -fno-strict-aliasing"
+  if test "x$enable_compile_warnings" = "xyes" ; then
+    AC_MSG_CHECKING(the warning flags for this compiler)
+    warnCFLAGS=
+    if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
       case " $CFLAGS " in
-      *-O*) ;;
-      *) optCFLAGS="$optCFLAGS -03" ;;
+      *-Wall*) ;;
+      *) warnCFLAGS="-Wall -Wunused" ;;
       esac
-  fi
-  AC_MSG_RESULT($optCFLAGS)
 
-  # Take the right flags
-  if test "x$cflags_set" != "xyes" ; then  
-    if test "x$enable_iso_c" != "xno"; then
-      CFLAGS="$CFLAGS $complCFLAGS $optCFLAGS"
+      ## -W is not all that useful.  And it cannot be controlled
+      ## with individual -Wno-xxx flags, unlike -Wall
+      
+      ## -Wformat=2 chokes on the snprintf replacement because the format is passed to real sprintf
+      ## -Wshadow chokes on try{ try{} } constructs
+      if test "x$enable_compile_warnings" = "xyes"; then
+        warnCFLAGS=`echo $warnCFLAGS  -Wmissing-prototypes -Wmissing-declarations \
+        -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings \
+        -Wno-unused-function  -Wno-strict-aliasing  \
+        -Werror \
+       | sed 's/ +/ /g'`
+       # -Wno-unused-variable  -Wno-unused-label
+      fi
+    fi
+    AC_MSG_RESULT($warnCFLAGS)
+    # placed before since gcc remembers the last one on conflict
+    CFLAGS="$warnCFLAGS $CFLAGS"
+  fi
+  
+  if test "x$enable_compile_optimizations" = "xyes" ||
+     test "x$enable_compile_optimizations" = "xauto" ; then
+    AC_MSG_CHECKING(the optimization flags for this compiler)
+    optCFLAGS=
+    if test "x$CC" = "xgcc" || test "x$GCC" = "xyes" ; then
+        case " $CFLAGS " in
+        *-O*) ;;
+        *) optCFLAGS="$optCFLAGS -O3" ;;
+        esac
+        optCFLAGS="$optCFLAGS -finline-functions -ffast-math -funroll-loops -fno-strict-aliasing"
+      
+        GCC_VER=`gcc --version | head -n 1 | sed 's/^[^0-9]*\([^ ]*\).*$/\1/'`
+        GCC_VER_MAJ=`echo $GCC_VER | sed 's/^\(.\).*$/\1/'`
+        if test "x$target_cpu" = "xpowerpc" && test "x$GCC_VER_MAJ" == "x3" ; then
+          # avoid gcc bug #12828, which apeared in 3.x branch and is fixed in 3.4.0
+          # but the check would be too complicated to get 3.4. 
+         # Instead, rule out any 3.x compiler.
+          
+          # Note that the flag didn't exist before gcc 3.0
+          optCFLAGS="$optCFLAGS -fno-loop-optimize"
+        fi
+        dnl A C_MSG_WARN(GCC_VER_MAJ=$GCC_VER_MAJ)
     fi
-    if test "x$enable_compile_warnings" != "xno" ; then
-      CFLAGS="$CFLAGS $warnCFLAGS $optCFLAGS"
-    fi  
-    
-    cflags_set=yes
-    AC_SUBST(cflags_set)
+    AC_MSG_RESULT($optCFLAGS)
+    # Take it only if CFLAGS not explicitly set. Unless the flag was explicitly given
+    if test "x$cflags_set" != "xyes" ; then  
+      CFLAGS="$optCFLAGS $CFLAGS"
+    fi
+  fi
+
+  if test x$lt_cv_prog_gnu_ld = xyes ; then
+    LD_DYNAMIC_FLAGS=-Wl,--export-dynamic
+  else
+    LD_DYNAMIC_FLAGS=
   fi
+  AC_SUBST(LD_DYNAMIC_FLAGS) 
+  
 ])