Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU make empty recipe vs. no recipe

Tags:

Looking at the GNU make manual, what exactly is the difference between an empty recipe and no recipe (for example see one instance in Rules without Recipes or Prerequisites)? More importantly, when should one use/avoid each of these two recipes?

In my current understanding, one should always use

target: ;

because sometimes an implicit rule could defeat one's purpose of no rule.

like image 219
green diod Avatar asked Dec 08 '16 14:12

green diod


People also ask

What is the difference between make and make all?

A simple make will build the first target in the list, which is put-files . make all will build the target all . If you want all to be the default, then move it to the top of the list.

What are rules in makefiles?

A rule appears in the makefile and says when and how to remake certain files, called the rule's targets (most often only one per rule). It lists the other files that are the dependencies of the target, and commands to use to create or update the target.

What is $@ and in makefile?

From make manpage: $@ is: The file name of the target of the rule. If the target is an archive member, then '$@' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), '$@' is the name of whichever target caused the rule's recipe to be run.


1 Answers

A given target can have only one recipe. If you declare an empty recipe then you've now given that target that recipe and it won't be searched for via implicit rules. Also if you try to give that same target another recipe, then make will complain.

"No recipe" just means you're adding more prerequisites to an existing target or, if you don't list prerequisites, you're just informing make that this is a target you're interested in. But you're not overriding any recipe lookup that make will do elsewhere.

It's definitely not true that one should always use one or the other: the one you use depends on what you're trying to achieve.

I don't know what you mean when you say defeat one's purpose of no rule so I can't respond to that... what are you trying to achieve when you say "no rule"?

like image 98
MadScientist Avatar answered Oct 13 '22 21:10

MadScientist