Reputation: 189
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?
I also have used the
.PHONY: clean FORCE
clean: FORCE
rm *.o rm *.mod FORCE:
I could resolve my problem using:
ifneq ($(MAKECMDGOALS),clean)
-include $(OBJS:%.o=%.d)
endif
Upvotes: 0
Views: 376
Reputation: 100856
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.
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.
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.
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
Of course, this will have to be tweaked if you have more clean-type rules (distclean
etc.)
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
Upvotes: 3