Makefile filter-out 是什么
时间: 2024-02-22 12:57:14 浏览: 193
在 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` 函数。
相关问题
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!
@MAKE -C dir1 dir2 -f Makefile1 $(filter-out _all sub-make,$(MAKECMDGOALS)) explain the grammar in this snippet
Sure, here is an explanation of the grammar in this snippet:
- `@MAKE`: This tells Make to run the command `MAKE` silently, without displaying the command itself.
- `-C dir1 dir2`: This tells Make to change to the directory `dir1/dir2` before running the rest of the command.
- `-f Makefile1`: This tells Make to use the file `Makefile1` instead of the default `Makefile` for this command.
- `$(filter-out _all sub-make,$(MAKECMDGOALS))`: This is a Make function that filters out any targets that match `_all` or `sub-make` from the list of goals specified on the command line (`$(MAKECMDGOALS)`). The resulting list of targets is used as the goals for this Make command.
Put together, this command runs Make silently, changes to the directory `dir1/dir2`, uses `Makefile1` as the Makefile, and filters out any targets that match `_all` or `sub-make` from the list of goals specified on the command line. The resulting list of targets is then used as the goals for this Make command.
阅读全文