【发布时间】:2023-04-11 12:12:02
【问题描述】:
只是为了快速的术语:
#basic makefile rule
target: dependencies
recipe
问题:我想自动生成依赖。
例如,我希望转这个:
#one of my targets
file.o: file.cpp 1.h 2.h 3.h 4.h 5.h 6.h 7.h 8.h another.h lots.h evenMore.h
$(COMPILE)
进入这个:
#one of my targets
file.o: $(GENERATE)
$(COMPILE)
我不太确定这是否可能..
我所知道的:
我可以使用这个编译器标志:
g++ -MM file.cpp
它会返回正确的目标和依赖。
所以从示例中,它将返回:
file.o: file.cpp 1.h 2.h 3.h 4.h 5.h 6.h 7.h 8.h another.h lots.h evenMore.h
但是,'make' 不允许我在规则的目标或依赖部分显式编写 shell 代码:(
我知道有一个叫做shell的'make'函数@
但我不能完全将其作为依赖项插入并执行解析魔术,因为它依赖于代表目标的宏 $@.. 或者至少我认为这就是问题所在
我什至尝试用这个 makefile 函数替换“file.cpp”依赖项,但这也不起作用..
#it's suppose to turn the $@ (file.o) into file.cpp
THE_CPP := $(addsuffix $(.cpp),$(basename $@))
#one of my targets
file.o: $(THE_CPP) 1.h 2.h 3.h 4.h 5.h 6.h 7.h 8.h another.h lots.h evenMore.h
$(COMPILE)
#this does not work
所以在整个谷歌上,似乎有两种解决方案。这两个我都没有完全掌握。
From GNU Make Manual
Some Site that says the GNU Make Manual one is out-of-date
所以我的最终问题是:是否可以按照我想要的方式进行操作,
如果没有,有人可以分解其中一个站点的代码并向我详细解释它们是如何工作的。如果必须的话,我会以其中一种方式实现它,但我很厌倦在理解之前将一大块代码粘贴到我的 makefile 中
【问题讨论】:
标签: makefile dependencies gnu