Get a target's prerequisites from an external script?

"Sean Hammond" <[email protected]>
Newsgroups gmane.comp.gnu.make.general
Message-ID <[email protected]>
Is it possible to generate the list of prerequisites for a class of targets from an external command?

For example Python requirements.txt files (of the type compiled by pip-compile [1]) can import other requirements files with lines like "-r other.txt" or "-c other.txt". I'm no UNIX wizard but it seems easy to get a list of the other requirements files that a given requirements file (foo.txt in this example) depends on with a command like:

    grep --color=never '^[[:blank:]]*-r\|^[[:blank:]]*-c' foo.in | sed 's/^[[:blank:]]*\(-r\|-c\)[[:blank:]]*//'

I want to get my Makefile to use this command to automatically figure out the prerequisites of any requirements/*.txt file. This is what I tried:

    requirements/%.txt: requirements/$(shell grep --color=never '^[[:blank:]]*-r\|^[[:blank:]]*-c' requirements/%.in | sed 's/^[[:blank:]]*\(-r\|-c\)[[:blank:]]*//')

But it doesn't work:

    grep: %.in: No such file or directory

It seems that make didn't expand the % within the $(shell ...) command.

I couldn't find a way to get this to work. Is it possible?

Thanks

[1]: https://pip-tools.readthedocs.io/ <https://pip-tools.readthedocs.io/en/latest/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.