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?
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:
foo: ; @echo "Hello World"
runs /bin/sh -c 'echo "Hello World"'. It can only be used in a recipe. It will work in any version of make, and with any POSIX shell. Because it invokes a shell, you may need to be concerned with quoting issues, etc. (not in this simple example of course).
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.
However, because info is a make function it is parsed by make before the shell is invoked: that means it can't show shell variables that are set within a recipe; for example:
foo: ; @for i in a b c d; do $(info $$i); done
cannot work; you must use echo here.