Merge branch 'master' of git://carlos/home/carlos/work/shared/giggle
[giggle.git] / acinclude.m4
blob0bfaca0a73596cb031609abf2f63b9e1c3da73db
1 dnl Turn on the additional warnings last, so -Werror doesn't affect other tests.                                                                                
2 AC_DEFUN([IMENDIO_COMPILE_WARNINGS],[
3    if test -f $srcdir/autogen.sh; then
4         default_compile_warnings="error"
5     else
6         default_compile_warnings="no"
7     fi
8                                                                                 
9     AC_ARG_WITH(compile-warnings, [  --with-compile-warnings=[no/yes/error] Compiler warnings ], [enable_compile_warnings="$withval"], [enable_compile_warnings="$default_compile_warnings"])
10                                                                                 
11     warnCFLAGS=
12     if test "x$GCC" != xyes; then
13         enable_compile_warnings=no
14     fi
15                                                                                 
16     warning_flags=
17     realsave_CFLAGS="$CFLAGS"
18                                                                                 
19     case "$enable_compile_warnings" in
20     no)
21         warning_flags=
22         ;;
23     yes)
24         warning_flags="-Wall -Wunused -Wmissing-prototypes -Wmissing-declarations"
25         ;;
26     maximum|error)
27         warning_flags="-Wall -Wunused -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -std=c99"
28         CFLAGS="$warning_flags $CFLAGS"
29         for option in -Wno-sign-compare -Wno-pointer-sign; do
30                 SAVE_CFLAGS="$CFLAGS"
31                 CFLAGS="$CFLAGS $option"
32                 AC_MSG_CHECKING([whether gcc understands $option])
33                 AC_TRY_COMPILE([], [],
34                         has_option=yes,
35                         has_option=no,)
36                 CFLAGS="$SAVE_CFLAGS"
37                 AC_MSG_RESULT($has_option)
38                 if test $has_option = yes; then
39                   warning_flags="$warning_flags $option"
40                 fi
41                 unset has_option
42                 unset SAVE_CFLAGS
43         done
44         unset option
45         if test "$enable_compile_warnings" = "error" ; then
46             warning_flags="$warning_flags -Werror"
47         fi
48         ;;
49     *)
50         AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
51         ;;
52     esac
53     CFLAGS="$realsave_CFLAGS"
54     AC_MSG_CHECKING(what warning flags to pass to the C compiler)
55     AC_MSG_RESULT($warning_flags)
56                                                                                 
57     WARN_CFLAGS="$warning_flags"
58     AC_SUBST(WARN_CFLAGS)