Search code examples
makefilegnu-make

With a rule's prerequisite both a file and another rule, is only the file date checked, or always first that "sub rule" itself?


Considering the general rule form:

output_file_name: dep_file_name1, dep_file_name_2, ..., dep_file_name_n
    recipe

and assuming in one's hypothetical makefile with no phony targets ever, every dep_file_name_x is always a file name and often also another rule (ie. it is another rule's output_file_name), my question is:

Hitting any of many such rules, does make only check the file-mod-time of the dep_file_name_x file (if it exists of course) or does make also recognize that dep_file_name_x is also a another rule in the same makefile — which, if "run" (but maybe hasn't yet), would update the actual file?

More briefly: if the dep_file_name_x refers to an existing rule and an existing file, is it guaranteed the rule is invoked (with its own prereq checks etc) before the usual file-mod-time checking?


Solution

  • Make works recursively. Every prerequisite is treated as a target and goes through the entire process of bringing that target up to date. It doesn't matter if there's a file on the disk for that target or not (except insofar as how it effects make's decision on whether to update it). It doesn't even matter if there's a rule for the target or not (if not make will try to match an implicit rule).

    But yes, if I understand your question correctly, make will always completely attempt to rebuild all prerequisites and wait for them to complete, before checking timestamps to see if the current target needs to be updated.