[gegl] Make the compiler show extra warnings



commit 5e0c378f8b9994e78a951160e0313f1fe59afd3d
Author: Mukund Sivaraman <muks banu com>
Date:   Wed Jul 28 13:26:09 2010 +0530

    Make the compiler show extra warnings
    
    It will be useful to fix some of these warnings one by one in the
    long run, as they could be hiding problems.
    
    This commit also removes duplicate definitions of GEGL_DETECT_CFLAGS,
    and adds a m4macros directory.

 Makefile.am                  |    2 +
 acinclude.m4                 |   22 ----------
 autogen.sh                   |    1 +
 configure.ac                 |   89 +++++++++++++++---------------------------
 m4macros/as-compiler-flag.m4 |   64 ++++++++++++++++++++++++++++++
 5 files changed, 99 insertions(+), 79 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index fc230ac..baa9463 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,7 @@
 AUTOMAKE_OPTIONS = dist-bzip2
 
+ACLOCAL_AMFLAGS = -I m4macros
+
 # The libs directory needs to be before anything which can depend on its
 # libraries, otherwise any potentially rebuilt libs won't be picked up until
 # the next run of make.
diff --git a/acinclude.m4 b/acinclude.m4
index 4bc37c5..94dab67 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1,25 +1,3 @@
-dnl GEGL_DETECT_CFLAGS(RESULT, FLAGSET)
-dnl Detect if the compiler supports a set of flags
-
-AC_DEFUN([GEGL_DETECT_CFLAGS],
-[
-  $1=
-  for flag in $2; do
-    if test -z "[$]$1"; then
-      $1_save_CFLAGS="$CFLAGS"
-      CFLAGS="$CFLAGS $flag"
-      AC_MSG_CHECKING([whether [$]CC understands [$]flag])
-      AC_TRY_COMPILE([], [], [$1_works=yes], [$1_works=no])
-      AC_MSG_RESULT([$]$1_works)
-      CFLAGS="[$]$1_save_CFLAGS"
-      if test "x[$]$1_works" = "xyes"; then
-        $1="$flag"
-      fi
-    fi
-  done
-])
-
-
 dnl The following lines were copied from gtk-doc.m4
 
 dnl Usage:
diff --git a/autogen.sh b/autogen.sh
index b400176..1cc6eac 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -21,6 +21,7 @@ GLIB_REQUIRED_VERSION=2.8.0
 INTLTOOL_REQUIRED_VERSION=0.31
 LIBTOOL_REQUIRED_VERSION=1.5
 
+ACLOCAL_FLAGS="-I m4macros"
 
 PROJECT="GEGL"
 TEST_TYPE=-f
diff --git a/configure.ac b/configure.ac
index 1bd7f28..1cea442 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,6 +54,7 @@ m4_define([graphviz_required_version], [0.0.0])
 
 AC_INIT(gegl, gegl_major_version.gegl_minor_version.gegl_micro_version)
 AC_CONFIG_SRCDIR([gegl/gegl.h])
+AC_CONFIG_MACRO_DIR([m4macros])
 
 # Enable silent build rules by default, requires at least
 # Automake-1.11. Disable by either passing --disable-silent-rules to
@@ -187,34 +188,6 @@ else
 fi
 
 
-changequote(,)dnl
-if eval "test x$GCC = xyes"; then
-  case " $CFLAGS " in
-  *[\ \	]-Wall[\ \	]*) ;;
-  *) CFLAGS="$CFLAGS -Wall" ;;
-  esac
-changequote([,])dnl
-
-GEGL_DETECT_CFLAGS(extra_warnings, '-Wdeclaration-after-statement')
-CFLAGS="$CFLAGS $extra_warnings"
-
-GEGL_DETECT_CFLAGS(extra_warnings, '-Wmissing-prototypes')
-CFLAGS="$CFLAGS $extra_warnings"
-
-GEGL_DETECT_CFLAGS(extra_warnings, '-Wmissing-declarations')
-CFLAGS="$CFLAGS $extra_warnings"
-
-GEGL_DETECT_CFLAGS(extra_warnings, '-Winit-self')
-CFLAGS="$CFLAGS $extra_warnings"
-
-GEGL_DETECT_CFLAGS(extra_warnings, '-Wpointer-arith')
-CFLAGS="$CFLAGS $extra_warnings"
-
-GEGL_DETECT_CFLAGS(extra_warnings, '-Wold-style-definition')
-CFLAGS="$CFLAGS $extra_warnings"
-
-fi
-
 dnl disable docs generation.
 AC_ARG_ENABLE([docs],
               [  --disable-docs          disable docs generation (default=no)],,
@@ -358,27 +331,6 @@ dnl Checks for programs.
 # Check for MMX assembly
 ########################
 
-dnl GEGL_DETECT_CFLAGS(RESULT, FLAGSET)
-dnl Detect if the compiler supports a set of flags
-
-AC_DEFUN([GEGL_DETECT_CFLAGS],
-[
-  $1=
-  for flag in $2; do
-    if test -z "[$]$1"; then
-      $1_save_CFLAGS="$CFLAGS"
-      CFLAGS="$CFLAGS $flag"
-      AC_MSG_CHECKING([whether [$]CC understands [$]flag])
-      AC_TRY_COMPILE([], [], [$1_works=yes], [$1_works=no])
-      AC_MSG_RESULT([$]$1_works)
-      CFLAGS="[$]$1_save_CFLAGS"
-      if test "x[$]$1_works" = "xyes"; then
-        $1="$flag"
-      fi
-    fi
-  done
-])
-
 AC_ARG_ENABLE(mmx,
                 [  --enable-mmx            enable MMX support (default=auto)],,
                   enable_mmx=$have_x86)
@@ -388,7 +340,7 @@ AC_ARG_ENABLE(sse,
   enable_sse=$enable_mmx)
 
 if test "x$enable_mmx" = "xyes"; then
-  GEGL_DETECT_CFLAGS(MMX_EXTRA_CFLAGS, '-mmmx')
+  AS_COMPILER_FLAG([-mmmx], [MMX_EXTRA_CFLAGS="-mmmx"])
   SSE_EXTRA_CFLAGS=
 
   AC_MSG_CHECKING(whether we can compile MMX code)
@@ -402,12 +354,12 @@ if test "x$enable_mmx" = "xyes"; then
     AC_MSG_RESULT(yes)
 
     if test "x$enable_sse" = "xyes"; then
-      GEGL_DETECT_CFLAGS(sse_flag, '-msse')
-      SSE_EXTRA_CFLAGS="$MMX_EXTRA_CFLAGS $sse_flag"
+      AS_COMPILER_FLAG([-msse], [SSE_EXTRA_CFLAGS_X="-msse"])
+      SSE_EXTRA_CFLAGS="$MMX_EXTRA_CFLAGS $SSE_EXTRA_CFLAGS_X"
 
       AC_MSG_CHECKING(whether we can compile SSE code)
 
-      CFLAGS="$CFLAGS $sse_flag"
+      CFLAGS="$CFLAGS $SSE_EXTRA_CFLAGS_X"
 
       AC_COMPILE_IFELSE([asm ("movntps %xmm0, 0");],
         AC_DEFINE(USE_SSE, 1, [Define to 1 if SSE assembly is available.])
@@ -532,10 +484,6 @@ else
 fi
 AC_MSG_RESULT($have_glib_2_21)
 
-if test "x$have_glib_2_21" != "xyes"; then
-  CPPFLAGS="${CPPFLAGS} -DG_DISABLE_DEPRECATED"
-fi
-
 
 ######################################
 # Checks for gtk-doc and docbook-tools
@@ -994,6 +942,33 @@ AC_ARG_ENABLE([workshop],
 AM_CONDITIONAL(ENABLE_WORKSHOP, test "x$enable_workshop" = "xyes")
 
 
+#######################
+# Enable extra warnings
+#######################
+
+
+DESIRED_CFLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Wnested-externs -Winit-self -Wpacked -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
+
+# Also desirable:
+#   DESIRED_CFLAGS="-Wfloat-equal -Waggregate-return -Wredundant-decls $DESIRED_CFLAGS"
+
+#if test -z "${MAINTAINER_MODE_TRUE}"; then
+#   DESIRED_CFLAGS="-Werror $DESIRED_CFLAGS"
+#fi
+
+for flag in $DESIRED_CFLAGS; do
+  AS_COMPILER_FLAG([$flag], [CFLAGS="$CFLAGS $flag"])
+done
+
+# We should support this at some point if possible
+#LDFLAGS="-Wl,-z,defs"
+
+dnl Disable deprecated features in maintainer mode
+if test -z "${MAINTAINER_MODE_TRUE}"; then
+   GLIB_CFLAGS="-DG_DISABLE_DEPRECATED $GLIB_CFLAGS"
+   GTK_CFLAGS="-DG_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED $GTK_CFLAGS"
+fi
+
 dnl bin/node-editors/Makefile
 AC_OUTPUT([
 Makefile
diff --git a/m4macros/as-compiler-flag.m4 b/m4macros/as-compiler-flag.m4
new file mode 100644
index 0000000..882a4c7
--- /dev/null
+++ b/m4macros/as-compiler-flag.m4
@@ -0,0 +1,64 @@
+dnl as-compiler-flag.m4 0.1.0
+
+dnl autostars m4 macro for detection of compiler flags
+
+dnl David Schleef <ds schleef org>
+dnl Tim-Philipp Müller <tim centricular net>
+
+dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
+dnl Tries to compile with the given CFLAGS.
+dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
+dnl and ACTION-IF-NOT-ACCEPTED otherwise.
+
+AC_DEFUN([AS_COMPILER_FLAG],
+[
+  AC_MSG_CHECKING([to see if compiler understands $1])
+
+  save_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $1"
+
+  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+  CFLAGS="$save_CFLAGS"
+
+  if test "X$flag_ok" = Xyes ; then
+    $2
+    true
+  else
+    $3
+    true
+  fi
+  AC_MSG_RESULT([$flag_ok])
+])
+
+dnl AS_CXX_COMPILER_FLAG(CPPFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
+dnl Tries to compile with the given CPPFLAGS.
+dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
+dnl and ACTION-IF-NOT-ACCEPTED otherwise.
+
+AC_DEFUN([AS_CXX_COMPILER_FLAG],
+[
+  AC_REQUIRE([AC_PROG_CXX])
+
+  AC_MSG_CHECKING([to see if c++ compiler understands $1])
+
+  save_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $1"
+
+  AC_LANG_PUSH(C++)
+
+  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+  CPPFLAGS="$save_CPPFLAGS"
+
+  if test "X$flag_ok" = Xyes ; then
+    $2
+    true
+  else
+    $3
+    true
+  fi
+
+  AC_LANG_POP(C++)
+
+  AC_MSG_RESULT([$flag_ok])
+])
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]