[CRIU] [PATCH 3/3] make: Makefile.build -- Improve autocleanup target

Cyrill Gorcunov gorcunov at openvz.org
Fri Dec 13 03:41:53 PST 2013


Currently we clean up with wildchar mask. This actually
not that correct. Lets remove only the files were generated
by our make engine.

This as well allows to clean up objects generated as $obj-e
target even if the directory $obj-e is laying in doesn't have
own Makefile.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 scripts/Makefile.build | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index afee94b90706..fcaeaa8cc7e6 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -9,11 +9,27 @@ deps-after	:=
 all-objs	:=
 incdeps		:=
 _all		:=
+_cleanup-y	:=
 
 include scripts/Makefile.rules
 include $(obj)/$(makefile)
 
 ##
+## Append targets to be auto-cleanuped
+define add-cleanup-obj-c-by-name
+_cleanup-y+= $(1).o
+_cleanup-y+= $(1).i
+_cleanup-y+= $(1).d
+_cleanup-y+= $(1).s
+endef
+
+define add-cleanup-obj-S-by-name
+_cleanup-y+= $(1).o
+_cleanup-y+= $(1).d
+_cleanup-y+= $(1).i
+endef
+
+##
 ##
 ## Generate a bundle of rules for C files
 define gen-target-c-bundle
@@ -21,6 +37,7 @@ $(eval $(call gen-rule-o-from-c-by-name,$(1),$(2),$(3)))
 $(eval $(call gen-rule-i-from-c-by-name,$(1),$(2),$(3)))
 $(eval $(call gen-rule-d-from-c-by-name,$(1),$(2),$(3)))
 $(eval $(call gen-rule-s-from-c-by-name,$(1),$(2),$(3)))
+$(eval $(call add-cleanup-obj-c-by-name,$(1)))
 endef
 
 ##
@@ -30,6 +47,7 @@ define gen-target-S-bundle
 $(eval $(call gen-rule-o-from-S-by-name,$(1),$(2),$(3)))
 $(eval $(call gen-rule-d-from-S-by-name,$(1),$(2),$(3)))
 $(eval $(call gen-rule-i-from-S-by-name,$(1),$(2),$(3)))
+$(eval $(call add-cleanup-obj-S-by-name,$(1)))
 endef
 
 ##
@@ -156,6 +174,7 @@ $$(obj)/$(1).built-in.o: $$($(1)-all-objs) $$($(1)-libs-e) $(libs-e)
 	$$(Q) $$(LD) $$(LDFLAGS) -r -o $$@ $$^
 
 _all += $$(obj)/$(1).built-in.o
+cleanup-y += $$(obj)/$(1).built-in.o
 endef
 
 ##
@@ -176,6 +195,7 @@ $(obj)/built-in.o: $(all-objs) $(libs-e)
 	$(Q) $(LD) $(LDFLAGS) -r -o $@ $^
 
 _all += $(obj)/built-in.o
+cleanup-y += $(obj)/built-in.o
 endif
 endif
 
@@ -203,10 +223,7 @@ endif
 ##
 ##
 ## Autocomplete cleanups
-cleanup-y += $(obj)/*.o $(obj)/*.d
-cleanup-y += $(obj)/*.i $(obj)/*.s
-cleanup-y += $(obj)/*.built-in.o
-cleanup-y += $(obj)/built-in.o
+cleanup-y += $(_cleanup-y)
 
 ##
 ## Predefined .PHONY targets
-- 
1.8.3.1



More information about the CRIU mailing list