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