Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefiles: What is an order-only prerequisite?

Tags:

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?

like image 623
shuhalo Avatar asked Sep 21 '19 11:09

shuhalo


People also ask

What are prerequisites in makefile?

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.

Does order matter in Makefiles?

The order of rules is not significant, except for determining the default goal : the target for make to consider, if you do not otherwise specify one. The default goal is the target of the first rule in the first makefile. If the first rule has multiple targets, only the first target is taken as the default.

What is $@ in makefile?

The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.

What are dependencies in makefiles?

A dependency is a file that is used as input to create the target. A target often depends on several files. A command is an action that make carries out. A rule may have more than one command, each on its own line.


Video Answer


1 Answers

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 1., i.e. impose build-order, but not 2.

like image 54
Matt Avatar answered Oct 17 '22 20:10

Matt