From: Guy Harris Date: Tue, 7 May 2013 06:54:20 +0000 (-0700) Subject: With .devel, use -W flags iff the compiler supports them. X-Git-Tag: tcpdump-4.5.0~80^2~12 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/7d0510cec8de0f7157050e9daaf0246d7d6c7eeb With .devel, use -W flags iff the compiler supports them. Don't base the question of whether to use a particular -W flag on whether we're compiling with GCC or not, and on which version of GCC we're using; some compilers, such as clang, also support many of those -W flags. Base it on whether the compiler complains if we use it (which means, for clang, that we have to force it to exit with a non-zero exit status if it doesn't like a flag; otherwise, we'll specify it, and clang will warn about it on every compile). --- diff --git a/aclocal.m4 b/aclocal.m4 index 7573fae3..55e32103 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -202,6 +202,60 @@ AC_DEFUN(AC_LBL_C_INIT, fi ]) +dnl +dnl Check whether, if you pass an unknown warning option to the +dnl compiler, it fails or just prints a warning message and succeeds. +dnl Set ac_lbl_unknown_warning_option_error to the appropriate flag +dnl to force an error if it would otherwise just print a warning message +dnl and succeed. +dnl +AC_DEFUN(AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR, + [ + AC_MSG_CHECKING([whether the compiler fails when given an unknown warning option]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wxyzzy-this-will-never-succeed-xyzzy" + AC_TRY_COMPILE( + [], + [return 0], + [ + AC_MSG_RESULT([no]) + # + # We're assuming this is clang, where + # -Werror=unknown-warning-option is the appropriate + # option to force the compiler to fail. + # + ac_lbl_unknown_warning_option_error="-Werror=unknown-warning-option" + ], + [ + AC_MSG_RESULT([yes]) + ]) + CFLAGS="$save_CFLAGS" + ]) + +dnl +dnl Check whether the compiler option specified as the second argument +dnl is supported by the compiler and, if so, add it to the macro +dnl specified as the first argument +dnl +AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT, + [ + AC_MSG_CHECKING([whether the compiler supports the $2 option]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error $2" + AC_TRY_COMPILE( + [], + [return 0], + [ + AC_MSG_RESULT([yes]) + CFLAGS="$save_CFLAGS" + $1="$$1 $2" + ], + [ + AC_MSG_RESULT([no]) + CFLAGS="$save_CFLAGS" + ]) + ]) + # # Try compiling a sample of the type of code that appears in # gencode.c with "inline", "__inline__", and "__inline". @@ -792,11 +846,11 @@ EOF fi]) dnl -dnl If using gcc and the file .devel exists: -dnl Compile with -g (if supported) and -Wall -dnl If using gcc 2 or later, do extra prototype checking and some other -dnl checks +dnl If the file .devel exists: +dnl Add some warning flags if the compiler supports them dnl If an os prototype include exists, symlink os-proto.h to it +dnl If we're using gcc: +dnl Compile with -g (if supported) dnl dnl usage: dnl @@ -814,15 +868,18 @@ AC_DEFUN(AC_LBL_DEVEL, $1="$$1 ${LBL_CFLAGS}" fi if test -f .devel ; then + AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR() + AC_LBL_CHECK_COMPILER_OPT($1, -Wall) + AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes) + AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes) + AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings) + AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith) + AC_LBL_CHECK_COMPILER_OPT($1, -W) if test "$GCC" = yes ; then if test "${LBL_CFLAGS+set}" != set; then if test "$ac_cv_prog_cc_g" = yes ; then $1="-g $$1" fi - $1="$$1 -Wall" - if test $ac_cv_lbl_gcc_vers -gt 1 ; then - $1="$$1 -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wpointer-arith -W" - fi fi else case "$host_os" in diff --git a/configure b/configure index 20ba1c14..f7b49d81 100755 --- a/configure +++ b/configure @@ -11289,15 +11289,407 @@ rm -f os-proto.h V_CCOPT="$V_CCOPT ${LBL_CFLAGS}" fi if test -f .devel ; then + + { echo "$as_me:$LINENO: checking whether the compiler fails when given an unknown warning option" >&5 +echo $ECHO_N "checking whether the compiler fails when given an unknown warning option... $ECHO_C" >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wxyzzy-this-will-never-succeed-xyzzy" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + # + # We're assuming this is clang, where + # -Werror=unknown-warning-option is the appropriate + # option to force the compiler to fail. + # + ac_lbl_unknown_warning_option_error="-Werror=unknown-warning-option" + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS="$save_CFLAGS" + + + { echo "$as_me:$LINENO: checking whether the compiler supports the -Wall option" >&5 +echo $ECHO_N "checking whether the compiler supports the -Wall option... $ECHO_C" >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wall" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + CFLAGS="$save_CFLAGS" + V_CCOPT="$V_CCOPT -Wall" + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + CFLAGS="$save_CFLAGS" + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { echo "$as_me:$LINENO: checking whether the compiler supports the -Wmissing-prototypes option" >&5 +echo $ECHO_N "checking whether the compiler supports the -Wmissing-prototypes option... $ECHO_C" >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wmissing-prototypes" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + CFLAGS="$save_CFLAGS" + V_CCOPT="$V_CCOPT -Wmissing-prototypes" + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + CFLAGS="$save_CFLAGS" + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { echo "$as_me:$LINENO: checking whether the compiler supports the -Wstrict-prototypes option" >&5 +echo $ECHO_N "checking whether the compiler supports the -Wstrict-prototypes option... $ECHO_C" >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wstrict-prototypes" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + CFLAGS="$save_CFLAGS" + V_CCOPT="$V_CCOPT -Wstrict-prototypes" + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + CFLAGS="$save_CFLAGS" + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { echo "$as_me:$LINENO: checking whether the compiler supports the -Wwrite-strings option" >&5 +echo $ECHO_N "checking whether the compiler supports the -Wwrite-strings option... $ECHO_C" >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wwrite-strings" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + CFLAGS="$save_CFLAGS" + V_CCOPT="$V_CCOPT -Wwrite-strings" + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + CFLAGS="$save_CFLAGS" + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { echo "$as_me:$LINENO: checking whether the compiler supports the -Wpointer-arith option" >&5 +echo $ECHO_N "checking whether the compiler supports the -Wpointer-arith option... $ECHO_C" >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wpointer-arith" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + CFLAGS="$save_CFLAGS" + V_CCOPT="$V_CCOPT -Wpointer-arith" + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + CFLAGS="$save_CFLAGS" + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { echo "$as_me:$LINENO: checking whether the compiler supports the -W option" >&5 +echo $ECHO_N "checking whether the compiler supports the -W option... $ECHO_C" >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -W" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + CFLAGS="$save_CFLAGS" + V_CCOPT="$V_CCOPT -W" + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + CFLAGS="$save_CFLAGS" + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + if test "$GCC" = yes ; then if test "${LBL_CFLAGS+set}" != set; then if test "$ac_cv_prog_cc_g" = yes ; then V_CCOPT="-g $V_CCOPT" fi - V_CCOPT="$V_CCOPT -Wall" - if test $ac_cv_lbl_gcc_vers -gt 1 ; then - V_CCOPT="$V_CCOPT -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wpointer-arith -W" - fi fi else case "$host_os" in