Makefile 始终认为项目是最新的 - 但文件甚至不存在
我有以下 makefile: 我的
CCC = g++ CCFLAGS = -ansi driver: driver.o graph.o $(CCC) -o driver driver.o graph.o graph.o: graph.h driver.o: graph.h adjl: rm -f graph.h graph.cc ln -s adjl/graph.cc . ln -s adjl/graph.h . touch graph.cc graph.h adjm: rm -f graph.h graph.cc ln -s adjm/graph.cc . ln -s adjm/graph.h . touch graph.cc graph.h clean: rm -f *.o real_clean: clean rm -f graph.cc graph.h rm -f driver
想法是,我尝试根据我要使用的实现来链接两个不同的 .cc/.h 文件。如果我进行 real_clean,则 .cc/.h 文件都不存在,文件夹中只有 driver.cc 文件和 makefile。如果我调用 make,它会说它们是最新的。即使我编辑 adjl/adjm 中的文件以使其成为“较新”版本,也会发生这种情况。
[95]% ls adjl/ adjm/ driver.cc makefile [96]% make adjl make: `adjl' is up to date. [97]% make adjm make: `adjm' is up to date.
我从我完成的另一个项目中获取了模板 makefile,它们的编写方式相同,但我可以重复执行相同的命令,而不会出现“最新”问题。
我已经用谷歌搜索过,但没有发现与我类似的问题(它们通常似乎涉及在制作前不进行清洁的用户)。
感谢任何人的阅读。
I have the following makefile:
CCC = g++ CCFLAGS = -ansi driver: driver.o graph.o $(CCC) -o driver driver.o graph.o graph.o: graph.h driver.o: graph.h adjl: rm -f graph.h graph.cc ln -s adjl/graph.cc . ln -s adjl/graph.h . touch graph.cc graph.h adjm: rm -f graph.h graph.cc ln -s adjm/graph.cc . ln -s adjm/graph.h . touch graph.cc graph.h clean: rm -f *.o real_clean: clean rm -f graph.cc graph.h rm -f driver
The idea is that I am trying to link two different .cc/.h files depending on which implementation I want to use. If I make real_clean, none of the .cc/.h files exist, I merely have a driver.cc file and the makefile in the folder. If I call make, it says they are up to date. This happens even if I edit the files in adjl/adjm to make them "newer" versions.
[95]% ls adjl/ adjm/ driver.cc makefile [96]% make adjl make: `adjl' is up to date. [97]% make adjm make: `adjm' is up to date.
I took the template makefile from another project I had done, and they are written the same way but I can repeatedly make the same commands with no "up to date" issues.
I have googled but have not found a problem similar to mine (they generally seem to involve users who aren't cleaning before making).
Thanks to anyone for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题在于您的目录名称与 Makefile 中的目标名称相同。
当您发出
make adjl
时,make 检查它找到的文件adjl
并且什么也不做。将目标重命名为其他名称,然后重试。
The problem is that you have directory named the same as your targets in Makefile.
When you issue
make adjl
make checks for fileadjl
which it finds and does nothing.Rename targets to something else and try again.
adjl
和adjm
目标是真实目标。由于它们没有依赖项,并且文件存在(列表中的 2 个目录),因此 make 不会执行任何操作(因为它们就在附近)。但是,您想要的是将
adjl
和adjm
指定为虚假目标(以便在您指定它们时执行命令)。为此,请阅读 http://www.gnu.org/ software/automake/manual/make/Phony-Targets.html 了解更多信息。
编辑
事实上,
real_clean
和clean
规则可能也应该是假的。The
adjl
andadjm
targets are real targets. Since they have no dependencies, and the files are present (the 2 directories in your listing), make doesn't do anything (because they are around).However, what you want is to specify
adjl
andadjm
as phony targets (so that the commands are executed when you specify them). To do so,Read http://www.gnu.org/software/automake/manual/make/Phony-Targets.html for more information.
EDIT
In fact, the
real_clean
andclean
rules should probably also be made phony.您的目录与您的目标同名。
由于您的目标不依赖于任何东西,因此它们将始终被认为是最新的。
当指定未链接到磁盘上文件的目标时,您需要使用特殊目标
.PHONY
:您还应该对 clean 和 real_clean 目标执行相同的操作 - 否则它们'如果有人创建一个名为“clean”的文件,就会中断。
Your have directories with the same name as your targets.
Since your targets don't depend on anything, they'll always be considered up to date.
When specifying a target that isn't linked to a file on disk, you need to use the special target
.PHONY
:You should also do the same for your clean and real_clean targets as well - otherwise they'll break if someone creates a file called "clean".