{"thread":{"id":"7116","subject":"[PATCH] Makefile: do not optimize when DEBUG=1","startedAt":"2007-03-06T21:50:19Z","lastAt":"2007-03-07T18:01:14Z","messageCount":5,"participants":["Johannes Schindelin","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"36474","messageId":"Pine.LNX.4.63.0703062249540.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7116","inReplyTo":null,"subject":"[PATCH] Makefile: do not optimize when DEBUG=1","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-03-06T21:50:19Z","receivedAt":"2007-03-06T21:50:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThere is this wonderful debugger named gdb, which sometimes has severe\nproblems when the source is compiled with optimization. So, you have to\nrecompile (at least parts of the source) _without_ -O2 if you want to\nhave a chance to look at otherwise optimized-out variables.\n\nYou can do that now by removing just the object files containing the\ncode you want to debug, and saying \"make DEBUG=1\".\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n Makefile |    7 ++++++-\n 1 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex c3d67af..18fdc5e 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -110,6 +110,8 @@ all::\n # Define NO_PERL_MAKEMAKER if you cannot use Makefiles generated by perl's\n # MakeMaker (e.g. using ActiveState under Cygwin).\n #\n+# Define DEBUG=1 to compile without optimization.\n+#\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -123,7 +125,10 @@ uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')\n \n # CFLAGS and LDFLAGS are for the users to override from the command line.\n \n-CFLAGS = -g -O2 -Wall\n+CFLAGS = -g -Wall\n+ifndef DEBUG\n+\tCFLAGS += -O2\n+endif\n LDFLAGS =\n ALL_CFLAGS = $(CFLAGS)\n ALL_LDFLAGS = $(LDFLAGS)\n-- \n1.5.0.3.2559.g30d3b\n"},{"id":"36539","messageId":"45EE854E.210EDAFF@eudaptics.com","threadId":"7116","inReplyTo":"Pine.LNX.4.63.0703062249540.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Makefile: do not optimize when DEBUG=1","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-03-07T09:26:38Z","receivedAt":"2007-03-07T09:26:38Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin wrote:\n> You can do that now by removing just the object files containing the\n> code you want to debug, and saying \"make DEBUG=1\".\n> [...]\n> -CFLAGS = -g -O2 -Wall\n> +CFLAGS = -g -Wall\n> +ifndef DEBUG\n> +       CFLAGS += -O2\n> +endif\n\nI think the shortcut to remove just the interesting object file does not\nwork because Makefile notices (the GIT-CFLAGS rule) that there are \"new\nflags or prefix\", and so recompiles everything.\n\n-- Hannes\n"},{"id":"36546","messageId":"Pine.LNX.4.63.0703071319520.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7116","inReplyTo":"45EE854E.210EDAFF@eudaptics.com","subject":"Re: [PATCH] Makefile: do not optimize when DEBUG=1","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-03-07T12:37:15Z","receivedAt":"2007-03-07T12:37:15Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 7 Mar 2007, Johannes Sixt wrote:\n\n> Johannes Schindelin wrote:\n> > You can do that now by removing just the object files containing the\n> > code you want to debug, and saying \"make DEBUG=1\".\n> > [...]\n> > -CFLAGS = -g -O2 -Wall\n> > +CFLAGS = -g -Wall\n> > +ifndef DEBUG\n> > +       CFLAGS += -O2\n> > +endif\n> \n> I think the shortcut to remove just the interesting object file does not \n> work because Makefile notices (the GIT-CFLAGS rule) that there are \"new \n> flags or prefix\", and so recompiles everything.\n\nThat is unfortunatley true, and was hidden in my test by something \ncompletely unrelated.\n\nI do something completely different now:\n\n@@ -846,7 +841,8 @@ TRACK_CFLAGS = $(subst ','\\'',$(ALL_CFLAGS)):\\\n \n GIT-CFLAGS: .FORCE-GIT-CFLAGS\n \t@FLAGS='$(TRACK_CFLAGS)'; \\\n-\t    if test x\"$$FLAGS\" != x\"`cat GIT-CFLAGS 2>/dev/null`\" ; then \\\n+\t    if test x\"$$FLAGS\" != x\"`cat GIT-CFLAGS 2>/dev/null`\" -a \\\n+\t\t    -z \"$(IGNORE_GIT_CFLAGS)\"; then \\\n \t\techo 1>&2 \"    * new build flags or prefix\"; \\\n \t\techo \"$$FLAGS\" >GIT-CFLAGS; \\\n             fi\n\n... and in my config.mak, there is\n\nifdef DEBUG\n\tALL_CFLAGS := $(filter-out -O2,$(ALL_CFLAGS))\n\tIGNORE_GIT_CFLAGS = YesPlease\nendif\n\nI'm happy now.\n\nCiao,\nDscho\n"},{"id":"36547","messageId":"45EEC122.EA43CB72@eudaptics.com","threadId":"7116","inReplyTo":"Pine.LNX.4.63.0703071319520.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"[PATCH] Avoid rebuilding everything if user changes CFLAGS on the make command line","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-03-07T13:41:54Z","receivedAt":"2007-03-07T13:41:54Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"From: Johannes Sixt <johannes.sixt@telecom.at>\n\nThe following sequence of commands is commonly used to recompile\nselected files with different flags, for example, to change the debug\ninformation:\n\n   make\n   rm builtin-diff.o\n   make CFLAGS=\"-g -O0\"\n\nHowever, the Makefile is clever enough to notice that the second 'make'\ninvocation changes the build flags and rebuilds everything.\n\nThis change exempts the value of CFLAGS (which is explicitly declared\nas reserved for the user to change from the command line) from this\nauto-detection.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\nJohannes Schindelin wrote:\n>  GIT-CFLAGS: .FORCE-GIT-CFLAGS\n>         @FLAGS='$(TRACK_CFLAGS)'; \\\n> -           if test x\"$$FLAGS\" != x\"`cat GIT-CFLAGS 2>/dev/null`\" ; then \\\n> +           if test x\"$$FLAGS\" != x\"`cat GIT-CFLAGS 2>/dev/null`\" -a \\\n> +                   -z \"$(IGNORE_GIT_CFLAGS)\"; then \\\n>                 echo 1>&2 \"    * new build flags or prefix\"; \\\n>                 echo \"$$FLAGS\" >GIT-CFLAGS; \\\n>              fi\n\nIMHO, the value of $(CFLAGS) (which the Makefile declares as \"for the\nusers to override from the command line\") should never take part in this\nbuild-flags-change-autodetection.\n\n-- Hannes\n\n Makefile |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 9a37b15..8410530 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -812,7 +812,7 @@ tags:\n \tfind . -name '*.[hcS]' -print | xargs ctags -a\n \n ### Detect prefix changes\n-TRACK_CFLAGS = $(subst ','\\'',$(ALL_CFLAGS)):\\\n+TRACK_CFLAGS = $(subst ','\\'',$(BASIC_CFLAGS)):\\\n             \n$(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)\n \n GIT-CFLAGS: .FORCE-GIT-CFLAGS\n-- \n1.5.0.2.279.g4808\n"},{"id":"36563","messageId":"7vd53lexw5.fsf@assigned-by-dhcp.cox.net","threadId":"7116","inReplyTo":"45EEC122.EA43CB72@eudaptics.com","subject":"Re: [PATCH] Avoid rebuilding everything if user changes CFLAGS on the make command line","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-07T18:01:14Z","receivedAt":"2007-03-07T18:01:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <J.Sixt@eudaptics.com> writes:\n\n> IMHO, the value of $(CFLAGS) (which the Makefile declares as \"for the\n> users to override from the command line\") should never take part in this\n> build-flags-change-autodetection.\n\nThis on the surface looks nicer than the other Johannes's\napproach, but I have reservations.  The user can always say\n\"make CFLAGS=-DNO_SYNLINK_HEAD=NoThanks\" from the command line\nto affect the behaviour, and in such a case this approach\nbreaks.\n\nAs long as you declare CFLAGS is there for users to override\nonly the way the programs are compiled (e.g. optimization) and\nit is forbidden to use CFLAGS to affect the way the programs are\nto behave (iow, \"use of -D<FEATURE> in CFLAGS is forbidden\"), it\nwould be Ok, but in effect it is forcing people to modify\nconfig.mak even for \"try out this configuration just this time,\none-shot\" compilation, which makes me somewhat unhappy.\n\nIGNORE_GIT_CFLAGS looks much uglier, but is much nicer from\ndesign standpoint.  At least the user declares \"I know what I am\ndoing, and I assume full responsibility\".  That might be less\nconfusing in the end.\n\nUndecided.\n"}]}