Special Dependencies
GNU make has two special features for working with dependencies.
- Library dependencies
A dependency of the form
-lNAMEcauses make to search for a library file whose name is eitherlibNAME.soorlibNAME.ain the standard library directories. This is customizable with the.LIBPATTERNSvariable; see the later section "Macros with Special Handling" for more information.- Order-only prerequisites
When a normal prerequisite of a target is out of date, two things happen. First, the prerequisite (and its prerequisites, recursively) are rebuilt as needed. This imposes an ordering on the building of targets and prerequisites. Second, after the prerequisites are updated, the target itself is rebuilt using the accompanying commands. Normally, both of these are what’s desired.
Sometimes, you just wish to impose an ordering, such that the prerequisites are themselves updated, but the target is not rebuilt by running its rules. Such order-only prerequisites are specified in a dependency line by placing them to the right of a vertical bar or pipe symbol,
|:target: normal-dep1 normal-dep2 | order-dep1 order-dep2 commandDependency lines need not contain both. I.e., you do not have to provide regular dependencies if there are order-only dependencies as well; just place the
|right after the colon.
Here is an annotated example of an order-only dependency:
$ cat Makefile
all: target First target is default, point to real target
prereq0: How to make prereq0 @echo making prereq0 ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access