git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elia Pinto <gitter.spiros@gmail.com>
To: git@vger.kernel.org
Cc: jnareb@gmail.com, Elia Pinto <gitter.spiros@gmail.com>
Subject: [PATCH] configure.ac: Add --with-gcc-warnings configure option
Date: Tue,  6 Mar 2012 09:33:05 -0500	[thread overview]
Message-ID: <1331044385-14796-1-git-send-email-gitter.spiros@gmail.com> (raw)

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 <gitter.spiros@gmail.com>
---
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

             reply	other threads:[~2012-03-06 14:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-06 14:33 Elia Pinto [this message]
2012-03-06 15:51 ` [PATCH] configure.ac: Add --with-gcc-warnings configure option Stefano Lattarini
2012-03-06 16:08   ` Elia Pinto
2012-03-06 16:12     ` Stefano Lattarini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1331044385-14796-1-git-send-email-gitter.spiros@gmail.com \
    --to=gitter.spiros@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).