www.delorie.com/gnu/docs/make/make_89.html   search  
 
Buy the book!


GNU make

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.10 The shell Function

The shell function is unlike any other function except the wildcard function (see section The Function wildcard) in that it communicates with the world outside of make.

The shell function performs the same function that backquotes (``') perform in most shells: it does command expansion. This means that it takes an argument that is a shell command and returns the output of the command. The only processing make does on the result, before substituting it into the surrounding text, is to convert each newline or carriage-return / newline pair to a single space. It also removes the trailing (carriage-return and) newline, if it's the last thing in the result.

The commands run by calls to the shell function are run when the function calls are expanded (see section 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 section The Two Flavors of Variables).

Here are some examples of the use of the shell function:

 
contents := $(shell cat foo)

sets contents to the contents of the file `foo', with a space (rather than a newline) separating each line.

 
files := $(shell echo *.c)

sets files to the expansion of `*.c'. Unless make is using a very strange shell, this has the same result as `$(wildcard *.c)'.


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright © 2003   by The Free Software Foundation     Updated Jun 2003  

Please take a moment to fill out this visitor survey
You can help support this site by visiting the advertisers that sponsor it! (only once each, though)