user1759572
user1759572

Reputation: 683

Makefile dependency by file content, which might not exist

I am having a problem creating Makefile build that has dependency of some other file content.

I know that I can write something like that in makefile to generate prerequisites on-the-fly:

result/nuclease.stat : $(shell cat config/nuclease.sample.list)

#bash
make result/nuclease.stat

But the problem is that the file config/nuclease.sample.list might not exist and I have a target for it.

If I could force make to require config/nuclease.sample.list before $(shell cat config/nuclease.sample.list) gets evaluated - problem is solved.

What kind of dependency I should make?

One more thing, I would like keep all gnu make's good qualities: download files only once, process them only once and etc..

Please check Makefile dependency tree

Upvotes: 1

Views: 929

Answers (1)

MadScientist
MadScientist

Reputation: 100781

The most straightforward answer is to use constructed include files. In this method you'd include a makefile that defined the dependency relationships you wanted, and provide a make rule that generated that included file with the information you want. That's all you have to do: make knows how to do the rest. Based on your question it might be something like:

include nuclease-sample-list.mk

nuclease-sample-list.mk: config/nuclease.sample.list
        echo "result/nuclease.stat : $$(cat $<)" > $@

That's all you have to do. If you're using an older version of GNU make you might need to use -include instead of include to avoid seeing warning messages.

Upvotes: 5

Related Questions