0
votes

A makefile is:

all : foo ;


# A 'DEFAULT' special-target, providing a recipe to execute for target 'foo'.
.DEFAULT :
    @echo '$$@ is: "$@"'
    @echo '$$< is: "$<"'



Executing, I get:

$@ is: "foo"
$< is: "foo"


How come here, that $< and $@ expand to the same target?

Remember, that we had here:

  1. A file foo, that Make is executing the recipe for. (Therefore, the expansion for $@ is OK)
  2. The target foo has no prerequisites, at all. (Hence, $< should expand to an empty string).



To make it more absurd, let's try the following makefile:

.DEFAULT :
    @echo '$$< is "$<"'
    @echo '$$@ is "$@"'


Running, we get:

$ make .DEFAULT
$< is ".DEFAULT"
$@ is ".DEFAULT"


Really, can we justify that $< and $@ expand to the same string (.DEFAULT), when the target had no prerequisites at all, to begin with?

1

1 Answers

1
votes

Because foo is an implicit prerequisite of .DEFAULT, and $< will include implicit prerequisites.

The name of the first prerequisite. If the target got its recipe from an implicit rule, this will be the first prerequisite added by the implicit rule (see Implicit Rules).