那些行的目的是处理与依赖性处理的一个问题。
假设你有一个头文件bar.h
,并包含行
#include "bar.h"
现在生成依赖文件中的源文件foo.c
:
$(CC) -MM $*.c > $*.dep
文件foo.dep
现在包含:
foo.o: foo.cc bar.h
很好。我确定makefile有一行,如-include *.dep
,所以现在Make会正确处理foo的依赖关系。但是现在假设你编辑foo.c
,删除那条#include
行,并删除不再需要的bar.h
。下次您尝试make foo
时,Make会读取旧foo.dep
,其中要求bar.h
,请参阅没有这种标题,也没有已知的方式来构建它,然后中止。在重建dep文件之前,make不会知道这个头文件是不需要的,因为头文件缺失并且Make认为它是需要的,所以它不能这样做。
一种解决方法是删除foo.dep
,当出现这种情况(请中止之前,如果可能的话)。另一种是添加一条线到foo.dep
:
bar.h:
这将安慰使得对缺少标题的担忧。第一种方法需要人工关注,第二种方法可以自动化:第二种方法可以自动化:
@mv -f $*.dep $*.dep.tmp # rename foo.dep -> foo.dep.tmp
@sed -e 's|.*:|$*.o:|' < $*.dep.tmp > $*.dep # this does nothing and appears to be vestigal
@sed -e 's/.*://' \ # remove the target, leaving foo.c bar.h
-e 's/\\$$//' \ # remove line continuation marks, if any
< $*.dep.tmp | fmt -1 | \ # put each word on its own line
sed -e 's/^ *//' \ # remove leading whitespace
-e 's/$$/:/' \ # add a colon to the end of each line (making it a rule)
>> $*.dep # save the result as foo.dep
@rm -f $*.dep.tmp # delete the temporary file
它们通过'gcc -MM'调用重新格式化依赖项输出问题。为了什么? dunno ... –