filter-out 怎么用
时间: 2023-08-21 13:07:49 浏览: 69
filter-out 函数是 GNU Make 中的一个函数,用于在 Makefile 中过滤掉一部分字符串。它的语法如下:
```
$(filter-out pattern...,text)
```
其中,pattern 是要过滤掉的字符串模式,可以使用通配符 % 和 ?,也可以使用多个模式,以空格分隔;text 是要被过滤的字符串。
filter-out 函数的返回值是 text 中不匹配任何 pattern 的部分,多个结果之间以空格分隔。
下面是一个例子,演示如何使用 filter-out 函数过滤掉一部分字符串:
```
SOURCES = main.c foo.c bar.c
OBJECTS = $(filter-out main.o,$(SOURCES:.c=.o))
all: $(OBJECTS)
gcc -o myapp $(OBJECTS)
```
在上面的例子中,SOURCES 变量定义了所有的源文件,OBJECTS 变量使用 filter-out 函数过滤掉了 main.c 文件,并将剩下的所有文件转换成了 .o 文件。在 all 目标中,我们使用 GCC 将 OBJECTS 中的所有目标文件链接成可执行文件 myapp。
相关问题
makefile filter-out
Sure, I can help with that!
The `filter-out` function in a Makefile is used to remove certain strings from a list of strings.
Here's an example of how to use `filter-out` in a Makefile:
```
# Define a list of files
FILES := file1.txt file2.txt file3.dat file4.pdf
# Remove all files with a .pdf extension
PDF_FILES := $(filter-out %.pdf,$(FILES))
# Print the filtered list of files
all:
@echo $(PDF_FILES)
```
In the above example, the `filter-out` function removes all files with a `.pdf` extension from the `FILES` list and stores the resulting list in the `PDF_FILES` variable.
The resulting output when running `make` would be:
```
file1.txt file2.txt file3.dat
```
Let me know if you have any further questions!
Makefile filter-out 是什么
在 Makefile 中,`filter-out` 是一个函数,用于从一个字符串列表中过滤掉特定的字符串。它的语法如下:
```
$(filter-out pattern...,text)
```
其中,`pattern...` 是需要被过滤掉的字符串模式,可以使用通配符 `%`,`text` 是要进行过滤的原始字符串列表。
`filter-out` 函数会返回一个新的字符串列表,其中过滤掉了所有匹配 `pattern...` 的字符串。
下面是一个示例,演示如何使用 `filter-out` 从 Makefile 的文件列表中过滤掉所有以 `.pdf` 结尾的文件:
```makefile
# 定义文件列表
FILES := file1.txt file2.pdf file3.dat file4.pdf
# 过滤掉所有以 .pdf 结尾的文件
PDF_FILES := $(filter-out %.pdf, $(FILES))
# 打印过滤后的文件列表
all:
@echo $(PDF_FILES)
```
在上面的示例中,`PDF_FILES` 变量将只包含文件 `file1.txt` 和 `file3.dat`,因为 `file2.pdf` 和 `file4.pdf` 已经被过滤掉了。
希望这个解释能够帮助您理解 Makefile 中的 `filter-out` 函数。