Function wildcard
In the rule, the wildcard is automatically expanded. However, when defining variables and referencing functions, wildcards will become invalid. In this case, if the wildcard is required to be valid, you need to use the Function
"Wildcard", which is used: $ (wildcard pattern ...)
. In makefile, it is expanded into a list of all existing files that are separated by spaces and match this mode. If no file meets this mode, the function ignores the mode character and returns
Null. Note: In this case, the expansion of the wildcard in the rule is different from that in the previous section that matches the wildcard.
Generally, we can use "$ (wildcard
*. C) to obtain the list of all. c files in the working directory. Complex usage; you can use "$ (patsubst %. C, %. O, $ (wildcard
*. C) ", first use the" wildcard "function to obtain the. c file list in the working directory, and then replace the suffix. C of all file names in the list with. O. In this way, we can obtain
Directory. Therefore, you can use makefile of the following content in a directory to compile all. c files in the working directory and connect them to an executable file:
# Sample makefile
Objects: = $ (patsubst %. C, %. O, $ (wildcard *. c ))
Foo: $ (objects)
CC-O Foo $ (objects)