Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make: execute 2nd rule only if 1st changed file

Consider the following make workflow, in which I (a) want to be sure to always work on the newest download.zip file, but (b) only run the rest of the workflow when this file changes:

my_output.file: download.zip
    some_expensive_operation

download.zip:
    wget -N http://some.server/download.zip

In this example, wget has got dependency information that make does not have.

If download.zip is present, the rule will never be executed and wget will never check if there is a newer file available.

I can of course make .PHONY: download.zip to have the rule executed every time, by then some_expensive_operation will be executed as well no matter if the file changed or not.

Is there any way to tell make to run the my_output.file rule above only if download.zip actually changed?

like image 488
Michael Schubert Avatar asked Jan 21 '26 15:01

Michael Schubert


1 Answers

Use the force rule trick:

my_output.file: download.zip
        some_expensive_operation

download.zip: FORCE
        wget -N http://some.server/download.zip

FORCE: ;

(or you could declare .PHONY: FORCE if you prefer). This ensures that the recipe for download.zip is always run, but it's not marked phony itself so targets that depend on it won't be rebuilt unless it's changed.

like image 106
MadScientist Avatar answered Jan 24 '26 13:01

MadScientist