Makefile,头依赖 [英] Makefile, header dependencies

查看:168
本文介绍了Makefile,头依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个具有规则的生成文件:

 %。o:%.c 
gcc -Wall - 包括...

每当头文件更改时,我都希望* .o重建。而不是制定一个依赖列表,只要 / include 中的头文件发生更改,那么dir中的所有对象都必须重新构建。



我不能想到一个很好的方法来改变规则来适应这个,我可以接受建议。如果标题列表不需要硬编码,则会得到积分。

解决方案

如果您使用GNU编译器,编译器可以为您组装一个依赖列表。 Makefile片段:

 依赖:.depend 

.depend:$(SRCS)
rm -f ./.depend
$(CC)$(CFLAGS)-MM $ ^ -MF ./.depend;

include .depend

 依赖:.depend 

.depend:$(SRCS)
rm -f ./.depend
$ (CC)$(CFLAGS)-MM $ ^> 。/。依靠;

include .depend

其中 SRCS 是一个变量,指向您的整个源文件列表。



还有工具 makedepend ,但是我从来没有像 gcc -MM


那样喜欢

Let's say I have a makefile with the rule

%.o: %.c
 gcc -Wall -Iinclude ...

I want *.o to be rebuilt whenever a header file changes. Rather than work out a list of dependencies, whenever any header file in /include changes, then all objects in the dir must be rebuilt.

I can't think of a nice way to change the rule to accomodate this, I'm open to suggestions. Bonus points if the list of headers doesn't have to be hard-coded

解决方案

If you are using a GNU compiler, the compiler can assemble a list of dependencies for you. Makefile fragment:

depend: .depend

.depend: $(SRCS)
        rm -f ./.depend
        $(CC) $(CFLAGS) -MM $^ -MF  ./.depend;

include .depend

or

depend: .depend

.depend: $(SRCS)
        rm -f ./.depend
        $(CC) $(CFLAGS) -MM $^ > ./.depend;

include .depend

where SRCS is a variable pointing to your entire list of source files.

There is also the tool makedepend, but I never liked it as much as gcc -MM

这篇关于Makefile,头依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆