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

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

问题描述

假设我有一个包含规则的生成文件

Let's say I have a makefile with the rule

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

我希望在头文件更改时重建 *.o.每当 /include 中的任何头文件发生更改时,都必须重新构建目录中的所有对象,而不是制定依赖项列表.

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

推荐答案

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

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 "$@"
        $(CC) $(CFLAGS) -MM $^ -MF "$@"

include .depend

depend: .depend

.depend: $(SRCS)
        rm -f "$@"
        $(CC) $(CFLAGS) -MM $^ > "$@"

include .depend

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

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

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

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

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

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