{"thread":{"id":"30347","subject":"Compiling git with -Werror","startedAt":"2012-04-27T09:45:20Z","lastAt":"2012-04-27T10:07:31Z","messageCount":3,"participants":["Michael Haggerty","Thomas Rast","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"190204","messageId":"4F9A6AB0.1050504@alum.mit.edu","threadId":"30347","inReplyTo":null,"subject":"Compiling git with -Werror","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2012-04-27T09:45:20Z","receivedAt":"2012-04-27T09:45:20Z","isPatch":false,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"I like to develop with errors and warnings turned up as strict as \npossible.  For example, I would like to use\n\n     CFLAGS=\"-g -O2 -Wall -Werror -Wdeclaration-after-statement\"\n\nI thought this would be as simple as\n\n     git clean -fdx\n     make configure\n     ./configure CFLAGS=\"-g -O2 -Wall -Werror -Wdeclaration-after-statement\"\n     make\n     # hack\n     make\n     # hack\n     # etc.\n\nbut the \"make\" step results in an error:\n\n> $ make\n>     * new build flags or prefix\n>     CC daemon.o\n> In file included from cache.h:4:0,\n>                  from daemon.c:1:\n> git-compat-util.h:359:0: error: \"strtok_r\" redefined [-Werror]\n> /usr/include/x86_64-linux-gnu/bits/string2.h:1196:0: note: this is the location of the previous definition\n> cc1: all warnings being treated as errors\n> make: *** [daemon.o] Error 1\n\nThe cause of the problem is that the CFLAGS variable is used by \n./configure when it is running its tests, and some of the tests don't \nwork correctly (they produce results that are not correct for the \nplatform) when run with the strict CFLAGS.  For example, in the broken \ncase config.log contains\n\n> configure:4592: cc -o conftest -g -O2 -Wall -Werror -Wdeclaration-after-statement   conftest.c -lc   >&5\n> conftest.c:16:6: error: conflicting types for built-in function 'gettext' [-Werror]\n> cc1: all warnings being treated as errors\n> configure:4592: $? = 1\n> configure: failed program was:\n> | /* confdefs.h */\n> | #define PACKAGE_NAME \"git\"\n> | #define PACKAGE_TARNAME \"git\"\n> | #define PACKAGE_VERSION \"1.7.10.362.g010b2\"\n> | #define PACKAGE_STRING \"git 1.7.10.362.g010b2\"\n> | #define PACKAGE_BUGREPORT \"git@vger.kernel.org\"\n> | #define PACKAGE_URL \"\"\n> | /* end confdefs.h.  */\n> |\n> | /* Override any GCC internal prototype to avoid an error.\n> |    Use char because int might match the return type of a GCC\n> |    builtin and then its argument prototype would still apply.  */\n> | #ifdef __cplusplus\n> | extern \"C\"\n> | #endif\n> | char gettext ();\n> | int\n> | main ()\n> | {\n> | return gettext ();\n> |   ;\n> |   return 0;\n> | }\n> configure:4601: result: no\n\nIt is possible to work around this problem by passing the CFLAGS value \nto make rather than configure:\n\n     git clean -fdx\n     make configure\n     ./configure\n     make CFLAGS=\"-g -O2 -Wall -Werror -Wdeclaration-after-statement\"\n     # hack\n     make CFLAGS=\"-g -O2 -Wall -Werror -Wdeclaration-after-statement\"\n     # hack\n     # etc.\n\nbut it is annoying to need such a long command line for \"make\" (not to \nmention that I run make from the command line, from emacs, etc. and \nwould have to adjust the command line everywhere).  Or the CFLAGS could \nbe put into an environment variable, but this again would have to be set \nup separately (and consistently!) for every terminal and emacs sessions \nthat is in use.\n\nIs there some other mechanism to set strict CFLAGS parameters for the \nbuild without confusing ./configure?\n\nIs this a bug in how the git project is using autoconf?\n\nIs it a bug in autoconf itself?\n\nThanks,\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\n"},{"id":"190205","messageId":"87bomd338q.fsf@thomas.inf.ethz.ch","threadId":"30347","inReplyTo":"4F9A6AB0.1050504@alum.mit.edu","subject":"Re: Compiling git with -Werror","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2012-04-27T09:58:45Z","receivedAt":"2012-04-27T09:58:45Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Michael Haggerty <mhagger@alum.mit.edu> writes:\n\n> Is there some other mechanism to set strict CFLAGS parameters for the\n> build without confusing ./configure?\n\nAs mentioned on IRC, you can put\n\n  CFLAGS = -g -O2 -Wall -Werror -Wdeclaration-after-statement\n\nin config.mak.  The Makefile includes that if it exists, so it is a good\nplace to gather your custom settings.\n\nOne trick I like to do in every Makefile is\n\n  O = 3\n  CFLAGS = -g -O$(O) -Wall <blah>\n\nThat way 'make O=0' does a build suitable for debugging.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"190206","messageId":"20120427100731.GC19918@sigill.intra.peff.net","threadId":"30347","inReplyTo":"4F9A6AB0.1050504@alum.mit.edu","subject":"Re: Compiling git with -Werror","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-04-27T10:07:31Z","receivedAt":"2012-04-27T10:07:31Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Apr 27, 2012 at 11:45:20AM +0200, Michael Haggerty wrote:\n\n> I like to develop with errors and warnings turned up as strict as\n> possible.  For example, I would like to use\n> \n>     CFLAGS=\"-g -O2 -Wall -Werror -Wdeclaration-after-statement\"\n\nThat's more or less how I compile git.\n\n> I thought this would be as simple as\n> \n>     git clean -fdx\n>     make configure\n>     ./configure CFLAGS=\"-g -O2 -Wall -Werror -Wdeclaration-after-statement\"\n\nI don't use our autoconf at all, though. I put settings like that into\nconfig.mak, which gets sourced by the Makefile (right after\nconfig.mak.autogen, which is what configure produces).\n\n> The cause of the problem is that the CFLAGS variable is used by\n> ./configure when it is running its tests, and some of the tests don't\n> work correctly (they produce results that are not correct for the\n> platform) when run with the strict CFLAGS.\n> [...]\n> Is there some other mechanism to set strict CFLAGS parameters for the\n> build without confusing ./configure?\n\nTry putting \"CFLAGS += -Werror\" in config.mak.\n\n> Is this a bug in how the git project is using autoconf?\n> \n> Is it a bug in autoconf itself?\n\nI think autoconf. Our configure input is just using\nAC_CHECK_FUNC(strtok_r) to generate the test.  Which would mean that\nit's a bad interaction of autoconf's code and your CFLAGS. So I would be\nsurprised if other packages didn't have similar problems.\n\nAnd indeed, googling for 'autoconf cflags \"-Werror\"' turns up:\n\n  http://lists.gnu.org/archive/html/bug-autoconf/2012-03/msg00070.html\n\nSummary: don't do that. We could add a special option to turn on\nwarnings, but given how easy the config.mak trick above is, I don't know\nthat it's necessary.\n\n-Peff\n"}]}