1

鉴于此Makefile(精简为一个最小示例):

include Makefile2
NAME=bar

第二个Makefile2是一些一般规则:

NAME=foo
something: $(NAME).txt
    @echo  $(NAME).txt

调用make something将取决于foo.txt但它会打印bar.txt

是否可以定义一个Makefile2依赖于$(NAME).txt实际值的NAME规则,因此示例规则也将bar.txt用作依赖项?

4

1 回答 1

1

这是一个 hack,但它有效:

NAME:=foo

something:
    @$(MAKE) -s other OTHERNAME=$(NAME)

other: $(OTHERNAME).txt
    @echo NAME is $(NAME).txt, and this rule depends on $<
于 2012-10-19T23:04:59.390 回答