1 # ==========================================================================
3 # ==========================================================================
10 # The filename Kbuild has precedence over Makefile
11 include $(if $(wildcard $(srctree)/$(src)/Kbuild), \
12 $(srctree)/$(src)/Kbuild, $(srctree)/$(src)/Makefile)
14 # Figure out what we need to build from the various variables
15 # ==========================================================================
17 __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
18 subdir-y += $(__subdir-y)
19 __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
20 subdir-m += $(__subdir-m)
21 __subdir-n := $(patsubst %/,%,$(filter %/, $(obj-n)))
22 subdir-n += $(__subdir-n)
23 __subdir- := $(patsubst %/,%,$(filter %/, $(obj-)))
24 subdir- += $(__subdir-)
26 # Subdirectories we need to descend into
28 subdir-ym := $(sort $(subdir-y) $(subdir-m))
29 subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
33 subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
35 # build a list of files to remove, usually releative to the current
38 __clean-files := $(extra-y) $(EXTRA_TARGETS) $(always) \
39 $(targets) $(clean-files) \
41 $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
43 # as clean-files is given relative to the current directory, this adds
44 # a $(obj) prefix, except for absolute paths
46 __clean-files := $(wildcard \
47 $(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \
48 $(filter /%, $(__clean-files)))
50 # as clean-dirs is given relative to the current directory, this adds
51 # a $(obj) prefix, except for absolute paths
53 __clean-dirs := $(wildcard \
54 $(addprefix $(obj)/, $(filter-out /%, $(clean-dirs))) \
55 $(filter /%, $(clean-dirs)))
57 # ==========================================================================
59 quiet_cmd_clean = CLEAN $(obj)
60 cmd_clean = rm -f $(__clean-files)
61 quiet_cmd_cleandir = CLEAN $(__clean-dirs)
62 cmd_cleandir = rm -rf $(__clean-dirs)
65 __clean: $(subdir-ymn)
66 ifneq ($(strip $(__clean-files)),)
69 ifneq ($(strip $(__clean-dirs)),)
72 ifneq ($(strip $(clean-rule)),)
78 # ===========================================================================
80 # ===========================================================================
83 # ---------------------------------------------------------------------------
87 $(Q)$(MAKE) $(clean)=$@
89 # If quiet is set, only print short version of command
91 cmd = @$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
93 # Shorthand for $(Q)$(MAKE) scripts/Makefile.clean obj=dir
95 # $(Q)$(MAKE) $(clean)=dir
96 clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj