# ========================================================================== # Cleaning up # ========================================================================== src := $(obj) PHONY := __clean __clean: include scripts/Kbuild.include # The filename Kbuild has precedence over Makefile kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile) # Figure out what we need to build from the various variables # ========================================================================== __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) subdir-y += $(__subdir-y) __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) subdir-m += $(__subdir-m) __subdir- := $(patsubst %/,%,$(filter %/, $(obj-))) subdir- += $(__subdir-) # Subdirectories we need to descend into subdir-ym := $(sort $(subdir-y) $(subdir-m)) subdir-ymn := $(sort $(subdir-ym) $(subdir-)) # Add subdir path subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) # build a list of files to remove, usually relative to the current # directory __clean-files := \ $(clean-files) $(targets) $(hostprogs) $(userprogs) \ $(extra-y) $(extra-m) $(extra-) \ $(always-y) $(always-m) $(always-) \ $(hostprogs-always-y) $(hostprogs-always-m) $(hostprogs-always-) \ $(userprogs-always-y) $(userprogs-always-m) $(userprogs-always-) # as clean-files is given relative to the current directory, this adds # a $(obj) prefix, except for absolute paths __clean-files := $(wildcard \ $(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \ $(filter /%, $(__clean-files))) # ========================================================================== quiet_cmd_clean = CLEAN $(obj) cmd_clean = rm -rf $(__clean-files) __clean: $(subdir-ymn) ifneq ($(strip $(__clean-files)),) +$(call cmd,clean) endif @: # =========================================================================== # Generic stuff # =========================================================================== # Descending # --------------------------------------------------------------------------- PHONY += $(subdir-ymn) $(subdir-ymn): $(Q)$(MAKE) $(clean)=$@ .PHONY: $(PHONY)