Update po/POTFILES.in
[nautilus-actions.git] / m4 / na-compiler-flags.m4
blob50baec7996c0eafadc89a31ae8469fb2d251e963
1 dnl GNOME_COMPILE_WARNINGS
2 dnl Turn on many useful compiler warnings
3 dnl For now, only works on GCC
5 # serial 3 Fix to correctly handle provided default values
8 # pwi 2009-05-15 shamelessly copied from gnome-compiler-flags.m4
9 # two patch have been submitted (see gnome-common #582860)
12 AC_DEFUN([NA_GNOME_COMPILE_WARNINGS],[
14         _ac_warning_def=m4_default([$1],[yes])
15         _ac_compliant_def=m4_default(["$2"],[no])
17     dnl ******************************
18     dnl More compiler warnings
19     dnl ******************************
21     AC_ARG_ENABLE(compile-warnings,
22                   AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
23                                  [Turn on compiler warnings]),,
24                   [enable_compile_warnings="${_ac_warning_def}"])
26     warnCFLAGS=
27     if test "x$GCC" != xyes; then
28         enable_compile_warnings=no
29     fi
31     warning_flags=
32     realsave_CFLAGS="$CFLAGS"
34     case "$enable_compile_warnings" in
35     no)
36         warning_flags=
37         ;;
38     minimum)
39         warning_flags="-Wall"
40         ;;
41     yes)
42         warning_flags="-Wall -Wmissing-prototypes"
43         ;;
44     maximum|error)
45         warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
46         CFLAGS="$warning_flags $CFLAGS"
47         for option in -Wno-sign-compare; do
48                 SAVE_CFLAGS="$CFLAGS"
49                 CFLAGS="$CFLAGS $option"
50                 AC_MSG_CHECKING([whether gcc understands $option])
51                 AC_TRY_COMPILE([], [],
52                         has_option=yes,
53                         has_option=no,)
54                 CFLAGS="$SAVE_CFLAGS"
55                 AC_MSG_RESULT($has_option)
56                 if test $has_option = yes; then
57                   warning_flags="$warning_flags $option"
58                 fi
59                 unset has_option
60                 unset SAVE_CFLAGS
61         done
62         unset option
63         if test "$enable_compile_warnings" = "error" ; then
64             warning_flags="$warning_flags -Werror"
65         fi
66         ;;
67     *)
68         AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
69         ;;
70     esac
71     CFLAGS="$realsave_CFLAGS"
72     AC_MSG_CHECKING(what warning flags to pass to the C compiler)
73     AC_MSG_RESULT($warning_flags)
75     AC_ARG_ENABLE(iso-c,
76                   AC_HELP_STRING([--enable-iso-c],
77                                  [Try to warn if code is not ISO C ]),,
78                   [enable_iso_c="${_ac_compliant_def}"])
80     AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
81     complCFLAGS=
82     if test "x$enable_iso_c" != "xno"; then
83                 if test "x$GCC" = "xyes"; then
84                         if test "x${_ac_compliant_def}" = "x"; then
85                                 case " $CFLAGS " in
86                                         *[\ \   ]-ansi[\ \      ]*) ;;
87                                     *) complCFLAGS="$complCFLAGS -ansi" ;;
88                                 esac
89                                 case " $CFLAGS " in
90                                     *[\ \       ]-pedantic[\ \  ]*) ;;
91                                     *) complCFLAGS="$complCFLAGS -pedantic" ;;
92                                 esac
93                         else
94                                 complCFLAGS="$complCFLAGS ${_ac_compliant_def}"
95                         fi
96                 fi
97     fi
98     AC_MSG_RESULT($complCFLAGS)
100     WARN_CFLAGS="$warning_flags $complCFLAGS"
101     AC_SUBST(WARN_CFLAGS)
104 dnl For C++, do basically the same thing.
106 AC_DEFUN([GNOME_CXX_WARNINGS],[
107   AC_ARG_ENABLE(cxx-warnings,
108                 AC_HELP_STRING([--enable-cxx-warnings=@<:@no/minimum/yes@:>@]
109                                [Turn on compiler warnings.]),,
110                 [enable_cxx_warnings="m4_default([$1],[minimum])"])
112   AC_MSG_CHECKING(what warning flags to pass to the C++ compiler)
113   warnCXXFLAGS=
114   if test "x$GXX" != xyes; then
115     enable_cxx_warnings=no
116   fi
117   if test "x$enable_cxx_warnings" != "xno"; then
118     if test "x$GXX" = "xyes"; then
119       case " $CXXFLAGS " in
120       *[\ \     ]-Wall[\ \      ]*) ;;
121       *) warnCXXFLAGS="-Wall -Wno-unused" ;;
122       esac
124       ## -W is not all that useful.  And it cannot be controlled
125       ## with individual -Wno-xxx flags, unlike -Wall
126       if test "x$enable_cxx_warnings" = "xyes"; then
127         warnCXXFLAGS="$warnCXXFLAGS -Wshadow -Woverloaded-virtual"
128       fi
129     fi
130   fi
131   AC_MSG_RESULT($warnCXXFLAGS)
133    AC_ARG_ENABLE(iso-cxx,
134                  AC_HELP_STRING([--enable-iso-cxx],
135                                 [Try to warn if code is not ISO C++ ]),,
136                  [enable_iso_cxx=no])
138    AC_MSG_CHECKING(what language compliance flags to pass to the C++ compiler)
139    complCXXFLAGS=
140    if test "x$enable_iso_cxx" != "xno"; then
141      if test "x$GXX" = "xyes"; then
142       case " $CXXFLAGS " in
143       *[\ \     ]-ansi[\ \      ]*) ;;
144       *) complCXXFLAGS="$complCXXFLAGS -ansi" ;;
145       esac
147       case " $CXXFLAGS " in
148       *[\ \     ]-pedantic[\ \  ]*) ;;
149       *) complCXXFLAGS="$complCXXFLAGS -pedantic" ;;
150       esac
151      fi
152    fi
153   AC_MSG_RESULT($complCXXFLAGS)
155   WARN_CXXFLAGS="$CXXFLAGS $warnCXXFLAGS $complCXXFLAGS"
156   AC_SUBST(WARN_CXXFLAGS)
159 dnl Bug #637797 
160 dnl see also http://www.gentoo.org/proj/en/qa/asneeded.xml
161 dnl the '-Wl,--as-needed' link option is forced in make distcheck
163 AC_DEFUN([NA_LINK_AS_NEEDED],[
164         AC_ARG_ENABLE(
165                 [as-needed],
166                 AC_HELP_STRING(
167                         [--enable-as-needed],
168                         [Enable '-Wl,--as-needed' link option @<:@no@:>@]
169                 ),
170                 [enable_as_needed=$enableval],
171                 [enable_as_needed=no])
173         AC_MSG_CHECKING([whether to only link with needed libraries])
174         AC_MSG_RESULT([$enable_as_needed])
176         if test "x${enable_as_needed}" = "xyes"; then
177                 AC_SUBST([AM_LDFLAGS],["${AM_LDFLAGS} -Wl,--as-needed"])
178         fi