On Sat, 2020-12-12 at 23:40 -0500, Stefan Monnier wrote: > I expect the `%` which appears within the $(shell..) to be replaced > with the target's stem, but tests indicate that obviously this is not > how it works. I think this is related to what the manual says: > > Note that expansion using '%' in pattern rules occurs *after* any > variable or function expansions, which take place when the makefile is > read. *Note How to Use Variables: Using Variables, and *note Functions > for Transforming Text: Functions.
Yes, exactly. When this $(shell ...) function is run it uses the literal value '%', because make cannot know what the pattern replacement will be when it's reading in the makefile. > But I don't know how to work around that. There are a variety of ways but one simple one is secondary expansion: https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html .SECONDEXPANSION: packages/%.tar.gz : $$(shell find packages/% -name '*.el' -print | sed 's/\.el/.elc/') tar -zcf packages/$*.tar.gz packages/$* (note, untested)
