GNU make empty recipe vs. no recipe
Asked Answered
H

1

7

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.

Humbug answered 8/12, 2016 at 14:29 Comment(0)
A
5

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"?

Analphabetic answered 8/12, 2016 at 18:31 Comment(2)
I said, in my current understanding ;) If I'm not mistaken, it's on your website's post about make.mad-scientist.net/papers/… that I saw another example. In .d files, you would add an automatically generated prerequisite as a new target with no recipe (and a %.d target with an empty recipe). But actually, in that particular case, .h files happen to have no implicit rule. But in other cases, maybe that would trigger some implicit rule that I can prevent with an explicit empty recipe?Humbug
Sure, maybe. I'm not sure I understand the question.Analphabetic

© 2022 - 2024 — McMap. All rights reserved.