git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Makefile: abort on shells that do not support ${parameter%word} expansion

From
BCBrandon Casey <brandon.casey.ctr@nrlssc.navy.mil>
Date
Sep 6, 2011, 20:30 UTC
Message-ID
<4KpnoijSRGBLoF4pZj7c1eShQRupu7h-gkSjM2Ej6nnefH-n7qWuAkoY4CEocEsJb6XCaqhrtHT3uQL2W3DKu0yJ1rAh-UxeXocbOTvMhBw@cipher.nrlssc.navy.mil>
In-Reply-To
<2i2CfjMHrXZ7dV7ciebqx3PjO-cpw8QIplKjdcx_bGmGt8jgFr3efDXeMJMcn_I9ZH6X71aBdaO7vGiRBQuhbukGEWFJZQuvWtq079u0KYQ@cipher.nrlssc.navy.mil>
On 09/06/2011 02:32 PM, Brandon Casey wrote:
Show 13 quoted lines
> 
> FYI:
> It should be possible to test this patch on a modern system by doing
> something like:
> 
>    make SHELL_PATH=/bin/false
> 
> and you should see something like this:
> 
>    make: *** [please_set_SHELL_PATH_to_a_more_modern_shell] Error 1
> 
> But beware, GNU make 3.81 seems to have a bug which sends it into an
> infinite loop.

Just a clarification, I didn't mean you'd actually be able to test the patch for correctness, but the above would at least allow you to stress the code path.

But, with the Makefile in its current form (patch or no patch) the above still works. Setting SHELL_PATH=/bin/false produces the desired error message.

There still appears to be a bug in make 3.81 which is triggered when using an ancient shell, it just manifests itself in a different way using our current Makefile. Right now, make 3.81 will enter an infinite loop when it tries to include the GIT-VERSION-FILE. When something like /bin/sh on Solaris processes the GIT-VERSION-GEN script, it produces the following incorrect string in the GIT-VERSION-FILE:

   GIT_VERSION = $(expr $(echo $(git describe --match v[0-9]* --abbrev=4 HEAD 2>/dev/null) | sed -e s/-/./g) : v*\(.*\))

which then becomes part of the Makefile when GIT-VERSION-FILE is included on line 264. GNU make then begins to print the following to the terminal repeatedly:

   GIT_VERSION = $(expr $(echo $(git describe --match v[0-9]* --abbrev=4 HEAD 2>/dev/null) | sed -e s/-/./g) : v*\(.*\))

GIT-VERSION-FILE should really have a dependency on shell_compatibility_test since it calls GIT-VERSION-GEN which may use shell features that are not provided by the configured shell. If that dependency is added so that the GIT-VERSION-FILE rule looks like this:

   GIT-VERSION-FILE: shell_compatibility_test FORCE
   	@$(SHELL_PATH) ./GIT-VERSION-GEN
   -include GIT-VERSION-FILE
_then_, we get the behavior I described originally, where
   make SHELL_PATH=/bin/false

sends the make process into an infinite loop, with no output to the terminal.

Either way, with GNU make 3.81, you get an infinite loop when you use a shell that should trigger our error message.

-Brandon
Previous: Brandon CaseyNext: Junio C Hamano
Message 15 of 19 in “shell portability: Use sed instead of non-portable variable expansion”
  1. shell portability: Use sed instead of non-portable variable expansionNaohiro Aota, Sep 5, 2011
  2. Johannes SixtSep 5, 2011
  3. Junio C HamanoSep 5, 2011
  4. Johannes SixtSep 5, 2011
  5. Junio C HamanoSep 5, 2011
  6. Johannes SixtSep 5, 2011
  7. Johannes SixtSep 5, 2011
  8. Naohiro AotaSep 5, 2011
  9. Junio C HamanoSep 5, 2011
  10. Johannes SixtSep 5, 2011
  11. Junio C HamanoSep 5, 2011
  12. Junio C HamanoSep 5, 2011
  13. Makefile: abort on shells that do not support ${parameter%word} expansionBrandon Casey, Sep 6, 2011
  14. Brandon CaseySep 6, 2011
  15. Brandon CaseySep 6, 2011
  16. Junio C HamanoSep 6, 2011
  17. Brandon CaseySep 6, 2011
  18. Junio C HamanoSep 6, 2011
  19. Brandon CaseySep 6, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.