{"thread":{"id":"32950","subject":"[BUG] Infinite make recursion when configure.ac changes","startedAt":"2013-02-20T08:44:58Z","lastAt":"2013-02-21T07:59:09Z","messageCount":5,"participants":["Stefano Lattarini","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"209897","messageId":"51248D0A.50603@gmail.com","threadId":"32950","inReplyTo":null,"subject":"[BUG] Infinite make recursion when configure.ac changes","fromName":"Stefano Lattarini","fromEmail":"stefano.lattarini@gmail.com","sentAt":"2013-02-20T08:44:58Z","receivedAt":"2013-02-20T08:44:58Z","isPatch":false,"sender":{"key":"stefano.lattarini@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1429199?v=4"},"body":">From a pristine master checkout:\n\n  $ make configure && ./configure make\n  ... # All successfull\n  $ touch configure.ac\n  $ make\n    GEN config.status\n  make[1]: Entering directory `/storage/home/stefano/git/src'\n    GEN config.status\n  make[2]: Entering directory `/storage/home/stefano/git/src'\n    GEN config.status\n  make[3]: Entering directory `/storage/home/stefano/git/src'\n    GEN config.status\n  make[4]: Entering directory `/storage/home/stefano/git/src'\n    GEN config.status\n  make[5]: Entering directory `/storage/home/stefano/git/src'\n    GEN config.status\n  ...\n\nand I have to hit ^C to interrupt that recursion.\n\nThis seems due to the change in commit v1.7.12.4-1-g1226504: the\nissue is still present there, but no longer is in the preceding\ncommit 7e201053 (a.k.a. v1.7.12.4).\n\nI haven't investigated this any further for the moment.\n\nRegards,\n  Stefano\n"},{"id":"209957","messageId":"20130221060401.GC25943@sigill.intra.peff.net","threadId":"32950","inReplyTo":"51248D0A.50603@gmail.com","subject":"Re: [BUG] Infinite make recursion when configure.ac changes","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-02-21T06:04:02Z","receivedAt":"2013-02-21T06:04:02Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 20, 2013 at 09:44:58AM +0100, Stefano Lattarini wrote:\n\n> From a pristine master checkout:\n> \n>   $ make configure && ./configure make\n>   ... # All successfull\n>   $ touch configure.ac\n>   $ make\n>     GEN config.status\n>   make[1]: Entering directory `/storage/home/stefano/git/src'\n>     GEN config.status\n>   make[2]: Entering directory `/storage/home/stefano/git/src'\n>     GEN config.status\n>   make[3]: Entering directory `/storage/home/stefano/git/src'\n>     GEN config.status\n>   make[4]: Entering directory `/storage/home/stefano/git/src'\n>     GEN config.status\n>   make[5]: Entering directory `/storage/home/stefano/git/src'\n>     GEN config.status\n>   ...\n> \n> and I have to hit ^C to interrupt that recursion.\n\nI can easily replicate it here.\n\n> This seems due to the change in commit v1.7.12.4-1-g1226504: the\n> issue is still present there, but no longer is in the preceding\n> commit 7e201053 (a.k.a. v1.7.12.4).\n> \n> I haven't investigated this any further for the moment.\n\nHmm. It looks like config.status depends on configure.ac. So make\nrebuilds config.status, which runs \"make configure\", which includes\n\"config.mak.autogen\", leading \"make\" to think that it should rebuild the\ninclude file to make sure it is up to date. The include file depends on\n\"config.status\", which needs to be rebuilt due to configure.ac, which\nentails running \"make configure\", and so on.\n\nSo the real problem is that make things that \"make configure\" depends on\n\"config.mak.autogen\" being up to date, which isn't true at all; the\nwhole point is to make a new configure script so we can write a new\nconfig.mak.autogen. The simplest thing is to just avoid re-running\n\"make\" to get the configure script; the only thing we are gaining is\nthat we don't have to repeat the build recipe, but we can sneak around\nthat by sticking it in a variable. Something like this seems to work:\n\ndiff --git a/Makefile b/Makefile\nindex 3b2c92c..ee1c0b0 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1871,12 +1871,14 @@ configure: configure.ac GIT-VERSION-FILE\n \tmv $@+ $@\n endif # NO_PYTHON\n \n+CONFIGURE_RECIPE = $(RM) configure configure.ac+ && \\\n+\t\t   sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n+\t\t\tconfigure.ac >configure.ac+ && \\\n+\t\t   autoconf -o configure configure.ac+ && \\\n+\t\t   $(RM) configure.ac+\n+\n configure: configure.ac GIT-VERSION-FILE\n-\t$(QUIET_GEN)$(RM) $@ $<+ && \\\n-\tsed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n-\t    $< > $<+ && \\\n-\tautoconf -o $@ $<+ && \\\n-\t$(RM) $<+\n+\t$(QUIET_GEN)$(CONFIGURE_RECIPE)\n \n ifdef AUTOCONFIGURED\n # We avoid depending on 'configure' here, because it gets rebuilt\n@@ -1885,7 +1887,7 @@ config.status: configure.ac\n # do want to recheck when the platform/environment detection logic\n # changes, hence this depends on configure.ac.\n config.status: configure.ac\n-\t$(QUIET_GEN)$(MAKE) configure && \\\n+\t$(QUIET_GEN)$(CONFIGURE_RECIPE) && \\\n \tif test -f config.status; then \\\n \t  ./config.status --recheck; \\\n \telse \\\n\n-Peff\n"},{"id":"209958","messageId":"7vk3q2w61p.fsf@alter.siamese.dyndns.org","threadId":"32950","inReplyTo":"20130221060401.GC25943@sigill.intra.peff.net","subject":"Re: [BUG] Infinite make recursion when configure.ac changes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-21T06:10:42Z","receivedAt":"2013-02-21T06:10:42Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I can easily replicate it here.\n>\n>> This seems due to the change in commit v1.7.12.4-1-g1226504: the\n>> issue is still present there, but no longer is in the preceding\n>> commit 7e201053 (a.k.a. v1.7.12.4).\n>> \n>> I haven't investigated this any further for the moment.\n>\n> Hmm. It looks like config.status depends on configure.ac. So make\n> rebuilds config.status, which runs \"make configure\", which includes\n> \"config.mak.autogen\", leading \"make\" to think that it should rebuild the\n> include file to make sure it is up to date. The include file depends on\n> \"config.status\", which needs to be rebuilt due to configure.ac, which\n> entails running \"make configure\", and so on.\n\nI noticed this while looking at the other autoconf patch yesterday,\nbut I was otherwise occupied in the evening and did not pursue it\nfurther.  Thanks for looking into it.\n\nThis may be an unrelated issue, but I've always thought that it was\nstrange and extremely unintuitive that running \"make configure\" once\nonly creates config.mak.autogen, while running it once again after\nthat (i.e. while having config.mak.autogen in the tree) seems to run\nthe resulting \"./configure\" as well. Maybe it is just me.\n"},{"id":"209959","messageId":"20130221062614.GA8827@sigill.intra.peff.net","threadId":"32950","inReplyTo":"7vk3q2w61p.fsf@alter.siamese.dyndns.org","subject":"Re: [BUG] Infinite make recursion when configure.ac changes","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-02-21T06:26:14Z","receivedAt":"2013-02-21T06:26:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 20, 2013 at 10:10:42PM -0800, Junio C Hamano wrote:\n\n> I noticed this while looking at the other autoconf patch yesterday,\n> but I was otherwise occupied in the evening and did not pursue it\n> further.  Thanks for looking into it.\n\nHere's the patch with a commit message. I'm pretty sure this is the\nright thing to do. I was tempted to find a way of telling make \"no,\ndon't include config.mak.autogen, but that actually _isn't_ right. It\nmight be defining $(RM) or some other variable that we use in the\nrecipe. By including it inline, we will use whatever is in the current\nconfig.mak.autogen (that we read when we started this make invocation),\nwhich is better than nothing.\n\n> This may be an unrelated issue, but I've always thought that it was\n> strange and extremely unintuitive that running \"make configure\" once\n> only creates config.mak.autogen, while running it once again after\n> that (i.e. while having config.mak.autogen in the tree) seems to run\n> the resulting \"./configure\" as well. Maybe it is just me.\n\nIt's not the \"configure\" target that causes it to run. It's the fact\nthat we include config.mak.autogen, which we then tell make can be\nrebuilt by running ./configure. _But_ we only tell it so if one already\nexists (since otherwise everybody would get automake cruft). This is the\n\"ifdef AUTOCONFIGURED\" you see.\n\nSo I think the rule makes sense. Once you have told the Makefile that\nyou are interested in autoconf (by running configure once), then it\nrebuilds it as necessary, and it should be consistent. You can opt back\nout of it be removing config.mak.autogen.\n\nAnyway, here is the patch to fix the loop.\n\n-- >8 --\nSubject: [PATCH] Makefile: avoid infinite loop on configure.ac change\n\nIf you are using autoconf and change the configure.ac, the\nMakefile will notice that config.status is older than\nconfigure.ac, and will attempt to rebuild and re-run the\nconfigure script to pick up your changes. The first step in\ndoing so is to run \"make configure\". Unfortunately, this\ntries to include config.mak.autogen, which depends on\nconfig.status, which depends on configure.ac; so we must\nrebuild config.status. Which leads to us running \"make\nconfigure\", and so on.\n\nIt's easy to demonstrate with:\n\n  make configure\n  ./configure\n  touch configure.ac\n  make\n\nWe can break this cycle by not re-invoking make to build\n\"configure\", and instead just putting its rules inline into\nour config.status rebuild procedure.  We can avoid a copy by\nfactoring the rules into a make variable.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Makefile | 14 ++++++++------\n 1 file changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 3b2c92c..ee1c0b0 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1871,12 +1871,14 @@ configure: configure.ac GIT-VERSION-FILE\n \tmv $@+ $@\n endif # NO_PYTHON\n \n+CONFIGURE_RECIPE = $(RM) configure configure.ac+ && \\\n+\t\t   sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n+\t\t\tconfigure.ac >configure.ac+ && \\\n+\t\t   autoconf -o configure configure.ac+ && \\\n+\t\t   $(RM) configure.ac+\n+\n configure: configure.ac GIT-VERSION-FILE\n-\t$(QUIET_GEN)$(RM) $@ $<+ && \\\n-\tsed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n-\t    $< > $<+ && \\\n-\tautoconf -o $@ $<+ && \\\n-\t$(RM) $<+\n+\t$(QUIET_GEN)$(CONFIGURE_RECIPE)\n \n ifdef AUTOCONFIGURED\n # We avoid depending on 'configure' here, because it gets rebuilt\n@@ -1885,7 +1887,7 @@ config.status: configure.ac\n # do want to recheck when the platform/environment detection logic\n # changes, hence this depends on configure.ac.\n config.status: configure.ac\n-\t$(QUIET_GEN)$(MAKE) configure && \\\n+\t$(QUIET_GEN)$(CONFIGURE_RECIPE) && \\\n \tif test -f config.status; then \\\n \t  ./config.status --recheck; \\\n \telse \\\n-- \n1.8.1.4.4.g265d2fa\n"},{"id":"209960","messageId":"7vbobew10y.fsf@alter.siamese.dyndns.org","threadId":"32950","inReplyTo":"20130221062614.GA8827@sigill.intra.peff.net","subject":"Re: [BUG] Infinite make recursion when configure.ac changes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-21T07:59:09Z","receivedAt":"2013-02-21T07:59:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Anyway, here is the patch to fix the loop.\n>\n> -- >8 --\n> Subject: [PATCH] Makefile: avoid infinite loop on configure.ac change\n>\n> If you are using autoconf and change the configure.ac, the\n> Makefile will notice that config.status is older than\n> configure.ac, and will attempt to rebuild and re-run the\n> configure script to pick up your changes. The first step in\n> doing so is to run \"make configure\". Unfortunately, this\n> tries to include config.mak.autogen, which depends on\n> config.status, which depends on configure.ac; so we must\n> rebuild config.status. Which leads to us running \"make\n> configure\", and so on.\n>\n> It's easy to demonstrate with:\n>\n>   make configure\n>   ./configure\n>   touch configure.ac\n>   make\n>\n> We can break this cycle by not re-invoking make to build\n> \"configure\", and instead just putting its rules inline into\n> our config.status rebuild procedure.  We can avoid a copy by\n> factoring the rules into a make variable.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n\nThanks.  This needs to go to both v1.8.1.x and v1.8.2.\n\nWill apply.\n\n>  Makefile | 14 ++++++++------\n>  1 file changed, 8 insertions(+), 6 deletions(-)\n>\n> diff --git a/Makefile b/Makefile\n> index 3b2c92c..ee1c0b0 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1871,12 +1871,14 @@ configure: configure.ac GIT-VERSION-FILE\n>  \tmv $@+ $@\n>  endif # NO_PYTHON\n>  \n> +CONFIGURE_RECIPE = $(RM) configure configure.ac+ && \\\n> +\t\t   sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n> +\t\t\tconfigure.ac >configure.ac+ && \\\n> +\t\t   autoconf -o configure configure.ac+ && \\\n> +\t\t   $(RM) configure.ac+\n> +\n>  configure: configure.ac GIT-VERSION-FILE\n> -\t$(QUIET_GEN)$(RM) $@ $<+ && \\\n> -\tsed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n> -\t    $< > $<+ && \\\n> -\tautoconf -o $@ $<+ && \\\n> -\t$(RM) $<+\n> +\t$(QUIET_GEN)$(CONFIGURE_RECIPE)\n>  \n>  ifdef AUTOCONFIGURED\n>  # We avoid depending on 'configure' here, because it gets rebuilt\n> @@ -1885,7 +1887,7 @@ config.status: configure.ac\n>  # do want to recheck when the platform/environment detection logic\n>  # changes, hence this depends on configure.ac.\n>  config.status: configure.ac\n> -\t$(QUIET_GEN)$(MAKE) configure && \\\n> +\t$(QUIET_GEN)$(CONFIGURE_RECIPE) && \\\n>  \tif test -f config.status; then \\\n>  \t  ./config.status --recheck; \\\n>  \telse \\\n"}]}