From 03227ed1c40290d0db2abcf6e6f70b4d28c5a92d Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Sat, 8 Oct 2011 07:48:01 +0000 Subject: [PATCH] Add some CFLAGS in maintainer mode if supported by gcc: -Wformat -Wformat-security -Werror=format-security -Werror=declaration-after-statement Add new macro APACHE_ADD_GCC_CFLAGS to do the compatibility check. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1180331 13f79535-47bb-0310-9956-ffa450edef68 --- acinclude.m4 | 22 ++++++++++++++++++++++ configure.in | 30 ++++++++++-------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 2e0907e6a9..f51d27d960 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -706,3 +706,25 @@ YES_IS_DEFINED CPPFLAGS="$apache_old_cppflags" ]) ]) + +dnl +dnl APACHE_ADD_GCC_CFLAGS +dnl +dnl Check if compiler is gcc and supports flag. If yes, add to CFLAGS. +dnl +AC_DEFUN([APACHE_ADD_GCC_CFLAG], [ + define([ap_gcc_ckvar], [ac_cv_gcc_]translit($1, [-:.=], [____])) + if test "$GCC" = "yes"; then + AC_CACHE_CHECK([whether gcc accepts $1], ap_gcc_ckvar, [ + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $1" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int foo() { return 0; }])], + [ap_gcc_ckvar=yes], [ap_gcc_ckvar=no]) + CFLAGS="$save_CFLAGS" + ]) + if test "$]ap_gcc_ckvar[" = "yes" ; then + APR_ADDTO(CFLAGS,[$1]) + fi + fi + undefine([ap_gcc_ckvar]) +]) diff --git a/configure.in b/configure.in index 8552213417..43ecea81e9 100644 --- a/configure.in +++ b/configure.in @@ -541,16 +541,11 @@ AC_ARG_ENABLE(maintainer-mode,APACHE_HELP_STRING(--enable-maintainer-mode,Turn o APR_ADDTO(CPPFLAGS, -DAP_DEBUG) if test "$GCC" = "yes"; then APR_ADDTO(CFLAGS,[-Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wpointer-arith]) - AC_CACHE_CHECK([whether gcc accepts -Wdeclaration-after-statement], [ap_cv_cc_Wdas], [ - save_CFLAGS=$CFLAGS - CFLAGS="$CFLAGS -Wdeclaration-after-statement" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([int foo() { return 0; }])], - [ap_cv_cc_Wdas=yes], [ap_cv_cc_Wdas=no]) - CFLAGS=$save_CFLAGS - ]) - if test "$ap_cv_cc_Wdas" = "yes"; then - APR_ADDTO(CFLAGS,[-Wdeclaration-after-statement]) - fi + APACHE_ADD_GCC_CFLAG([-Wdeclaration-after-statement]) + APACHE_ADD_GCC_CFLAG([-Werror=declaration-after-statement]) + APACHE_ADD_GCC_CFLAG([-Wformat]) + APACHE_ADD_GCC_CFLAG([-Wformat-security]) + APACHE_ADD_GCC_CFLAG([-Werror=format-security]) elif test "$AIX_XLC" = "yes"; then APR_ADDTO(CFLAGS,-qfullpath -qinitauto=FE -qcheck=all -qinfo=pro) fi @@ -561,16 +556,11 @@ AC_ARG_ENABLE(debugger-mode,APACHE_HELP_STRING(--enable-debugger-mode,Turn on de APR_ADDTO(CPPFLAGS, -DAP_DEBUG) if test "$GCC" = "yes"; then APR_ADDTO(CFLAGS,[-Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wpointer-arith -O0]) - AC_CACHE_CHECK([whether gcc accepts -Wdeclaration-after-statement], [ap_cv_cc_Wdas], [ - save_CFLAGS=$CFLAGS - CFLAGS="$CFLAGS -Wdeclaration-after-statement" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([int foo() { return 0; }])], - [ap_cv_cc_Wdas=yes], [ap_cv_cc_Wdas=no]) - CFLAGS=$save_CFLAGS - ]) - if test "$ap_cv_cc_Wdas" = "yes"; then - APR_ADDTO(CFLAGS,[-Wdeclaration-after-statement]) - fi + APACHE_ADD_GCC_CFLAG([-Wdeclaration-after-statement]) + APACHE_ADD_GCC_CFLAG([-Werror=declaration-after-statement]) + APACHE_ADD_GCC_CFLAG([-Wformat]) + APACHE_ADD_GCC_CFLAG([-Wformat-security]) + APACHE_ADD_GCC_CFLAG([-Werror=format-security]) elif test "$AIX_XLC" = "yes"; then APR_ADDTO(CFLAGS,-qfullpath -qinitauto=FE -qcheck=all -qinfo=pro) fi -- 2.50.1