旨在重命名所有 .c 文件的 Makefile 规则中使用的百分比

Percentage used in the Makefile rule that aims at renaming all .c files

我认为 Makefile 中的百分比表示通配符。作为尝试,我测试了一个旨在将任何 .c 文件更改为 'hi' 的设计 Makefile。这是我的 Makefile 规则:

%.c:
         mv $@ hi

我把上面的文件保存到'Makefile',然后在终端输入

touch hello.c
make  

终端显示

make: `hello.c' is up to date.

这当然不是我想要的。两个幼稚的问题:

您尚未在规则中定义任何依赖项。 hello.c 已经存在并且 none 的依赖项具有比 hello.c.

更新的时间戳

有像 clean 这样没有依赖关系的规则。在这种情况下,文件 clean 不存在并且 make 尝试通过执行规则的命令集来创建它。但是,如 GNU make documentation 中所述,这在创建 clean 文件的情况下不起作用。解决方案是将 clean 定义为 "Phony Target".

此外,命令的输出是文件 hi 而不是 %.c

Makefile 应如下所示:

%.hi : %.c
     mv $< $@