views:

32

answers:

2

One sign is that target does not exist, understand this.

Another is by comparing modification timestamp of target and prerequisites. How it works in more details? What is the logic of comparing target and prerequisite timestamps and how it works when there are multiple prerequisites?

A: 

Unix make has pretty complicated inference rules to determine if the target needs to be rebuilt. For GNU make you can dump them by running 'make -p' in a directory that doesn't have a Makefile.

Also the rules could be chained, more explanation about it is here

Standard Unix make and Microsoft nmake work in similar fashion

Vlad
+2  A: 

make first gets the modification time of the target, then compares that value to the modification time of each prereq, in order from left to right, stopping as soon as it finds any prereq that is newer than the target (since a single newer prereq is sufficient to require the target be rebuilt).

For example, suppose you have a rule like this:

foo: bar baz boo

Further, suppose that the modification times on these files are as follows:

foo: 4
bar: 3
baz: 6
boo: 2

In this case, make will compare the modification time of foo (4) to the modification time of bar (3); since bar is older, make will move on and compare the modification time of foo (4) to the modification time of baz (6). Since baz is newer, make will decide that foo must be rebuilt, and will stop checking the prereqs of foo (so boo will never be checked).

If you have multiple dependency lines for the output target, as in:

foo: bar baz
foo: boo

The prereqs in the second and subsequent dependency lines are simply appended to the end of the list of prereqs for the output target -- that is, this example is exactly equivalent to the first example above.

In general, all make variants behave this way, although some variants have extensions that modify this behavior (for example, GNU make includes order-only prerequisites; Sun make has "keep state" features; etc).

Eric Melski