What is the difference between these two commands in makefiles:
@echo "Hello World"
$(info Hello World)
As it seems, echo
and info
print the same output, so where is the difference? And when to use which one?
Well, echo
is a shell command. So if you put it in a recipe, a shell will be invoked to run it and the shell command will generate the output:
info
is a GNU make function. It is handled directly by make: no shell is invoked. It can appear anywhere in a makefile, not just in a recipe. It is not portable to other versions of make. Because no shell is invoked, there are no quoting issues.
How to print out a variable in makefile
As per the GNU Make manual and also pointed by 'bobbogo' in the below answer, you can use info / warning / error to display text.
$(error text…)
$(warning text…)
$(info text…)
To print variables,
$(error VAR is $(VAR))
$(warning VAR is $(VAR))
$(info VAR is $(VAR))
'error' would stop the make execution, after showing the error string