]> err.no Git - libchamplain/commitdiff
Build with warning flags
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 8 Mar 2009 22:37:15 +0000 (00:37 +0200)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 8 Mar 2009 22:37:15 +0000 (00:37 +0200)
champlain/Makefile.am
configure.ac
m4/acinclude.m4 [new file with mode: 0644]

index 7b5ac39a8e6c6da725118e9e85ff3a8b519bcc3b..3d37e60a44e49cc972a6023af31cee752e266a94 100644 (file)
@@ -70,8 +70,18 @@ libchamplain_includedir = $(includedir)/libchamplain-0.3/champlain
 
 libchamplain_0_3_la_LDFLAGS = -version-info $(LIBRARY_VERSION)
 
-AM_CPPFLAGS = $(DEPS_CFLAGS) -DDATADIR=\""$(datadir)"\" -I$(top_srcdir)/tidy -I$(top_srcdir) -DCHAMPLAIN_COMPILATION
-AM_LDFLAGS = $(DEPS_LIBS) -export-symbols-regex ^champlain_.*
+AM_CPPFLAGS =                          \
+       $(DEPS_CFLAGS)                  \
+       -DDATADIR=\""$(datadir)"\"      \
+       -I$(top_srcdir)/tidy            \
+       -I$(top_srcdir)                 \
+       -DCHAMPLAIN_COMPILATION         \
+       $(WARN_CFLAGS)
+
+AM_LDFLAGS =                           \
+       $(DEPS_LIBS)                    \
+       -export-symbols-regex           \
+       ^champlain_.*
 
 svgdir = $(datadir)/champlain
 svg_DATA = error.svg
index 98cd7460f811852b1d916a06493856a869907d1a..7bef2b5347fc5d368b35199ae8c1e9e6c1c605b2 100644 (file)
@@ -14,6 +14,7 @@ AM_PROG_LIBTOOL
 
 # Checks for programs.
 AC_PROG_CC
+AM_PROG_CC_C_O
 AC_PATH_PROG([GLIB_GENMARSHAL], [glib-genmarshal])
 
 # Checks for libraries.
@@ -39,6 +40,7 @@ PKG_CHECK_MODULES(DEPS,
 )
 # check for gtk-doc
 GTK_DOC_CHECK(1.9)
+IDT_COMPILE_WARNINGS
 
 # -----------------------------------------------------------
 # Enable debug
diff --git a/m4/acinclude.m4 b/m4/acinclude.m4
new file mode 100644 (file)
index 0000000..18cf7c8
--- /dev/null
@@ -0,0 +1,65 @@
+dnl Turn on the additional warnings last, so -Werror doesn't affect other tests.
+
+AC_DEFUN([IDT_COMPILE_WARNINGS],[
+   if test -f $srcdir/autogen.sh; then
+       default_compile_warnings="error"
+    else
+       default_compile_warnings="no"
+    fi
+
+    AC_ARG_WITH(compile-warnings,
+                AS_HELP_STRING([--with-compile-warnings=@<:@no/yes/error@:>@],
+                               [Compiler warnings]),
+                [enable_compile_warnings="$withval"],
+                [enable_compile_warnings="$default_compile_warnings"])
+
+    warnCFLAGS=
+    if test "x$GCC" != xyes; then
+       enable_compile_warnings=no
+    fi
+
+    warning_flags=
+    realsave_CFLAGS="$CFLAGS"
+
+    case "$enable_compile_warnings" in
+    no)
+       warning_flags=
+       ;;
+    yes)
+       warning_flags="-Wall -Wunused -Wmissing-prototypes -Wmissing-declarations"
+       ;;
+    maximum|error)
+       warning_flags="-Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wchar-subscripts -Wnested-externs -Wpointer-arith"
+       CFLAGS="$warning_flags $CFLAGS"
+       for option in -Wno-sign-compare -Wno-pointer-sign -Wformat; do
+               SAVE_CFLAGS="$CFLAGS"
+               CFLAGS="$CFLAGS $option"
+               AC_MSG_CHECKING([whether gcc understands $option])
+               AC_TRY_COMPILE([], [],
+                       has_option=yes,
+                       has_option=no,)
+               CFLAGS="$SAVE_CFLAGS"
+               AC_MSG_RESULT($has_option)
+               if test $has_option = yes; then
+                 warning_flags="$warning_flags $option"
+               fi
+               unset has_option
+               unset SAVE_CFLAGS
+       done
+       unset option
+       if test "$enable_compile_warnings" = "error" ; then
+           warning_flags="$warning_flags -Werror"
+       fi
+       ;;
+    *)
+       AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
+       ;;
+    esac
+    CFLAGS="$realsave_CFLAGS"
+    AC_MSG_CHECKING(what warning flags to pass to the C compiler)
+    AC_MSG_RESULT($warning_flags)
+
+    WARN_CFLAGS="$warning_flags"
+    AC_SUBST(WARN_CFLAGS)
+])
+