d791d0e0285ed63b9eb5415665e2c48745c2a789
[platform/upstream/gnome-common.git] / macros2 / compiler-flags.m4
1 dnl GNOME_COMPILE_WARNINGS
2 dnl Turn on many useful compiler warnings
3 dnl For now, only works on GCC
4 AC_DEFUN([GNOME_COMPILE_WARNINGS],[
5     dnl ******************************
6     dnl More compiler warnings
7     dnl ******************************
8
9     if test -z "$1" ; then
10         default_compile_warnings=no
11     else
12         default_compile_warnings="$1"
13     fi
14
15     AC_ARG_ENABLE(compile-warnings, 
16     [  --enable-compile-warnings=[no/minimum/yes/maximum/error] Turn on compiler warnings.],, [enable_compile_warnings="$default_compile_warnings"])
17
18     warnCFLAGS=
19     if test "x$GCC" != xyes; then
20         enable_compile_warnings=no
21     fi
22
23     warning_flags=
24     realsave_CFLAGS="$CFLAGS"
25
26     case "$enable_compile_warnings" in
27     no)
28         warning_flags=
29         ;;
30     minimum)
31         warning_flags="-Wall"
32         ;;
33     yes)
34         warning_flags="-Wall -Wmissing-prototypes"
35         ;;
36     maximum|error)
37         warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
38         CFLAGS="$warning_flags $CFLAGS"
39         for option in -Wno-sign-compare; do
40                 SAVE_CFLAGS="$CFLAGS"
41                 CFLAGS="$CFLAGS $option"
42                 AC_MSG_CHECKING([whether gcc understands $option])
43                 AC_TRY_COMPILE([], [],
44                         has_option=yes,
45                         has_option=no,)
46                 CFLAGS="$SAVE_CFLAGS"
47                 AC_MSG_RESULT($has_option)
48                 if test $has_option = yes; then
49                   warning_flags="$warning_flags $option"
50                 fi
51                 unset has_option
52                 unset SAVE_CFLAGS
53         done
54         unset option
55         if test "$enable_compile_warnings" = "error" ; then
56             warning_flags="$warning_flags -Werror"
57         fi
58         ;;
59     *)
60         AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
61         ;;
62     esac
63     CFLAGS="$realsave_CFLAGS"
64     AC_MSG_CHECKING(what warning flags to pass to the C compiler)
65     AC_MSG_RESULT($warning_flags)
66
67     AC_ARG_ENABLE(iso-c,
68     [  --enable-iso-c          Try to warn if code is not ISO C ],,
69     enable_iso_c=no)
70
71     AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
72     complCFLAGS=
73     if test "x$enable_iso_c" != "xno"; then
74         if test "x$GCC" = "xyes"; then
75         case " $CFLAGS " in
76             *[\ \       ]-ansi[\ \      ]*) ;;
77             *) complCFLAGS="$complCFLAGS -ansi" ;;
78         esac
79         case " $CFLAGS " in
80             *[\ \       ]-pedantic[\ \  ]*) ;;
81             *) complCFLAGS="$complCFLAGS -pedantic" ;;
82         esac
83         fi
84     fi
85     AC_MSG_RESULT($complCFLAGS)
86
87     WARN_CFLAGS="$warning_flags $complCFLAGS"
88     AC_SUBST(WARN_CFLAGS)
89 ])
90
91 dnl For C++, do basically the same thing.
92
93 AC_DEFUN([GNOME_CXX_WARNINGS],[
94   AC_ARG_ENABLE(cxx-warnings, 
95     [  --enable-cxx-warnings=[no/minimum/yes]   Turn on compiler warnings.],,enable_cxx_warnings=minimum)
96
97   AC_MSG_CHECKING(what warning flags to pass to the C++ compiler)
98   warnCXXFLAGS=
99   if test "x$GCC" != xyes; then
100     enable_compile_warnings=no
101   fi
102   if test "x$enable_cxx_warnings" != "xno"; then
103     if test "x$GCC" = "xyes"; then
104       case " $CXXFLAGS " in
105       *[\ \     ]-Wall[\ \      ]*) ;;
106       *) warnCXXFLAGS="-Wall -Wno-unused" ;;
107       esac
108
109       ## -W is not all that useful.  And it cannot be controlled
110       ## with individual -Wno-xxx flags, unlike -Wall
111       if test "x$enable_cxx_warnings" = "xyes"; then
112         warnCXXFLAGS="$warnCXXFLAGS -Wmissing-prototypes -Wmissing-declarations -Wshadow -Woverloaded-virtual"
113       fi
114     fi
115   fi
116   AC_MSG_RESULT($warnCXXFLAGS)
117
118    AC_ARG_ENABLE(iso-cxx,
119      [  --enable-iso-cxx          Try to warn if code is not ISO C++ ],,
120      enable_iso_cxx=no)
121
122    AC_MSG_CHECKING(what language compliance flags to pass to the C++ compiler)
123    complCXXFLAGS=
124    if test "x$enable_iso_cxx" != "xno"; then
125      if test "x$GCC" = "xyes"; then
126       case " $CXXFLAGS " in
127       *[\ \     ]-ansi[\ \      ]*) ;;
128       *) complCXXFLAGS="$complCXXFLAGS -ansi" ;;
129       esac
130
131       case " $CXXFLAGS " in
132       *[\ \     ]-pedantic[\ \  ]*) ;;
133       *) complCXXFLAGS="$complCXXFLAGS -pedantic" ;;
134       esac
135      fi
136    fi
137   AC_MSG_RESULT($complCXXFLAGS)
138   if test "x$cxxflags_set" != "xyes"; then
139     CXXFLAGS="$CXXFLAGS $warnCXXFLAGS $complCXXFLAGS"
140     cxxflags_set=yes
141     AC_SUBST(cxxflags_set)
142   fi
143 ])