百分号在makefile中有什么作用? [英] What does a percent symbol do in a makefile?

查看:661
本文介绍了百分号在makefile中有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的makefile:

I have a makefile that looks like this :

include $(patsubst %,$(src)/%/Make.tests, $(TEST_SUBDIRS))

%-test: 
       Something here

我了解目标规则行中的用途.第一行中的%符号是做什么的?它与目标规则行中的百分号有关系吗?

I understand what it is intended for in the target rule line. What is the % sign doing in the first line ? Does it have anything to do percent sign in the target rule line ?

当我编写make sometarget时,makefile中的所有行是否都没有作为任何规则的一部分(例如此makefile中的第一行)执行?如果是,那么执行的顺序是什么?

When I write make sometarget, are the lines in the makefile that are not written as part of any rule (like the first line in this makefile) executed at all ? If yes, then what is the order of execution ?

推荐答案

您可以在功能的第一个参数构成了模式.将最后一个参数中的每个项目/单词与该模式进行比较,如果匹配,则将其替换为第二个参数.如果模式中有通配符(%),则它将匹配任意数量的字符,并将这些字符复制到替换字符串中第二个参数中%的位置.

As you can read in the GNU make manual, the percent acts as a wildcard. The first argument of the patsubst function forms the pattern. Each item/word in the last argument is compared against this pattern, and if it matches, it is replaced with the second argument. If there is a wildcard symbol (%) in the pattern, this will match any number of characters, and these characters are copied into the replacement string at the place of the % in the second argument.

在您的示例中,模式只是通配符,因此它将与函数的最后一个参数中的任何单词匹配,并且该单词将被复制到%位置的替换字符串(第二个参数)中.

In your example the pattern is just the wildcard symbol, so it will match any word in the last argument to the function, and this word will be copied into the replacement string (the second argument) at the place of the %.

一个例子可以使事情变得更清楚.假设TEST_SUBDIRS包含两个名称.

An example may make things more clear. Let's assume TEST_SUBDIRS contains two names.

TEST_SUBDIRS := test1 test2
include $(patsubst %,$(src)/%/Make.tests, $(TEST_SUBDIRS))

然后等同于以下内容.

include $(src)/test1/Make.tests $(src)/test2/Make.tests

makefile逐行顺序处理.变量赋值是内部化的",并且include语句导致将其他文件的内容按原样插入该位置,然后将该内容作为makefile的一部分进行处理.
在读取规则时会根据规则形成一个依赖关系图,并且在处理完整个文件之后,将执行必要的配方以更新请求的目标.

A makefile is processed sequentially, line by line. Variable assignments are "internalized", and include statements cause the contents of other files to be inserted literally at that location after which that content is processed as part of the makefile.
A dependency graph is formed from the rules as they are being read in, and after the entire file is processed, the necessary recipes are executed to update the requested target.

这篇关于百分号在makefile中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆