Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Make to build files that are outdated AND newer than a certain timestamp

I am using GNU Make 3.81 for building a given C project. The normal behavior of GNU is to check, if the target exists and any prerequisite is newer than the target, the target commands are executed.

Is it possible to rebuild the target if the prerequisites are newer than the target AND newer than a given timestamp? Lets say, that it builds only if the files are newer than Oct 2, 2011, for example.

like image 275
Pedro Perez Avatar asked Nov 05 '22 05:11

Pedro Perez


1 Answers

There's no way to do it directly with make, but you could do it with the shell in the action for the rule:

target: prereq
        touch --date='Oct 2, 2011' .timestamp
        if [ $< -nt .timestamp ]; then         \
            command to rebuild target;        \
        fi

Note the use of \ to make the if command a single command. You could also use an else to deal with the case where the target is out of date and the prereq is also old.

like image 185
Chris Dodd Avatar answered Nov 15 '22 06:11

Chris Dodd