Makefiles: What is an order-only prerequisite?
First, let's recall what the ordinary prerequisites are.
Basically, the prerequisites in Makefile have two functions:
- They are checked and, if necessary, are built before the target
- If any of the prerequisites gets rebuilt (or is simply newer than the target) then the target will also be rebuilt.
Now, the order-only prerequisites do item 1, i.e. impose build-order, but not item 2.
Suppose you have a Makefile like this
baby: love
touch $@
love:
touch $@
then make
says,
touch love
touch baby
now you rm love
and again make
say
touch love
touch baby
because in order to make baby you must make love, and every time you make love, you must make baby. However, suppose you don't want to make baby every time you make love. In that case you can use a pipe.
baby: | love
touch $@
now you rm love
and make
says only
touch love
because although in order to make baby you must make love, it is not the case that every time you make love, you must make baby.
I think the documentation does describe how they behave. It describes how a normal prerequisite behaves:
A normal prerequisite makes two statements: first, it imposes an order in which recipes will be invoked: the recipes for all prerequisites of a target will be completed before the recipe for the target is run. Second, it imposes a dependency relationship: if any prerequisite is newer than the target, then the target is considered out-of-date and must be rebuilt.
Then it describes how the behavior of an order-only prerequisite differs from that; it will:
impose a specific ordering on the rules to be invoked without forcing the target to be updated if one of those rules is executed.