Makefile:几个语法问题

发布于 2024-08-31 01:04:56 字数 977 浏览 1 评论 0原文

  • 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风情万种。 2024-09-07 01:04:56

变量扩展

$() 是 make 中的变量扩展,这应该只是字符串替换 - 如果您的 makefile 是,

version=1
date=1.1.10
package_version:=$(version)x0d$(date)

则变量 package_version 将扩展为1x0d1.1.10

替换

语法$(var:a=b)是一个替换引用 并将扩展为 var,后缀 a 替换为 b.

例如,

foobar:= foo bar
faabar:=$(foobar:oo=aa)

$(faabar) 将扩展为字符串 faa bar

多个目标

make 规则中的多个目标相当于具有单个目标的 n 条规则,例如

foo bar:foo.c bar.c
     $(CC) -o $@ $^

相当于

foo:foo.c bar.c
     $(CC) -o $@ $^
bar:foo.c bar.c
     $(CC) -o $@ $^

记住此处的任何变量都是扩展的。

虚假目标

.PHONY 目标声明规则不会生成实际文件,因此始终会构建它。与往常一样,变量首先被扩展。在您的情况下,这将扩展为类似

.PHONY: foo bar

Escaping

美元符号是 makefile 中的转义字符,perl 示例中的 $$ 是文字 $,例如substitute将是字符串

perl -p -e 's/@([^@]+)@/defined $ENV{$1} ? $ENV{$1} : 
amp;/ge'

这里的美元符号由perl处理,并且可能给出环境变量(我不知道perl)。

Variable Expansion

$() is variable expansion in make, this should just be string substitution - if your makefile is

version=1
date=1.1.10
package_version:=$(version)x0d$(date)

then the variable package_version will expand to 1x0d1.1.10.

Substitution

The syntax $(var:a=b) is a substitution reference and will expand to var with a suffix a substituted with b.

For example, in

foobar:= foo bar
faabar:=$(foobar:oo=aa)

$(faabar) will expand to the string faa bar.

Multiple Targets

Multiple targets in a make rule is equivalent to having n rules with a single target, eg

foo bar:foo.c bar.c
     $(CC) -o $@ $^

is equivalent to

foo:foo.c bar.c
     $(CC) -o $@ $^
bar:foo.c bar.c
     $(CC) -o $@ $^

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 like

.PHONY: foo bar

Escaping

A dollar sign is an escape character in makefiles, the $$ in your perl example is a literal $, eg substitute will be the string

perl -p -e 's/@([^@]+)@/defined $ENV{$1} ? $ENV{$1} : 
amp;/ge'

The dollar signs here are processed by perl, and probably give environment variables (I don't know perl).

梦里梦着梦中梦 2024-09-07 01:04:56
  • 版本和日期变量之间的 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.

天荒地未老 2024-09-07 01:04:56

Michael,您一直在问很多基本的 Makefile 问题,您现在问的问题应该能够通过实验自己回答。

can target contain multiple files?

尝试一下:

dotin_files := foo.in bar.in

$(dotin_files):
    @echo $@

现在尝试 make foo.inmake bar.in。会发生什么?

What $(dotin_files:.in=) does

这是一个替代参考。自己尝试一下,看看会发生什么,就像这样:

dotin_files := foo.in bar.in
dotin_files := $(dotin_files:.in=)

all:
    @echo $(dotin_files)

它做了什么?

substitute := perl -p -e 's/@([^@]+)@/defined $ENV{$1} ? $ENV{$1} : $&/ge'
what are $ENV{$1} and $&? I guess it's Perl scope...

让我们看一下:

all:
    @echo $(substitute)

如果您想了解更多有关 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.

can target contain multiple files?

Try it:

dotin_files := foo.in bar.in

$(dotin_files):
    @echo $@

Now try make foo.in and make bar.in. What happens?

What $(dotin_files:.in=) does

It's a substitution reference. Try it yourself and see what happens, like this:

dotin_files := foo.in bar.in
dotin_files := $(dotin_files:.in=)

all:
    @echo $(dotin_files)

What did it do?

substitute := perl -p -e 's/@([^@]+)@/defined $ENV{$1} ? $ENV{$1} : $&/ge'
what are $ENV{$1} and $&? I guess it's Perl scope...

Let's take a look:

all:
    @echo $(substitute)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文