From mboxrd@z Thu Jan 1 00:00:00 1970 From: Elia Pinto Subject: [PATCH] configure.ac: Add --with-gcc-warnings configure option Date: Tue, 6 Mar 2012 09:33:05 -0500 Message-ID: <1331044385-14796-1-git-send-email-gitter.spiros@gmail.com> Cc: jnareb@gmail.com, Elia Pinto To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Mar 06 15:33:21 2012 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S4vS3-00061l-EX for gcvg-git-2@plane.gmane.org; Tue, 06 Mar 2012 15:33:20 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030753Ab2CFOdN (ORCPT ); Tue, 6 Mar 2012 09:33:13 -0500 Received: from mail-iy0-f174.google.com ([209.85.210.174]:41783 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030694Ab2CFOdM (ORCPT ); Tue, 6 Mar 2012 09:33:12 -0500 Received: by iagz16 with SMTP id z16so7128595iag.19 for ; Tue, 06 Mar 2012 06:33:11 -0800 (PST) Received-SPF: pass (google.com: domain of gitter.spiros@gmail.com designates 10.50.216.231 as permitted sender) client-ip=10.50.216.231; Authentication-Results: mr.google.com; spf=pass (google.com: domain of gitter.spiros@gmail.com designates 10.50.216.231 as permitted sender) smtp.mail=gitter.spiros@gmail.com; dkim=pass header.i=gitter.spiros@gmail.com Received: from mr.google.com ([10.50.216.231]) by 10.50.216.231 with SMTP id ot7mr12953299igc.8.1331044391719 (num_hops = 1); Tue, 06 Mar 2012 06:33:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=q7/+PN9mFKWwCSHZuQzg46HIuD86SObpjdvhea4kAE4=; b=GLedvegJ4+ej8LbVkHXZ6y8tTh3FNwFBV5WdqKPjlEygjN9EBudRk/BIr+oRIaJcP6 /qAtXQpg8k1ojcOnX70yNKG2SWc6V5dk91G4Yv9l99PwaS/KTmZvpcfnQnwjg44Ve3HH JdBKLU0gobJCsAp/IOhBNoig/+qC0iZ6uxlG6UwiwNS9I9t/8nfkflQsmh7u/y0icbI/ hSmFmHqM55AgvrpRhaKau2hLOPD3cMB1qJYQbmLlE3WsyjSxyApvmZ+PQ1H8XjRKnwoX vReJJRWILbbH7pnA9zOI3zus/M92mmO8rFVuRihtPLmhJ4haRUXi3kvm59VcIFIZXy5T LL8w== Received: by 10.50.216.231 with SMTP id ot7mr10799923igc.8.1331044391645; Tue, 06 Mar 2012 06:33:11 -0800 (PST) Received: from localhost.localdomain (vm049244212.pmman.net. [198.49.244.212]) by mx.google.com with ESMTPS id eo1sm10208007igc.17.2012.03.06.06.33.10 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 06 Mar 2012 06:33:11 -0800 (PST) X-Mailer: git-send-email 1.7.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Introduce a new --with-gcc-warnings configure option using a new autoconf macro that check if the compiler know the option passed or not in a portable way, as it not depends from the gcc version or from the other compiler used. Signed-off-by: Elia Pinto --- This is the version 2 of the patch, in which i have slightly changed the commit message for clarify the purpose. To activate the patch is of course necessary to do a autoreconf -vfi after applying the patch. Makefile | 2 +- config.mak.in | 1 + configure.ac | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index be1957a..d0aef0f 100644 --- a/Makefile +++ b/Makefile @@ -310,7 +310,7 @@ endif CFLAGS = -g -O2 -Wall LDFLAGS = -ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) +ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) $(AM_CFLAGS) ALL_LDFLAGS = $(LDFLAGS) STRIP ?= strip diff --git a/config.mak.in b/config.mak.in index b2ba710..5b7dbfd 100644 --- a/config.mak.in +++ b/config.mak.in @@ -2,6 +2,7 @@ # @configure_input@ CC = @CC@ +AM_CFLAGS = @GIT_CFLAGS@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ diff --git a/configure.ac b/configure.ac index 8bb0f44..dba42a9 100644 --- a/configure.ac +++ b/configure.ac @@ -14,6 +14,34 @@ echo "# ${config_append}. Generated by configure." > "${config_append}" ## Definitions of macros +# git_AS_VAR_APPEND(VAR, VALUE) +# ---------------------------- +# Provide the functionality of AS_VAR_APPEND if Autoconf does not have it. +m4_ifdef([AS_VAR_APPEND], +[m4_copy([AS_VAR_APPEND], [git_AS_VAR_APPEND])], +[m4_define([git_AS_VAR_APPEND], +[AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])]) + +# GIT_CFLAGS_ADD(PARAMETER, [VARIABLE = GIT_CFLAGS]) +# ------------------------------------------------ +# Adds parameter to GIT_CFLAGS if the compiler supports it. For example, +# GIT_CFLAGS_ADD([-Wall],[GIT_CFLAGS]). +AC_DEFUN([GIT_CFLAGS_ADD], +[AS_VAR_PUSHDEF([git_my_cflags], [git_cv_warn_$1])dnl +AC_CACHE_CHECK([whether compiler handles $1], [git_my_cflags], [ + save_CFLAGS="$CFLAGS" + CFLAGS="${CFLAGS} $1" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], + [AS_VAR_SET([git_my_cflags], [yes])], + [AS_VAR_SET([git_my_cflags], [no])]) + CFLAGS="$save_CFLAGS" +]) +AS_VAR_PUSHDEF([git_cflags], m4_if([$2], [], [[GIT_CFLAGS]], [[$2]]))dnl +AS_VAR_IF([git_my_cflags], [yes], [git_AS_VAR_APPEND([git_cflags], [" $1"])]) +AS_VAR_POPDEF([git_cflags])dnl +AS_VAR_POPDEF([git_my_cflags])dnl +m4_ifval([$2], [AS_LITERAL_IF([$2], [AC_SUBST([$2])], [])])dnl +]) # GIT_CONF_APPEND_LINE(LINE) # -------------------------- # Append LINE to file ${config_append} @@ -158,6 +186,96 @@ if test -z "$lib"; then lib=lib fi +# Turn gcc warning + +AC_ARG_ENABLE([gcc-warnings], + [AS_HELP_STRING([--enable-gcc-warnings], + [turn on GCC warnings (for developers)@<:@default=no@:>@])], + [case $enableval in + yes|no) ;; + *) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;; + esac + git_gcc_warnings=$enableval], + [git_gcc_warnings=no] +) + +AS_IF([test "x$git_gcc_warnings" = xyes], + [ # Add/Delete as needed + MAX_STACK_SIZE=32768 + GIT_CFLAGS_ADD([-Wall], [GIT_CFLAGS]) + GIT_CFLAGS_ADD([-pedantic], [GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wextra], [GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wformat-y2k], [GIT_CFLAGS]) + GIT_CFLAGS_ADD([-fdiagnostics-show-option],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-funit-at-a-time],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-fstrict-aliasing],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wstrict-overflow],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-fstrict-overflow],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wpointer-arith],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wundef],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wformat-security],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Winit-self],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wmissing-include-dirs],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wunused],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wunknown-pragmas],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wstrict-aliasing],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wshadow],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wbad-function-cast],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wcast-align],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wwrite-strings],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wlogical-op],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Waggregate-return],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wstrict-prototypes],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wold-style-definition],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wmissing-prototypes],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wmissing-declarations],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wmissing-noreturn],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wmissing-format-attribute],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wredundant-decls],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wnested-externs],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Winline],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Winvalid-pch],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wvolatile-register-var],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wdisabled-optimization],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wbuiltin-macro-redefined],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wmudflap],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wpacked-bitfield-compat],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wsync-nand],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wattributes],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wcoverage-mismatch],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wmultichar],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wcpp],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wdeprecated-declarations],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wdiv-by-zero],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wdouble-promotion],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wendif-labels],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wformat-contains-nul],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wformat-extra-args],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wformat-zero-length],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wformat=2],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wmultichar],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wnormalized=nfc],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Woverflow],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wpointer-to-int-cast],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wpragmas],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wsuggest-attribute=const],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wsuggest-attribute=noreturn],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wsuggest-attribute=pure],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wtrampolines],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wno-missing-field-initializers],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wno-sign-compare],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wjump-misses-init],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wno-format-nonliteral],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wframe-larger-than=$MAX_STACK_SIZE],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-fstack-protector-all],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-fasynchronous-unwind-tables],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-fdiagnostics-show-option],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-funit-at-a-time],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-fipa-pure-const],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wno-aggregate-return],[GIT_CFLAGS]) + GIT_CFLAGS_ADD([-Wno-redundant-decls],[GIT_CFLAGS]) + AC_SUBST([GIT_CFLAGS]) + ]) AC_ARG_ENABLE([pthreads], [AS_HELP_STRING([--enable-pthreads=FLAGS], [FLAGS is the value to pass to the compiler to enable POSIX Threads.] -- 1.7.8.rc3.31.g017d1