我正在研究 make 文件和 VPATH 变量。基本上,我从几个不同的位置(由 VPATH 指定)获取源文件,并仅使用我想要的 .o 文件列表将它们编译到当前目录中。
到目前为止一切顺利,现在我正在将依赖项信息生成到一个名为“.depend”的文件中,并将其包括在内。如果包含的文件不存在,Gnumake 将尝试使用到目前为止定义的规则来创建该文件,所以没关系。基本上,我的 makefile 看起来像这样。
VPATH=A/source:B/source:C/source
objects=first.o second.o third.o
executable: $(objects)
.depend: $(objects:.o=.c)
$(CC) -MM $^ > $@
include .depend
现在真正的问题是,我可以以任何方式抑制 .depend 文件的生成吗?我目前在 Clearcase 环境中工作 -> sloooow,所以我希望在更新依赖项信息时能够更多地控制它。
这或多或少是一个学术练习,因为我可以将这个东西包装在一个脚本中,该脚本在执行 make 之前接触 .depend 文件(从而使其比任何源文件更新),但很有趣的是知道我是否可以以某种方式使用“纯”make 抑制它。
我无法删除对源文件的依赖关系(即仅使用 .depend:
),因为我依赖 $^
变量来为我执行 VPATH 解析。
如果有任何方法可以仅因更新的 #include
指令而更新依赖项,那当然会更好..但我不会为此屏住呼吸.. :)
I'm playing around with make files and the VPATH variable. Basically, I'm grabbing source files from a few different places (specified by the VPATH), and compile them into the current directory using simply a list of .o-files that I want.
So far so good, now I'm generating dependency information into a file called '.depend' and including that. Gnumake will attempt to use the rules defined so far to create the included file if it doesn't exist, so that's ok. Basically, my makefile looks like this.
VPATH=A/source:B/source:C/source
objects=first.o second.o third.o
executable: $(objects)
.depend: $(objects:.o=.c)
$(CC) -MM $^ > $@
include .depend
Now for the real question, can I suppress the generation of the .depend file in any way? I'm currently working in a clearcase environment -> sloooow, so I'd prefer to have it a bit more under control when to update the dependency information.
It's more or less an academic exercise as I could just wrap the thing in a script which is touching the .depend file before executing make (thus making it more recent than any source file), but it'd interesting to know if I can somehow suppress it using 'pure' make.
I cannot remove the dependency to the source files (i.e. using simply .depend:
), as I'm depending on the $^
variable to do the VPATH resolution for me.
If there'd be any way to only update dependencies as a result of updated #include
directives, that'd be even better of course.. But I'm not holding my breath for that one.. :)
发布评论
评论(1)
如果您不想每次都重新制作 .depend,则不必为其制定规则。请注意,每当您确实需要重新制作依赖项文件时,您还必须重新制作目标文件(这不是我的见解,它来自 高级自动依赖生成,我花了一些时间才掌握它)。因此,使用 PHONY 目标在链接规则中构造 .depend :
您可以通过拥有单独的依赖文件(每个对象一个)来提高效率,这样当一个文件发生更改时,您不必重新计算所有对象的依赖关系:
(编辑:刚刚纠正了一个愚蠢的错误。)
If you don't want to remake .depend every time, you mustn't have a rule for it. Note that whenever you really need to remake the dependencies file, you must also remake an object file (this is not my insight, it comes from Advanced Auto-Dependency Generation, and it took me some time to grasp it). So construct .depend in the linking rule, using a PHONY target:
You can make things more efficient by having seperate depend files, one for each object, so that when one changes you don't have to recalculate the dependencies of all the objects:
(EDIT: just corrected a dumb mistake.)