makefile中的空目标

时间:2016-01-13 10:49:42

标签: makefile

尝试了解空目标的工作原理以及何时有用。

我的makefile:

;assuming global_list1 and global_list2 exist

to setup
  let index 0
  create-turtles slidervalue [
                               set turtle_value1 item index global_list1
                               set turtle_value2 item index global_list2
                               set index index + 1
                             ]
end

空目标是 count_words: size count_words.o gcc size count_words.o -o count_words %.o:%.c gcc -c -o $@ $< size: count_words.o size $^ touch size 。无法理解删除size文件时运行规则的原因,但size是最新的。我想如果count_words.o是最新的,它不应该运行大小规则,如果大小文件被删除则会发生事件,但确实如此! count_words.o不取决于count_words.o

当空目标可能有用时?

2 个答案:

答案 0 :(得分:0)

您的count_words目标取决于size。如果文件丢失或 比count_words更早,其目标被自动调用 &#34;重建&#34;它。如果不删除,则只有正确的行为 size个文件。

尺寸目标的行为与普通目标相同。

由于你只有一个文件,&#34;空&#34;目标没有 很有道理。

答案 1 :(得分:0)

这不是一个空目标。而是一个空文件。 GNU make仅关注文件/目录是否存在及其时间戳。

当make创建或更新size时,表示所有size个家属都已过期,必须重新构建。

相关问题