shell function is unlike any other function other than the
(see The Function
wildcard) in that it
communicates with the world outside of
shell function performs the same function that backquotes
(‘`’) perform in most shells: it does command expansion.
This means that it takes as an argument a shell command and evaluates
to the output of the command. The only processing
make does on
the result is to convert each newline (or carriage-return / newline
pair) to a single space. If there is a trailing (carriage-return
and) newline it will simply be removed.
The commands run by calls to the
shell function are run when the
function calls are expanded (see How
make Reads a Makefile). Because this function involves
spawning a new shell, you should carefully consider the performance
implications of using the
shell function within recursively
expanded variables vs. simply expanded variables (see The Two Flavors of Variables).
Here are some examples of the use of the
contents := $(shell cat foo)
contents to the contents of the file foo, with a space
(rather than a newline) separating each line.
files := $(shell echo *.c)
files to the expansion of ‘*.c’. Unless
using a very strange shell, this has the same result as
‘$(wildcard *.c)’ (as long as at least one ‘.c’ file