The wildcard and PATSUBST functions in Makefile

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.