From c950d1480dc2bf72b4ea69f32976be016c66135f Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 30 Jun 2010 17:05:36 -0700 Subject: [PATCH] Only make compiler warnings fatal with --enable-debug While in theory I like the idea of compiler warnings always being fatal. In practice this causes problems when small harmless errors cause build failures for end users. To handle this I've updated the build system such that -Werror is only used when --enable-debug is passed to configure. This is how I always build when developing so I'll catch all build warnings and end users will not get stuck by minor issues. --- Makefile.in | 1 + cmd/Makefile.in | 5 +-- config/Rules.am | 4 +-- config/spl-build.m4 | 17 +++++++--- configure | 83 ++++++++++++++++++++++++++++++++------------- include/Makefile.in | 1 + lib/Makefile.in | 5 +-- scripts/Makefile.in | 1 + spl_config.h.in | 6 ++++ 9 files changed, 89 insertions(+), 34 deletions(-) diff --git a/Makefile.in b/Makefile.in index f2ec0112b..572e88ec2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -140,6 +140,7 @@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ diff --git a/cmd/Makefile.in b/cmd/Makefile.in index 819957e07..75e5d8d2f 100644 --- a/cmd/Makefile.in +++ b/cmd/Makefile.in @@ -114,6 +114,7 @@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ @@ -236,8 +237,8 @@ top_srcdir = @top_srcdir@ DEFAULT_INCLUDES = -include ${top_srcdir}/spl_config.h \ -I${top_srcdir}/lib AM_LIBTOOLFLAGS = --silent -AM_CFLAGS = -Wall -Wstrict-prototypes -Werror -Wshadow \ - -D__USE_LARGEFILE64 +AM_CFLAGS = -Wall -Wshadow -Wstrict-prototypes -fno-strict-aliasing \ + -D__USE_LARGEFILE64 ${DEBUG_CFLAGS} spl_SOURCES = spl.c splat_SOURCES = splat.c splat_LDFLAGS = $(top_builddir)/lib/libcommon.la diff --git a/config/Rules.am b/config/Rules.am index 7b72770b8..c6b00b6b8 100644 --- a/config/Rules.am +++ b/config/Rules.am @@ -9,5 +9,5 @@ DEFAULT_INCLUDES = -include ${top_srcdir}/spl_config.h AM_LIBTOOLFLAGS = --silent -AM_CFLAGS = -Wall -Wstrict-prototypes -Werror -Wshadow -AM_CFLAGS += -D__USE_LARGEFILE64 +AM_CFLAGS = -Wall -Wshadow -Wstrict-prototypes -fno-strict-aliasing +AM_CFLAGS += -D__USE_LARGEFILE64 ${DEBUG_CFLAGS} diff --git a/config/spl-build.m4 b/config/spl-build.m4 index 135783cdc..9fd97c06f 100644 --- a/config/spl-build.m4 +++ b/config/spl-build.m4 @@ -12,7 +12,7 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [ dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other dnl # compiler options are added by the kernel build system. abs_srcdir=`readlink -f ${srcdir}` - KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes -Werror" + KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes" KERNELCPPFLAGS="$KERNELCPPFLAGS -I${abs_srcdir}/include" KERNELCPPFLAGS="$KERNELCPPFLAGS -include ${abs_srcdir}/spl_config.h" @@ -235,6 +235,7 @@ dnl # Enable if the SPL should be compiled with internal debugging enabled. dnl # By default this support is disabled. dnl # AC_DEFUN([SPL_AC_DEBUG], [ + AC_MSG_CHECKING([whether debugging is enabled]) AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], [Enable generic debug support @<:@default=no@:>@])], @@ -242,10 +243,18 @@ AC_DEFUN([SPL_AC_DEBUG], [ [enable_debug=no]) AS_IF([test "x$enable_debug" = xyes], - [KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG"], - [KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"]) + [ + AC_DEFINE([DEBUG], [1], [Define to 1 to enable debug]) + KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror" + DEBUG_CFLAGS="-DDEBUG -Werror" + ], + [ + AC_DEFINE([NDEBUG], [1], [Define to 1 to enable debug]) + KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG" + DEBUG_CFLAGS="-DNDEBUG" + ]) - AC_MSG_CHECKING([whether debugging is enabled]) + AC_SUBST(DEBUG_CFLAGS) AC_MSG_RESULT([$enable_debug]) ]) diff --git a/configure b/configure index fe3de76dc..a0d4cf890 100755 --- a/configure +++ b/configure @@ -791,6 +791,7 @@ CONFIG_KERNEL_FALSE CONFIG_KERNEL_TRUE CONFIG_USER_FALSE CONFIG_USER_TRUE +DEBUG_CFLAGS KERNELCPPFLAGS KERNELMAKE_PARAMS LINUX_SYMBOLS @@ -4759,13 +4760,13 @@ if test "${lt_cv_nm_interface+set}" = set; then else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:4762: $ac_compile\"" >&5) + (eval echo "\"\$as_me:4763: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:4765: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:4766: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:4768: output\"" >&5) + (eval echo "\"\$as_me:4769: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -5971,7 +5972,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 5974 "configure"' > conftest.$ac_ext + echo '#line 5975 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -7824,11 +7825,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7827: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7828: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7831: \$? = $ac_status" >&5 + echo "$as_me:7832: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -8163,11 +8164,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:8166: $lt_compile\"" >&5) + (eval echo "\"\$as_me:8167: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:8170: \$? = $ac_status" >&5 + echo "$as_me:8171: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -8268,11 +8269,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:8271: $lt_compile\"" >&5) + (eval echo "\"\$as_me:8272: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:8275: \$? = $ac_status" >&5 + echo "$as_me:8276: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -8323,11 +8324,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:8326: $lt_compile\"" >&5) + (eval echo "\"\$as_me:8327: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:8330: \$? = $ac_status" >&5 + echo "$as_me:8331: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -11126,7 +11127,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11129 "configure" +#line 11130 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11222,7 +11223,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11225 "configure" +#line 11226 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11605,7 +11606,7 @@ $as_echo "$LINUX_SYMBOLS" >&6; } abs_srcdir=`readlink -f ${srcdir}` - KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes -Werror" + KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes" KERNELCPPFLAGS="$KERNELCPPFLAGS -I${abs_srcdir}/include" KERNELCPPFLAGS="$KERNELCPPFLAGS -include ${abs_srcdir}/spl_config.h" @@ -11617,6 +11618,8 @@ $as_echo "$LINUX_SYMBOLS" >&6; } + { $as_echo "$as_me:$LINENO: checking whether debugging is enabled" >&5 +$as_echo_n "checking whether debugging is enabled... " >&6; } # Check whether --enable-debug was given. if test "${enable_debug+set}" = set; then enableval=$enable_debug; @@ -11626,14 +11629,29 @@ fi if test "x$enable_debug" = xyes; then - KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG" + + +cat >>confdefs.h <<\_ACEOF +#define DEBUG 1 +_ACEOF + + KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror" + DEBUG_CFLAGS="-DDEBUG -Werror" + else - KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG" + + +cat >>confdefs.h <<\_ACEOF +#define NDEBUG 1 +_ACEOF + + KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG" + DEBUG_CFLAGS="-DNDEBUG" + fi - { $as_echo "$as_me:$LINENO: checking whether debugging is enabled" >&5 -$as_echo_n "checking whether debugging is enabled... " >&6; } + { $as_echo "$as_me:$LINENO: result: $enable_debug" >&5 $as_echo "$enable_debug" >&6; } @@ -15068,7 +15086,7 @@ $as_echo "$LINUX_SYMBOLS" >&6; } abs_srcdir=`readlink -f ${srcdir}` - KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes -Werror" + KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes" KERNELCPPFLAGS="$KERNELCPPFLAGS -I${abs_srcdir}/include" KERNELCPPFLAGS="$KERNELCPPFLAGS -include ${abs_srcdir}/spl_config.h" @@ -15080,6 +15098,8 @@ $as_echo "$LINUX_SYMBOLS" >&6; } + { $as_echo "$as_me:$LINENO: checking whether debugging is enabled" >&5 +$as_echo_n "checking whether debugging is enabled... " >&6; } # Check whether --enable-debug was given. if test "${enable_debug+set}" = set; then enableval=$enable_debug; @@ -15089,14 +15109,29 @@ fi if test "x$enable_debug" = xyes; then - KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG" + + +cat >>confdefs.h <<\_ACEOF +#define DEBUG 1 +_ACEOF + + KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror" + DEBUG_CFLAGS="-DDEBUG -Werror" + else - KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG" + + +cat >>confdefs.h <<\_ACEOF +#define NDEBUG 1 +_ACEOF + + KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG" + DEBUG_CFLAGS="-DNDEBUG" + fi - { $as_echo "$as_me:$LINENO: checking whether debugging is enabled" >&5 -$as_echo_n "checking whether debugging is enabled... " >&6; } + { $as_echo "$as_me:$LINENO: result: $enable_debug" >&5 $as_echo "$enable_debug" >&6; } diff --git a/include/Makefile.in b/include/Makefile.in index 97c854e20..21ce72f8e 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -73,6 +73,7 @@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ diff --git a/lib/Makefile.in b/lib/Makefile.in index 3ba39fff7..eb2e83134 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -106,6 +106,7 @@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ @@ -227,8 +228,8 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ DEFAULT_INCLUDES = -include ${top_srcdir}/spl_config.h AM_LIBTOOLFLAGS = --silent -AM_CFLAGS = -Wall -Wstrict-prototypes -Werror -Wshadow \ - -D__USE_LARGEFILE64 +AM_CFLAGS = -Wall -Wshadow -Wstrict-prototypes -fno-strict-aliasing \ + -D__USE_LARGEFILE64 ${DEBUG_CFLAGS} noinst_LTLIBRARIES = libcommon.la libcommon_la_SOURCES = list.c EXTRA_DIST = list.h diff --git a/scripts/Makefile.in b/scripts/Makefile.in index b171b01ff..64e414acb 100644 --- a/scripts/Makefile.in +++ b/scripts/Makefile.in @@ -68,6 +68,7 @@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ diff --git a/spl_config.h.in b/spl_config.h.in index a22ca7b8b..540b79392 100644 --- a/spl_config.h.in +++ b/spl_config.h.in @@ -3,6 +3,9 @@ /* Atomic types use spinlocks */ #undef ATOMIC_SPINLOCK +/* Define to 1 to enable debug */ +#undef DEBUG + /* Define to 1 to enable basic kmem accounting */ #undef DEBUG_KMEM @@ -208,6 +211,9 @@ */ #undef LT_OBJDIR +/* Define to 1 to enable debug */ +#undef NDEBUG + /* get_zone_counts() is needed */ #undef NEED_GET_ZONE_COUNTS