只有当需要编译的文件 [英] Compile files only if needing

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

问题描述

我在目录 ./ SRC 情侣CPP和HPP文件。我编译一个二进制文件中的所有cpp文件,比如 ./斌/运行。我只想重新编译,如果我需要即它或它的报头的一个改变。

I have couple of cpp and hpp files in directory ./src. I compile all cpp files in one binary file, say ./bin/run. I want to re-compile only if I need i.e it or one of its header was changed.

我,也许可以创造的Makefile,其中当且仅当它被改变文件将被重新编译,但它是相当不舒服,因为我的code的很大一部分是在头部。 (它不会被改变,因为该产品是头本身和CPP文件测试)。

I, probably, can create Makefile where file will be recompiled if and only if it was changed, but it's quite uncomfortable because big part of my code is in the headers. (It's not going to be changed, because the product is header itself and cpp files are tests).

我要暂时的.o 文件存储在 ./建立

我知道 G ++ -MM 的功能,但我不知道如何使用它。

I know about g++ -MM function but I'm not sure how to use it.

我会很高兴地看到,使用没有必要的解决方案制作,但其他系统可能的,如果他们是很容易的。

I'll glad to see solutions that use not necessary make but any other system possible if they are easy enough.

UPD
我会尽力澄清,有什么问题是:

UPD I'll try to clarify, what's the problem is:

新刑事诉讼法的可能创建的,包括可以增加或消失,等等。我不想每次编辑我的Makefile文件。

New cpp's maybe created, includes may be added or gone, etc. I don't want to edit my makefile each time.

推荐答案

您提 G ++ -MM ,它可以做你想做什么:

You mention g++ -MM, which can do what you're trying to do:

include $(ALLOBJ:%.o=%.d)

%.d: %.cxx
    @echo making dependencies for $<
    @g++ -MM -MP $(CXXFLAGS) $< -o $@
    @sed -i 's,$*\.o,& $@ ,g' $@

基本上,这定义了从 .CXX 文件创建 .D 文件的规则。在 .D 文件,反过来,要求由包含语句,这就需要为每个<$ C $在 ALLOBJ C>的.o 文件。

Basically this defines a rule that creates .d files from .cxx files. The .d files are, in turn, required by the include statement, which requires one for each .o file in ALLOBJ.

在依赖关系规则中的最后一行是sed的魔术,使依赖文件生成自己。如果你觉得普通的前pressions是黑客在最好的,和邪恶的往往不是,你可以使用 -MT 标志

The last line in the dependency rule is the 'sed magic' that makes the dependency files regenerate themselves. If you think regular expressions are hacks at best, and evil more often than not, you can use the -MT flag.

这篇关于只有当需要编译的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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