这是我的 Makefile:
# the issue seems to be the "." in the filename, since
# if NAME = test7 the desired result is achieved!
# although, when I check the [4.9 Special Built-in Target Names][1]
# section of the GNU make command, there is nothing mentioned
# about this?
NAME = .test7
$(NAME):
@echo Making $(NAME)...
@touch $(NAME)
@echo Done.
hello:
@echo Hello :\)
all: $(NAME)
@:
clean fclean:
rm -r $(NAME)
re: fclean all
@:
.PHONY: all clean fclean re
如果我只是简单地第一次运行 make,或者此后多次运行,就会显示以下输出:
Hello :)
即使第一条规则是 $(NAME),它也会被忽略,因为它的值以“.”开头,如 NAME = .test7 ?
这是预期的行为吗?
我找到了GNU make 文档的4.9 特殊内置目标名称部分,但其中没有提到这方面的内容?
但是,如果我有 NAME = test7(开头没有“。”),那么在第一次运行时我将获得预期的结果:
Making .test7...
Done.
经过多次尝试后,只需运行 make,正确的输出如下所示:
make: '.test7' is up to date.
有什么建议吗?也许,修复此 .test7 目标,使其像 NAME = test7 的情况一样运行?
上述问题的解决方案似乎是:
生成文件:
NAME = .test7
.DEFAULT_GOAL := $(NAME)
$(NAME):
@echo Making $(NAME)...
@touch $(NAME)
@echo Done.
hello:
@echo Hello :\)
all: $(NAME)
clean fclean:
rm -r $(NAME)
re: fclean all
@:
.PHONY: all clean fclean re default_target
第一次运行make时将输出:
Making .test7...
Done.
而在后续运行中将输出:
make: '.test7' is up to date.
现在make all将输出:
make: Nothing to be done for 'all'.
感谢所有发表评论的人!:)