Search code examples
makefile

Makefiles: What is an order-only prerequisite?


The GNU make manual introduces order-only prerequisites:

target: prerequisite1 prerequisite2 | orderonlyprerequisite1 orderonlyprerequisite2

However, while that manual page gives an example and describes the purpose of order-only prerequisites, at no point does the manual page answer the question in the title: What is an order-only prerequisite?

Can you give a precise definition how order-only prerequisites behave?


Solution

  • First, let's recall what the ordinary prerequisites are.

    Basically, the prerequisites in Makefile have two functions:

    1. They are checked and, if necessary, are built before the target
    2. 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.