Hi Konrad, > Trying to understand a bug in my Makefile, I consulted the manual > section on chained rules > (https://www.gnu.org/software/make/manual/html_node/Chained-Rules.html#Chained-Rules) > and found the following paragraph, which is more confusing than > helpful:
>> The first difference is what happens if the intermediate file does >> not exist. If an ordinary file b does not exist, and make considers a >> target that depends on b, it invariably creates b and then updates >> the target from b. But if b is an intermediate file, then make can >> leave well enough alone. It won’t bother updating b, or the ultimate >> target, unless some prerequisite of b is newer than that target or >> there is some other reason to update that target. > The whole paragraph is about the case of an intermediate file that > does not exist. But then there are references to updating the file - > you cannot update a non-existing file! The non-existing file is b. The target that gets updated is the file that depends on b. The manual doesn't claim that non-existent b gets updated (although it may be transiently created in order to update the target), it says that the target gets updated. > Also, "make can leave well enough alone" sounds more like the > description of a person having a bad day than of a deterministically > running computer program. > > Unfortunately, I cannot propose a better formulation because I don't > know how Make deals with this case - I really need the manual to help > me out! See if this is any clearer: target: b .INTERMEDIATE: b b: other stuff command -o b other stuff If target exists and is newer than the other stuff, the absence of b does not trigger a rebuild of (b and thus) target; i.e. "make can leave well enough alone", because there is no need to update target. If any of the other stuff is newer than target, or is itself out of date with respect to its own prerequisites, make will (update other stuff as needed, ...) recreate b from other stuff, update target and tidy away b (because it's intermediate). If b were not intermediate, its absence would always force its recreation and an update to target. Eddy.