Commit bf2737d1 authored by Sam Ravnborg's avatar Sam Ravnborg

kbuild: Distributed clean infrastructure

  
Today there is a huge list of files in the top-level Makefile that is
deleted during make clean and make mrproper.
This patch add infrastructure to get rid of this centralised list.

Within a makefile simply use:
clean-files := files-to-be-deleted
or eventually
clean-rule := command to be executed to delete files
  
Files specified by host-progs and EXTRA_TARGETS are deleted during cleaning,
and the same is all *.[oas] .*.cmd .*.tmp .*.d in the visited directories.
  
Deleting core files is moved down to mrporper time

Patches utilising this and the centralised list will dismiss.

Based on a concept originally made by Kai Germaschewski
parent 469d2810
...@@ -661,10 +661,15 @@ allmodconfig: ...@@ -661,10 +661,15 @@ allmodconfig:
defconfig: defconfig:
yes '' | $(CONFIG_SHELL) $(src)/scripts/Configure -d arch/$(ARCH)/config.in yes '' | $(CONFIG_SHELL) $(src)/scripts/Configure -d arch/$(ARCH)/config.in
# Cleaning up ###
# --------------------------------------------------------------------------- # Cleaning is done on three levels.
# make clean Delete all automatically generated files, including
# files removed with 'make clean' # tools and firmware.
# make mrproper Delete the current configuration, and related files
# Any core files spread around is deleted as well
# make distclean Remove editor backup files, patch leftover files and the like
# Files removed with 'make clean'
CLEAN_FILES += \ CLEAN_FILES += \
include/linux/compile.h \ include/linux/compile.h \
vmlinux System.map \ vmlinux System.map \
...@@ -690,7 +695,7 @@ CLEAN_FILES += \ ...@@ -690,7 +695,7 @@ CLEAN_FILES += \
net/khttpd/make_times_h net/khttpd/times.h \ net/khttpd/make_times_h net/khttpd/times.h \
submenu* submenu*
# files removed with 'make mrproper' # Files removed with 'make mrproper'
MRPROPER_FILES += \ MRPROPER_FILES += \
include/linux/autoconf.h include/linux/version.h \ include/linux/autoconf.h include/linux/version.h \
drivers/net/hamradio/soundmodem/sm_tbl_{afsk1200,afsk2666,fsk9600}.h \ drivers/net/hamradio/soundmodem/sm_tbl_{afsk1200,afsk2666,fsk9600}.h \
...@@ -712,33 +717,43 @@ MRPROPER_FILES += \ ...@@ -712,33 +717,43 @@ MRPROPER_FILES += \
tags TAGS kernel.spec \ tags TAGS kernel.spec \
.tmp* .tmp*
# directories removed with 'make mrproper' # Directories removed with 'make mrproper'
MRPROPER_DIRS += \ MRPROPER_DIRS += \
.tmp_export-objs \ .tmp_export-objs \
include/config \ include/config \
include/linux/modules include/linux/modules
clean: archclean # clean - Delete all intermidiate files
@echo 'Cleaning up' #
@find . $(RCS_FIND_IGNORE) \ clean-dirs += $(ALL_SUBDIRS) Documentation/DocBook
\( -name \*.[oas] -o -name core -o -name .\*.cmd -o \ cleanprint:
-name .\*.tmp -o -name .\*.d \) -type f -print \ @echo ' Cleaning the srctree'
| grep -v lxdialog/ | xargs rm -f
@rm -f $(CLEAN_FILES)
+@$(call descend,Documentation/DocBook,clean)
$(addprefix _clean_,$(clean-dirs)): cleanprint
+@$(call descend,$(patsubst _clean_%,%,$@), subdirclean)
quiet_cmd_rmclean = RM $$(CLEAN_FILES)
cmd_rmclean = rm -f $(CLEAN_FILES)
clean: archclean $(addprefix _clean_,$(clean-dirs))
$(call cmd,rmclean)
# mrproper - delete configuration + modules + core files
#
quiet_cmd_mrproper = RM $$(MRPROPER_DIRS) + $$(MRPROPER_FILES)
cmd_mrproper = rm -rf $(MRPROPER_DIRS) && rm -f $(MRPROPER_FILES)
mrproper: clean archmrproper mrproper: clean archmrproper
@echo 'Making mrproper' @echo ' Making mrproper in the srctree'
@find . $(RCS_FIND_IGNORE) \ @find . $(RCS_FIND_IGNORE) \
\( -name .depend -o -name .\*.cmd \) \ \( -name .depend -o -name .\*.cmd -o -name core \) \
-type f -print | xargs rm -f -type f -print | xargs rm -f
@rm -rf $(MRPROPER_DIRS) $(call cmd,mrproper)
@rm -f $(MRPROPER_FILES)
+@$(call descend,scripts,mrproper) +@$(call descend,scripts,mrproper)
+@$(call descend,Documentation/DocBook,mrproper) +@$(call descend,Documentation/DocBook,mrproper)
# distclean - remove all temporaries left behind by patch, vi, emacs etc.
#
distclean: mrproper distclean: mrproper
@echo 'Making distclean' @echo ' Making distclean in the srctree'
@find . $(RCS_FIND_IGNORE) \ @find . $(RCS_FIND_IGNORE) \
\( -not -type d \) -and \ \( -not -type d \) -and \
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \ \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
......
...@@ -87,6 +87,7 @@ obj-m := $(filter-out %/, $(obj-m)) ...@@ -87,6 +87,7 @@ obj-m := $(filter-out %/, $(obj-m))
# Subdirectories we need to descend into # Subdirectories we need to descend into
subdir-ym := $(sort $(subdir-y) $(subdir-m)) subdir-ym := $(sort $(subdir-y) $(subdir-m))
subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
# export.o is never a composite object, since $(export-objs) has a # export.o is never a composite object, since $(export-objs) has a
# fixed meaning (== objects which EXPORT_SYMBOL()) # fixed meaning (== objects which EXPORT_SYMBOL())
...@@ -113,6 +114,10 @@ real-objs-m := $(foreach m, $(obj-m), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m ...@@ -113,6 +114,10 @@ real-objs-m := $(foreach m, $(obj-m), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m
# Only build module versions for files which are selected to be built # Only build module versions for files which are selected to be built
export-objs := $(filter $(export-objs),$(real-objs-y) $(real-objs-m)) export-objs := $(filter $(export-objs),$(real-objs-y) $(real-objs-m))
host-progs-single := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m)))
host-progs-multi := $(foreach m,$(host-progs),$(if $($(m)-objs),$(m)))
host-progs-multi-objs := $(foreach m,$(host-progs-multi),$($(m)-objs))
# Add subdir path # Add subdir path
EXTRA_TARGETS := $(addprefix $(obj)/,$(EXTRA_TARGETS)) EXTRA_TARGETS := $(addprefix $(obj)/,$(EXTRA_TARGETS))
...@@ -127,12 +132,19 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) ...@@ -127,12 +132,19 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y))
multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
clean-files := $(addprefix $(obj)/,$(clean-files))
host-progs := $(addprefix $(obj)/,$(host-progs))
host-progs-single := $(addprefix $(obj)/,$(host-progs-single))
host-progs-multi := $(addprefix $(obj)/,$(host-progs-multi))
host-progs-multi-objs := $(addprefix $(obj)/,$(host-progs-multi-objs))
# The temporary file to save gcc -MD generated dependencies must not # The temporary file to save gcc -MD generated dependencies must not
# contain a comma # contain a comma
depfile = $(subst $(comma),_,$(@D)/.$(@F).d) depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
# We're called for one of three purposes: # We're called for one of four purposes:
# o subdirclean: Delete intermidiate files in the current directory
# o fastdep: build module version files (.ver) for $(export-objs) in # o fastdep: build module version files (.ver) for $(export-objs) in
# the current directory # the current directory
# o modules_install: install the modules in the current directory # o modules_install: install the modules in the current directory
...@@ -142,6 +154,13 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d) ...@@ -142,6 +154,13 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
# When targets are given directly (like foo.o), we just build these # When targets are given directly (like foo.o), we just build these
# targets (That happens when someone does make some/dir/foo.[ois]) # targets (That happens when someone does make some/dir/foo.[ois])
ifeq ($(MAKECMDGOALS),subdirclean)
subdirclean: $(subdir-ymn)
@/bin/true
@rm -f $(EXTRA_TARGETS) $(host-progs) $(clean-files) \
$(addprefix $(obj)/,*.[oas] .*.cmd .*.tmp .*.d)
@$(clean-rule)
else
ifeq ($(MAKECMDGOALS),fastdep) ifeq ($(MAKECMDGOALS),fastdep)
# =========================================================================== # ===========================================================================
...@@ -399,14 +418,6 @@ targets += $(multi-used-y) $(multi-used-m) ...@@ -399,14 +418,6 @@ targets += $(multi-used-y) $(multi-used-m)
# Compile programs on the host # Compile programs on the host
# =========================================================================== # ===========================================================================
host-progs-single := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m)))
host-progs-multi := $(foreach m,$(host-progs),$(if $($(m)-objs),$(m)))
host-progs-multi-objs := $(foreach m,$(host-progs-multi),$($(m)-objs))
host-progs := $(addprefix $(obj)/,$(host-progs))
host-progs-single := $(addprefix $(obj)/,$(host-progs-single))
host-progs-multi := $(addprefix $(obj)/,$(host-progs-multi))
host-progs-multi-objs := $(addprefix $(obj)/,$(host-progs-multi-objs))
quiet_cmd_host_cc__c = HOSTCC $(echo_target) quiet_cmd_host_cc__c = HOSTCC $(echo_target)
cmd_host_cc__c = $(HOSTCC) -Wp,-MD,$(depfile) \ cmd_host_cc__c = $(HOSTCC) -Wp,-MD,$(depfile) \
$(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
...@@ -431,6 +442,7 @@ $(host-progs-multi): %: $(host-progs-multi-objs) FORCE ...@@ -431,6 +442,7 @@ $(host-progs-multi): %: $(host-progs-multi-objs) FORCE
targets += $(host-progs-single) $(host-progs-multi-objs) $(host-progs-multi) targets += $(host-progs-single) $(host-progs-multi-objs) $(host-progs-multi)
endif # ! subdirclean
endif # ! modules_install endif # ! modules_install
endif # ! fastdep endif # ! fastdep
...@@ -480,9 +492,9 @@ cmd_gzip = gzip -f -9 < $< > $@ ...@@ -480,9 +492,9 @@ cmd_gzip = gzip -f -9 < $< > $@
# Descending # Descending
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
.PHONY: $(subdir-ym) .PHONY: $(subdir-ymn)
$(subdir-ym): $(subdir-ymn):
+@$(call descend,$@,$(MAKECMDGOALS)) +@$(call descend,$@,$(MAKECMDGOALS))
# Add FORCE to the prequisites of a target to force it to be always rebuilt. # Add FORCE to the prequisites of a target to force it to be always rebuilt.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment