the wildcard and PATSUBST functions in Makefile
The function in makefile is very similar to its variable-when used, you use a $ symbol followed by parentheses, a function name, a space followed by a comma-delimited argument, and the end of the closing parenthesis. For example, in GNU make there is a function called ' wildcard ', which has a parameter that expands into a column of all the file names that conform to their parameters, separated by a space between the files. You can use this command as shown below:
SOURCES = $ (wildcard *.c)
This line produces a list of all files that end with '. C ' and is then stored in the variable SOURCES. Of course you don't have to put the result into a variable.
Another useful function is the Patsubst (Patten substitude, matching substitution abbreviation) function. It requires 3 parameters-the first is a design that needs to be matched, the second indicates what to replace it, and the third is a space-delimited column that needs to be processed. For example, to process the variable that was defined above,
OBJS = $ (patsubst%.c,%.o,$ (SOURCES))
This will process all the words in the SOURCES column (a list of filenames), and if it ends with '. C ', use '. O ' to replace '. C '. Note that the% symbol here will match one or more characters, and each time it matches a string called a ' handle ' (STEM). In the second argument,% is interpreted as the handle that matches the first parameter.
Reprinted from: http://blogold.chinaunix.net/u/6889/showart_461187.html