我试图了解如何在给定链接的 makefile 中生成自动依赖关系,我无法理解以下代码:
DEPDIR = .deps
df = $(DEPDIR)/$(*F)
SRCS = foo.c bar.c ...
%.o : %.c
@$(MAKEDEPEND); \
cp $(df).d $(df).P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
rm -f $(df).d
$(COMPILE.c) -o $@ $<
-include $(SRCS:%.c=$(DEPDIR)/%.P)
我从 this link. 得到的我知道它会生成依赖文件,但我无法理解这一行的作用:
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
有人可以解释一下这段代码吗,这么多通配符让我很困惑,我是 makefile 的新手。
最佳答案
这是许多不同的命令,因此请将其分解。
-e 's/#.*//'
删除以
#
开头的所有内容(注释?预处理器指令?)-e 's/^[^:]*: *//'
删除任何具有
:
的内容,直至:
。-e 's/*\\$$//'
从行尾删除续行斜杠(及其前面的空格)。
-e '/^$$/d'
删除所有空行。
-e 's/$$/:/'
将
:
添加到每行末尾。
这为每个列出的依赖文件添加了显式目标,以便 make “知道”如何构建它们,以避免“没有规则来创建目标”错误。这里的推理在 an earlier section 中的链接中进行了解释。 .
Briefly, this creates a .P file with the original prerequisites list, then adds targets to it by taking each line, removing any existing target information and any line continuation (\) characters, then adding a target separator (:) to the end. This works with the values for MAKEDEPEND I suggest below; it’s possible you will need to modify the translation for other dependency generators you might use.
关于gnu-make - makefile 中的自动依赖生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30669884/