YannDubois
YannDubois

Reputation: 11

Makefile : get the command output and use it in a rule

My command get the dependencies of a file passed in parameter and now, I want use it like dependencies into Makefile. I do somethink like :

%.dep: %.txt
./mycommand filedepend ${<} > $@

#Tex compilation
$(OUTPUTDIRECTORY)/%.tex.json: %.txt %.dep $(eval $(shell cat %.dep))
    ./mycommand export --to="latex" --path="${<}" $<
    rm $*.dep

It doesn't work, the result of the rule should be like :

$(OUTPUTDIRECTORY)/%.tex.json: %.txt %.dep foo.txt bar.txt
    ./mycommand export --to="latex" --path="${<}" $<
    rm $*.dep

but for independant file (I want one rule for all files)

Upvotes: 1

Views: 1086

Answers (1)

Wurmloch
Wurmloch

Reputation: 529

You could generate your dependency files in such a way they contain:

$(OUTPUTDIRECTORY)/%.tex.json: foo.txt bar.txt

instead of only

foo.txt bar.txt

and then include the dependency files with:

-include %.dep

The minus is for ignoring the initial include error when the dependency file not yet exists. You can try what happens when you omit it, it shall also work.

Complete example, not tested, maybe i'm missing something, but basically this should work:

 -include %.dep
 %.dep: %.txt
    ./mycommand filedepend ${<} > $@   # <-- this must generate the dep file in the correct format


#Tex compilation
$(OUTPUTDIRECTORY)/%.tex.json: %.txt %.dep
    ./mycommand export --to="latex" --path="${<}" $<
    rm $*.dep

This is a good source explaining auto dependency generation using gcc, just replace gcc by your custom dependency generator: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

Upvotes: 1

Related Questions