makefile目标的第二次扩展和替换

时间:2014-07-22 14:08:59

标签: makefile expansion

我正在尝试使用替换在makefile中进行第二次扩展。 示例makefile:

# We have src{0..3}.md documents. Generate them with
#
#   for i in src{0..3}.md; do echo "Hello in $i" > $i; done
#
# doc0.txt and doc2.txt are capitalized and doc1.txt and doc3b.txt are
# lowercased.

CAP_DOCS := doc0.txt doc2.txt
LOW_DOCS := doc1.txt doc3.txt
DOCS := $(CAP_DOCS) $(LOW_DOCS)

all: $(DOCS)

.SECONDEXPANSION:
$(CAP_DOCS): $$(@:doc%.txt=src%.md)
    tr '[a-z]' '[A-Z]' < $< > $@

.SECONDEXPANSION:
$(LOW_DOCS): $$(@:doc%.txt=src%.md)
    tr '[A-Z]' '[a-z]' < $< > $@

我得到的错误是

$ make 
Makefile:15: *** target pattern contains no `%'.  Stop.

我还尝试设置perc=%并将%字符替换为$(perc)甚至$$(perc),因为我认为它是在第二次扩展之前尝试扩展它们而失败了。它没有帮助。

1 个答案:

答案 0 :(得分:2)

我也无法将变量中的%隐藏起来,但这也是我的第一个想法。

我能够让$(CAP_DOCS): $$(patsubst doc%.txt,src%.md,$$@)$(LOW_DOCS): $$(patsubst doc%.txt,src%.md,$$@工作。

我还没有尝试过,但我想知道你是否可以在定义或其他东西中隐藏替换引用并达到同样的效果。

相关问题