假设我有一个带有规则的makefile
%.o: %.c
gcc -Wall -Iinclude ...
Run Code Online (Sandbox Code Playgroud)
我想要在头文件更改时重建*.o.无论何时/include更改任何头文件,都必须重建dir中的所有对象,而不是计算出依赖项列表.
我想不出一个改变规则以适应这个的好方法,我愿意接受建议.如果标题列表不必硬编码,则奖励积分
只是为了快速术语:
#basic makefile rule
target: dependencies
recipe
Run Code Online (Sandbox Code Playgroud)
例如,我希望转此:
#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)
Run Code Online (Sandbox Code Playgroud)
进入:
#one of my targets
file.o: $(GENERATE)
$(COMPILE)
Run Code Online (Sandbox Code Playgroud)
而且我不太确定它是否可能......
我可以使用这个编译器标志:
g++ -MM file.cpp
Run Code Online (Sandbox Code Playgroud)
它将返回正确的目标和依赖.
所以从示例中,它将返回:
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
Run Code Online (Sandbox Code Playgroud)
但是,'make'不允许我在规则的目标或依赖部分中显式编写shell代码:(
我知道有一个'make'函数叫做shell
但我不能完全插入这个依赖并解析魔法,因为它依赖于表示目标的宏$ @或者至少我认为这就是问题所在
我甚至尝试用这个makefile函数替换"file.cpp"依赖项,但这也无效.
#it's suppose to turn the $@ (file.o) into file.cpp
THE_CPP := $(addsuffix $(.cpp),$(basename $@))
#one of my targets …Run Code Online (Sandbox Code Playgroud)