|
From: | John Calcote |
Subject: | Re: How does make compare the timestamp if the file does not exist |
Date: | Mon, 13 Jul 2009 21:39:22 -0600 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b3pre) Gecko/20090223 Thunderbird/3.0b2 |
Hello, On 7/13/2009 8:51 PM, 雷 高 wrote: If a file doesn't exist, it's considered "out of date" and is thus rebuilt, just as you surmised. Make builds a dependency tree based on the rules in the makefile. It then traverses the dependency tree, starting with the first target listed in the makefile (in this case, foo). It processes the tree in a depth-first manner, not actually executing any commands until it finds the first dependency in the traversal that doesn't have any of its own dependencies. If any of the current node's (zero or more) dependencies are newer than the target, or if the target is missing (or declared "phony"), then make runs its commands and moves to the next node along the traversal path. It continues in this manner until it has returned to the original node. This is why you see "boo" first, followed by "foo" on your screen, when you execute make. The commands for the leaf nodes are executed before those of higher level nodes in order to ensure that dependencies are built before targets that need those files. When you don't actually build a target with a rule's commands (as in your example), then make processes higher-level targets, as if their dependencies were actually built. The comparison timestamp for those dependencies becomes "now", even if the files don't exist after their commands are executed. And "now" is always newer than a non-existent file. If the current target actually does exist, then "now" is still going to be newer than any timestamp on that file, so it will be rebuilt. Regards, John |
[Prev in Thread] | Current Thread | [Next in Thread] |