Summary of using patsubst and wildcard functions in a Makefile.
In the makefile, the functions patsubst and wildcard are very useful for pattern matching and replacing file names.
- wildcard function
- Syntax: $(wildcard pattern)
- Function: used to search for files with a specified pattern and return a list of files that match the pattern.
- SRC := $(wildcard *.c) # Get a list of all files ending in .c in the current directory
OBJ := $(patsubst %.c, %.o, $(SRC)) # Replace the .c files in SRC with .o files - The patsubst function helps to substitute text in a Native language.
- Syntax: $(patsubst pattern,replacement,text)
- Function: used to replace specified patterns in the text with specified content.
- SRC includes main.c and utils.c # Define the source files to be compiled
OBJ includes the corresponding object files for each source file in SRC. # Replace .c files with .o files in SRC
In conclusion, the patsubst and wildcard functions are very useful in makefiles, as they can help us with pattern matching and replacing file names, thereby simplifying our makefile writing process.