pedantic nitpickery: difference between "goal" and "target"?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

pedantic nitpickery: difference between "goal" and "target"?

Robert P. J. Day-2

  junior colleague who is just learning make and is going through make
manual asked me the other day (regarding section 2.3 in manual) about
this passage:

"By default, make starts with the first target (not targets whose
names start with ‘.’). This is called the default goal. (Goals are the
targets that make strives ultimately to update ..."

  the question was, "what is the difference between a 'goal' and a
'target'?"

  i wasn't quite sure ... i didn't think there was any substantive
difference. the best i could come up is that targets define what *can*
be invoked, while the goal is the target you're currently *trying* to
update, but that sounded pretty lame.

  is there a better explanation? or am i overthinking this?

rday

--

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                         http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================
Reply | Threaded
Open this post in threaded view
|

Re: pedantic nitpickery: difference between "goal" and "target"?

David
On Sat, 2 Nov 2019 at 22:18, Robert P. J. Day <[hidden email]> wrote:

[...]

> "By default, make starts with the first target (not targets whose
> names start with ‘.’). This is called the default goal. (Goals are the
> targets that make strives ultimately to update ..."
>
> the question was, "what is the difference between a 'goal' and a
> 'target'?"

Not surprised to see this question. I observe that 'goal' and 'target'
are often used interchangeably, and it doesn't really matter.

Personally, I do see a slight distinction between these two terms.
As explained in your quote above: goals are the *ultimate* desired
targets.

For example, in the command 'make foo', foo is the goal.

'make foo' searches for a rule with a target that matches 'foo', and
if it finds one it builds the rule prerequisites and then the rule target
using the associated recipes.

So when 'make' documentation discusses the "default goal",
it's no different to talking about a default target.

Make rules are defined in terms of target: prerequisite.
These targets aren't necessarily goals, if they're not
invoked. Consider 'make clean' as an example. There's only
one goal: "clean". The makefile might contain many other
targets, but they aren't goals for that invocation of 'make'.

This is my take on it:
- rules have targets.
- 'make' has goals and builds them by looking for rules with
  matching targets.

So the difference is subtle and in practice it doesn't really matter.

I notice that 'man make' doesn't contain the word "goal",
it uses [TARGET] in the command line syntax.

Reply | Threaded
Open this post in threaded view
|

Re: pedantic nitpickery: difference between "goal" and "target"?

pacalet
In reply to this post by Robert P. J. Day-2
Le 02/11/2019 à 12:01, Robert P. J. Day a écrit :

>
>   junior colleague who is just learning make and is going through make
> manual asked me the other day (regarding section 2.3 in manual) about
> this passage:
>
> "By default, make starts with the first target (not targets whose
> names start with ‘.’). This is called the default goal. (Goals are the
> targets that make strives ultimately to update ..."
>
>   the question was, "what is the difference between a 'goal' and a
> 'target'?"
>
>   i wasn't quite sure ... i didn't think there was any substantive
> difference. the best i could come up is that targets define what *can*
> be invoked, while the goal is the target you're currently *trying* to
> update, but that sounded pretty lame.
>
>   is there a better explanation? or am i overthinking this?
As far as I understand the make parlance, a "goal" is passed to make on the command line:

    make GOAL1 GOAL2...

It is what we really want, not the intermediate targets that make may also build to reach the goals. If make is invoked without a goal a default one is selected, based on the rules you already know.

Remarks:

* A goal must be a target, else you get an error because make does not know how to reach the goal.
* A target is not necessarily a goal for a given make invocation. Indeed, usually, most targets are not goals.
* Any target can be a goal if make is invoked with this target as the specified goal (or if it is the default goal and make is invoked without a specified goal).

>
> rday
>


--
Renaud Pacalet
Télécom Paris
Campus SophiaTech
450 Route des Chappes, CS 50193
06904 Biot Sophia Antipolis cedex, FRANCE
Tel : +33 (0) 4 9300 8402
Web : http://www.telecom-paris.fr/


signature.asc (849 bytes) Download Attachment