make: Shell Function

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