开发者

How make decides to build target

开发者 https://www.devze.com 2022-12-28 20:37 出处:网络
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 targe

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 p开发者_StackOverflowrerequisites?


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).


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

0

精彩评论

暂无评论...
验证码 换一张
取 消