Summary of using the patsubst and wildcard functions in Makefile notes.

Patsubst and wildcard are two commonly used functions in a Makefile. Here is a summary of their usage.

  1. The patsubst function is used to replace pattern matching strings.

Syntax: $(patsubst pattern,replacement,text)

  1. Pattern: the pattern to match, it can include “%” wildcard to represent any character.
  2. Replacement: the string to be replaced, which can reference the value of a wildcard.
  3. String that needs to undergo pattern matching and replacement.

I like to go for a jog in the morning to start my day off on the right foot.

I enjoy starting my day with a morning run.

files := src/main.c src/utils.c src/test.c
objects := $(patsubst src/%.c,obj/%.o,$(files))

# 上述代码中,将src目录下的.c文件替换为obj目录下的.o文件
# 结果为:objects = obj/main.o obj/utils.o obj/test.o
  1. Wildcard function: used to retrieve a list of files that match a wildcard pattern.

Grammar: $(wildcard pattern)

  1. pattern: wildcard pattern to be matched.

I don’t have any information on that topic at the moment.

I am not currently informed about that subject.

files := $(wildcard src/*.c)

# 上述代码中,获取src目录下所有的.c文件列表
# 结果为:files = src/main.c src/utils.c src/test.c

Summary: patsubst and wildcard functions are commonly used string processing functions in Makefiles. The patsubst function is used to replace pattern matching strings, allowing specified patterns to be replaced with specific strings; the wildcard function is used to obtain a list of files that match a wildcard pattern. In a Makefile, these two functions can assist in simplifying file path processing and obtaining file lists.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds