Maxim Blumental
Maxim Blumental

Reputation: 743

Redirection of output in shell script lines in Makefiles

I'm trying to figure out what one specific line in a makefile is doing:

foo: smth_foo_depends_on
    ...
    @echo $< | bar >> $@
    ...

In particular I'd like to know:

Thanks!

Upvotes: 2

Views: 1659

Answers (1)

Eugeniu Rosca
Eugeniu Rosca

Reputation: 5315

Why do we write @ before echo?

Source: It is done to suppress the echoing for one specific line in the recipe.

What does $< mean?

Source: $< is the name of the first prerequisite (i.e. smth_foo_depends_on)

Why do we output something in $@ which, as far as I know, is the list of arguments given to the script? Why do we modify it?

Source: In makefile language, $@ is the name of the current target (i.e. foo). Do not confuse it with the shell list of positional parameters. The recipe line echo $< | bar >> $@ is expanded to:

echo smth_foo_depends_on | bar >> foo

Upvotes: 4

Related Questions