# [PATCH] configure.ac: Add --with-gcc-warnings configure option

4 messages from 2012-03-06 to 2012-03-06. Participants: Elia Pinto, Stefano Lattarini.
Thread: https://gitlist.dev/t/29858

## Elia Pinto, 2012-03-06 14:33

Subject: [PATCH] configure.ac: Add --with-gcc-warnings configure option
Message-ID: <1331044385-14796-1-git-send-email-gitter.spiros@gmail.com>
URL: https://gitlist.dev/e/1331044385-14796-1-git-send-email-gitter.spiros%40gmail.com

```
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

```

## Stefano Lattarini, 2012-03-06 15:51

Subject: Re: [PATCH] configure.ac: Add --with-gcc-warnings configure option
Message-ID: <4F56329E.9050506@gmail.com>
URL: https://gitlist.dev/e/4F56329E.9050506%40gmail.com
In-Reply-To: <1331044385-14796-1-git-send-email-gitter.spiros@gmail.com>

```
On 03/06/2012 03:33 PM, Elia Pinto wrote:
> 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)
>
Wouldn't it be better to use $(WARN_CFLAGS) here?  It makes the purpose
of the variable clearer, and don't give the wrong impression that Automake
is involved (as the 'AM_' prefix might suggest).

>  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@
>
Accordingly here: s/AM_CFLAGS/WARN_CFLAGS/ and s/GIT_CFLAGS/WARN_CFLAGS/.

> +# GIT_CFLAGS_ADD(PARAMETER, [VARIABLE = GIT_CFLAGS])
> +# ------------------------------------------------
>
And here as well: s/GIT_CFLAGS/WARN_CFLAGS/.  Ditto for the rest of the
M4 file.

Regards,
  Stefano

```

## Elia Pinto, 2012-03-06 16:08

Subject: Re: [PATCH] configure.ac: Add --with-gcc-warnings configure option
Message-ID: <CA+EOSBm6autG8MCe1fWC+8V=Kx6FkAuVdS-SLKUzkmxz-x-qiw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BEOSBm6autG8MCe1fWC%2B8V%3DKx6FkAuVdS-SLKUzkmxz-x-qiw%40mail.gmail.com
In-Reply-To: <4F56329E.9050506@gmail.com>

```
2012/3/6 Stefano Lattarini <stefano.lattarini@gmail.com>:
> On 03/06/2012 03:33 PM, Elia Pinto wrote:
>> 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)
>>
> Wouldn't it be better to use $(WARN_CFLAGS) here?  It makes the purpose
> of the variable clearer, and don't give the wrong impression that Automake
> is involved (as the 'AM_' prefix might suggest).
Ok, this is derived from the similar patch in popt HEAD and in branch
1.17, for which i use  the full autofu.
No problem to reroll with your suggestions.

Thanks a lot

Regards

Elia

```

## Stefano Lattarini, 2012-03-06 16:12

Subject: Re: [PATCH] configure.ac: Add --with-gcc-warnings configure option
Message-ID: <4F563789.9080807@gmail.com>
URL: https://gitlist.dev/e/4F563789.9080807%40gmail.com
In-Reply-To: <CA+EOSBm6autG8MCe1fWC+8V=Kx6FkAuVdS-SLKUzkmxz-x-qiw@mail.gmail.com>

```
On 03/06/2012 05:08 PM, Elia Pinto wrote:
>
> No problem to reroll with your suggestions.
> 
> Thanks a lot
> 
Before doing so, consider that the git developers might disagree with
me, and their opinion certainly holds more weight than mine ...  You
might want to hear what they think before re-rolling, to save yourself
some potentially useless work.

Best regards,
  Stefano

```
