Makefile:几个语法问题
package_version := $(版本)x0d$(日期)
版本和日期变量之间的 x0d 部分是什么?它只是字符串吗?
$(dotin_files:.in=) 下面的作用
代码的
dotin_files := $(shell find . -type f -name \*.in)
dotin_files := $(dotin_files:.in=)
- 作用是什么 $(dotin_files:=.in)
代码
$(dotin_files): $(dotin_files:=.in)
$(substitute) [email protected] > $@
目标可以包含多个文件吗?
将目标变量声明为 PHONY 的含义是什么?
代码
.PHONY: $(dotin_files)
- 在下面的正则表达式替换代码中,
代码
substitute := perl -p -e 's/@([^@]+)@/defined $$ENV{$$1} ? $$ENV{$$1} : $$&/ge'
中的 $$ENV{$$1}
和 $$&
是什么?我想这是 Perl 范围...
谢谢您的时间
package_version := $(version)x0d$(date)
what is the x0d part between version and date vars? is it just string?
What $(dotin_files:.in=) does below
code
dotin_files := $(shell find . -type f -name \*.in)
dotin_files := $(dotin_files:.in=)
- what this means $(dotin_files:=.in)
code
$(dotin_files): $(dotin_files:=.in)
$(substitute) [email protected] > $@
can target contain multiple files?
what is the meaning of declaring target variable as PHONY?
code
.PHONY: $(dotin_files)
- In the regex replacement code below
code
substitute := perl -p -e 's/@([^@]+)@/defined $ENV{$1} ? $ENV{$1} : $&/ge'
what are $$ENV{$$1}
and $$&
? I guess it's Perl scope...
thanks for your time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
变量扩展
$()
是 make 中的变量扩展,这应该只是字符串替换 - 如果您的 makefile 是,则变量
package_version
将扩展为1x0d1.1.10
。替换
语法
$(var:a=b)
是一个替换引用 并将扩展为var
,后缀a
替换为b.
例如,
$(faabar)
将扩展为字符串faa bar
。多个目标
make 规则中的多个目标相当于具有单个目标的 n 条规则,例如
相当于
记住此处的任何变量都是扩展的。
虚假目标
.PHONY
目标声明规则不会生成实际文件,因此始终会构建它。与往常一样,变量首先被扩展。在您的情况下,这将扩展为类似Escaping
美元符号是 makefile 中的转义字符,perl 示例中的
$$
是文字$,例如
substitute
将是字符串这里的美元符号由perl处理,并且可能给出环境变量(我不知道perl)。
Variable Expansion
$()
is variable expansion in make, this should just be string substitution - if your makefile isthen the variable
package_version
will expand to1x0d1.1.10
.Substitution
The syntax
$(var:a=b)
is a substitution reference and will expand tovar
with a suffixa
substituted withb
.For example, in
$(faabar)
will expand to the stringfaa bar
.Multiple Targets
Multiple targets in a make rule is equivalent to having n rules with a single target, eg
is equivalent to
remember that any variables here are expanded.
Phony Targets
The
.PHONY
target declares that a rule doesn't produce an actual file, so it will always be built. As always, variables are expanded first. In your case this will expand to something likeEscaping
A dollar sign is an escape character in makefiles, the
$$
in your perl example is a literal$
, egsubstitute
will be the stringThe dollar signs here are processed by perl, and probably give environment variables (I don't know perl).
版本和日期变量之间的 x0d 部分,它只是字符串吗?
是的。
$(dotin_files:.in=) 下面的作用
从使用 shell find 找到的文件名中删除 .in。
这意味着什么 $(dotin_files:=.in)
我认为你的意思是 $(dotin_files:.in=)。正如已经回答的,在变量 dotin_files 中,它将任何出现的“.in”替换为空字符串(“=”和“)”之间的部分。
目标可以包含多个文件吗?
是的
将目标变量声明为 PHONY 是什么意思?
make 将忽略目标时间戳并将其视为新目标
从而每次都重建它们。
在下面的正则表达式替换代码中,$$ENV{$$1} 和 $$& 是什么?
为了避免 $ENV 扩展,$ 被加倍,想想 C 格式字符串中的 '%',因此字符串
perl -p -e 's/@([^@]+)@/定义 $$ENV{$$1} ? $$ENV{$$1} : $$&/ge'
当作为 shell 命令调用时将变成:
perl -p -e 's/@([^@]+)@/定义 $ENV{$1} ? $ENV{$1} : $&/ge'
$ENV 是 perl 环境哈希,$1 我认为它是 s/// 正则表达式组中的反向引用。
x0d part between version and date vars, is it just string?
Yes.
What $(dotin_files:.in=) does below
Removes the .in from the filenames found with the shell find.
what this means $(dotin_files:=.in)
I think you meant $(dotin_files:.in=). As already answered, within the variable dotin_files it replaces any occurrence of ".in" with an empty string(the part between the "=" and ")".
can target contain multiple files?
Yes
what is the meaning of declaring target variable as PHONY?
make will ignore targets time-stamp and consider them as new
thus rebuilding them each time.
In the regex replacement code below what are $$ENV{$$1} and $$&?
To avoid expansion of $ENV, the $ is doubled, think of '%' in C format strings, thus the string
perl -p -e 's/@([^@]+)@/defined $$ENV{$$1} ? $$ENV{$$1} : $$&/ge'
when called as a shell command will become:
perl -p -e 's/@([^@]+)@/defined $ENV{$1} ? $ENV{$1} : $&/ge'
$ENV is the perl Environment hash, $1 I think it's a backreference in the s/// regexp group.
Michael,您一直在问很多基本的 Makefile 问题,您现在问的问题应该能够通过实验自己回答。
尝试一下:
现在尝试
make foo.in
和make bar.in
。会发生什么?这是一个替代参考。自己尝试一下,看看会发生什么,就像这样:
它做了什么?
让我们看一下:
如果您想了解更多有关 Perl、正则表达式、查找、制作或其他内容的信息,请随时在这里提问,但请先花一点时间尝试弄清楚。
Michael, you've been asking a lot of basic Makefile questions, and the ones you're asking now are ones you should be able to answer for yourself by experiment.
Try it:
Now try
make foo.in
andmake bar.in
. What happens?It's a substitution reference. Try it yourself and see what happens, like this:
What did it do?
Let's take a look:
If you want to know more about Perl, or regexs, or find, or make, or whatever, feel free to ask here, but please take a little time to try to figure it out first.