作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这样的目标
test.%
export var1=$(basename $*) && export var2=$(subst .,,$(suffix $*))
test.var1.var2
test.var1.var2.var3
我怎样才能在 makefile 中得到它
make install.{app1}.{test}.{build_number}
最佳答案
使用 subst
用空格替换点,使其成为一个列表。然后使用 word
访问特定元素:
word-dot = $(word $2,$(subst ., ,$1))
test.%:
export var1=$(call word-dot,$*,1) && export var2=$(call word-dot,$*,2) && export var3=$(call word-dot,$*,3)
$ make test.foo.bar.baz
export var1=foo && export var2=bar && export var3=baz
test-{app}
一些目标
APPS
:
tmpl-for = $(foreach x,$2,$(call $1,$x))
rule-for = $(foreach x,$2,$(eval $(call $1,$x)))
APPS := foo bar baz
tmpl-test = test-$1
define test-vars-rule
$(call tmpl-test,$1): APP := $1
.PHONY: $(call tmpl-test,$1)
endef
$(call rule-for,test-vars-rule,$(APPS))
$(call tmpl-for,tmpl-test,$(APPS)):
@echo Testing app: $(APP)
tmpl-for
)或生成规则(
rule-for
)。我创建了一个
tmpl-test
它采用应用程序名称并给出
test-{app}
.我定义了一个规则模板,它采用应用程序名称并设置特定于目标的
APP
适当的变量
test-{app}
目标(顺便说一句,这也是假的)。然后我使用
rule-for
创建我的所有设置规则
APP
.最后,我写出目标的实际主体,并使用
tmpl-for
获得所有可能目标的列表。 .
$ make test-foo
Testing app: foo
$ make test-bar
Testing app: bar
$ make test-baz
Testing app: baz
$ make test-blah
make: *** No rule to make target 'test-blah'. Stop.
关于makefile - 我如何在makefile中用点分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39092055/
我是一名优秀的程序员,十分优秀!