如何不做任何修改就清洁? [英] how to make clean without any modification?

查看:51
本文介绍了如何不做任何修改就清洁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的大型库提供了一个makefile,当我修改一些文件但不想编译该库并执行make clean时,首先它将编译所有文件,然后进行清理.我如何在不做任何其他修改的情况下清洁它?

I have a makefile for my huge library, when I modify some files but do not want to compile the library and do make clean, at first it will compile all the files then does the clean. How can I make it to clean without any other modifications?

我也使用了

.PHONY:清洁力
清洁:FORCE
rm * .o rm * .mod 力:

.PHONY: clean FORCE
clean: FORCE
rm *.o rm *.mod FORCE:

我可以使用以下方法解决问题:

I could resolve my problem using:

ifneq($(MAKECMDGOALS),干净)
-包括$(OBJS:%.o =%.d)
结束符

ifneq ($(MAKECMDGOALS),clean)
-include $(OBJS:%.o=%.d)
endif

推荐答案

正如Zhertal所说,至少没有看到干净规则的定义就无法确定.有两种可能性.

As Zhertal says there's no way to know for sure without seeing the definition of the clean rule, at the very least. There are two possibilities for this.

首先,您的clean目标列出了导致所有内容重新生成的先决条件.这不太可能,但是我以前见过人们做过这样的事情.

The first is that your clean target is listing a prerequisite that is causing everything to rebuild. This is unlikely, but I've seen people do things like this before.

第二个也是更有可能的原因是,您正在使用GNU make手册中描述的方法来自动生成先决条件,将%.d模式添加到%.o模式规则中,然后再-include所有.d文件.这里的问题是,make在运行任何目标之前将始终尝试确保makefile是最新的 first ,这意味着尝试重建所有包含的.d文件,这意味着重新编译所有内容.

The second, and more likely, cause is that you're using the method described in the GNU make manual for automatically generating prerequisites, where you add the %.d pattern to your %.o pattern rule and you -include all the .d files. The problem here is that make will always try to make sure that the makefile is up to date first before running any targets, and that means trying to rebuild all the included .d files, which means recompiling everything.

您有两个选择可以解决此问题.首先是将include行放在条件语句中,这样如果您说make clean,它就不会运行,就像这样:

You have two options to fix this. The first is to put the include line inside a conditional so it doesn't run if you say make clean, something like this:

ifeq ($(filter clean,$(MAKECMDGOALS)),)
  -include $(OBJS:%.o=%.d)
endif

当然,如果您有更多干净类型的规则(distclean等),则必须对此进行调整

Of course, this will have to be tweaked if you have more clean-type rules (distclean etc.)

另一种方法是重新处理自动生成的Makefile的方式,以使用更现代,更高级的方法.您可以在高级自动中找到说明. -依赖项

The other is to rework the way you do your auto-generated makefiles to use a more modern, advanced method. You can find a description at Advanced Auto-Dependencies

这篇关于如何不做任何修改就清洁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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