git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Compiling git with -Werror
@ 2012-04-27  9:45 Michael Haggerty
  2012-04-27  9:58 ` Thomas Rast
  2012-04-27 10:07 ` Jeff King
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Haggerty @ 2012-04-27  9:45 UTC (permalink / raw)
  To: git discussion list

I like to develop with errors and warnings turned up as strict as 
possible.  For example, I would like to use

     CFLAGS="-g -O2 -Wall -Werror -Wdeclaration-after-statement"

I thought this would be as simple as

     git clean -fdx
     make configure
     ./configure CFLAGS="-g -O2 -Wall -Werror -Wdeclaration-after-statement"
     make
     # hack
     make
     # hack
     # etc.

but the "make" step results in an error:

> $ make
>     * new build flags or prefix
>     CC daemon.o
> In file included from cache.h:4:0,
>                  from daemon.c:1:
> git-compat-util.h:359:0: error: "strtok_r" redefined [-Werror]
> /usr/include/x86_64-linux-gnu/bits/string2.h:1196:0: note: this is the location of the previous definition
> cc1: all warnings being treated as errors
> make: *** [daemon.o] Error 1

The cause of the problem is that the CFLAGS variable is used by 
./configure when it is running its tests, and some of the tests don't 
work correctly (they produce results that are not correct for the 
platform) when run with the strict CFLAGS.  For example, in the broken 
case config.log contains

> configure:4592: cc -o conftest -g -O2 -Wall -Werror -Wdeclaration-after-statement   conftest.c -lc   >&5
> conftest.c:16:6: error: conflicting types for built-in function 'gettext' [-Werror]
> cc1: all warnings being treated as errors
> configure:4592: $? = 1
> configure: failed program was:
> | /* confdefs.h */
> | #define PACKAGE_NAME "git"
> | #define PACKAGE_TARNAME "git"
> | #define PACKAGE_VERSION "1.7.10.362.g010b2"
> | #define PACKAGE_STRING "git 1.7.10.362.g010b2"
> | #define PACKAGE_BUGREPORT "git@vger.kernel.org"
> | #define PACKAGE_URL ""
> | /* end confdefs.h.  */
> |
> | /* Override any GCC internal prototype to avoid an error.
> |    Use char because int might match the return type of a GCC
> |    builtin and then its argument prototype would still apply.  */
> | #ifdef __cplusplus
> | extern "C"
> | #endif
> | char gettext ();
> | int
> | main ()
> | {
> | return gettext ();
> |   ;
> |   return 0;
> | }
> configure:4601: result: no

It is possible to work around this problem by passing the CFLAGS value 
to make rather than configure:

     git clean -fdx
     make configure
     ./configure
     make CFLAGS="-g -O2 -Wall -Werror -Wdeclaration-after-statement"
     # hack
     make CFLAGS="-g -O2 -Wall -Werror -Wdeclaration-after-statement"
     # hack
     # etc.

but it is annoying to need such a long command line for "make" (not to 
mention that I run make from the command line, from emacs, etc. and 
would have to adjust the command line everywhere).  Or the CFLAGS could 
be put into an environment variable, but this again would have to be set 
up separately (and consistently!) for every terminal and emacs sessions 
that is in use.

Is there some other mechanism to set strict CFLAGS parameters for the 
build without confusing ./configure?

Is this a bug in how the git project is using autoconf?

Is it a bug in autoconf itself?

Thanks,
Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Compiling git with -Werror
  2012-04-27  9:45 Compiling git with -Werror Michael Haggerty
@ 2012-04-27  9:58 ` Thomas Rast
  2012-04-27 10:07 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Rast @ 2012-04-27  9:58 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: git discussion list

Michael Haggerty <mhagger@alum.mit.edu> writes:

> Is there some other mechanism to set strict CFLAGS parameters for the
> build without confusing ./configure?

As mentioned on IRC, you can put

  CFLAGS = -g -O2 -Wall -Werror -Wdeclaration-after-statement

in config.mak.  The Makefile includes that if it exists, so it is a good
place to gather your custom settings.

One trick I like to do in every Makefile is

  O = 3
  CFLAGS = -g -O$(O) -Wall <blah>

That way 'make O=0' does a build suitable for debugging.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Compiling git with -Werror
  2012-04-27  9:45 Compiling git with -Werror Michael Haggerty
  2012-04-27  9:58 ` Thomas Rast
@ 2012-04-27 10:07 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2012-04-27 10:07 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: git discussion list

On Fri, Apr 27, 2012 at 11:45:20AM +0200, Michael Haggerty wrote:

> I like to develop with errors and warnings turned up as strict as
> possible.  For example, I would like to use
> 
>     CFLAGS="-g -O2 -Wall -Werror -Wdeclaration-after-statement"

That's more or less how I compile git.

> I thought this would be as simple as
> 
>     git clean -fdx
>     make configure
>     ./configure CFLAGS="-g -O2 -Wall -Werror -Wdeclaration-after-statement"

I don't use our autoconf at all, though. I put settings like that into
config.mak, which gets sourced by the Makefile (right after
config.mak.autogen, which is what configure produces).

> The cause of the problem is that the CFLAGS variable is used by
> ./configure when it is running its tests, and some of the tests don't
> work correctly (they produce results that are not correct for the
> platform) when run with the strict CFLAGS.
> [...]
> Is there some other mechanism to set strict CFLAGS parameters for the
> build without confusing ./configure?

Try putting "CFLAGS += -Werror" in config.mak.

> Is this a bug in how the git project is using autoconf?
> 
> Is it a bug in autoconf itself?

I think autoconf. Our configure input is just using
AC_CHECK_FUNC(strtok_r) to generate the test.  Which would mean that
it's a bad interaction of autoconf's code and your CFLAGS. So I would be
surprised if other packages didn't have similar problems.

And indeed, googling for 'autoconf cflags "-Werror"' turns up:

  http://lists.gnu.org/archive/html/bug-autoconf/2012-03/msg00070.html

Summary: don't do that. We could add a special option to turn on
warnings, but given how easy the config.mak trick above is, I don't know
that it's necessary.

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-27 10:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-27  9:45 Compiling git with -Werror Michael Haggerty
2012-04-27  9:58 ` Thomas Rast
2012-04-27 10:07 ` Jeff King

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).