aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/Makefile.clean
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Makefile.clean')
-rw-r--r--scripts/Makefile.clean94
1 files changed, 94 insertions, 0 deletions
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
new file mode 100644
index 000000000000..ff3e87dbf387
--- /dev/null
+++ b/scripts/Makefile.clean
@@ -0,0 +1,94 @@
1# ==========================================================================
2# Cleaning up
3# ==========================================================================
4
5src := $(obj)
6
7.PHONY: __clean
8__clean:
9
10include $(if $(wildcard $(obj)/Kbuild), $(obj)/Kbuild, $(obj)/Makefile)
11
12# Figure out what we need to build from the various variables
13# ==========================================================================
14
15__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
16subdir-y += $(__subdir-y)
17__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
18subdir-m += $(__subdir-m)
19__subdir-n := $(patsubst %/,%,$(filter %/, $(obj-n)))
20subdir-n += $(__subdir-n)
21__subdir- := $(patsubst %/,%,$(filter %/, $(obj-)))
22subdir- += $(__subdir-)
23
24# Subdirectories we need to descend into
25
26subdir-ym := $(sort $(subdir-y) $(subdir-m))
27subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
28
29# Add subdir path
30
31subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
32
33# build a list of files to remove, usually releative to the current
34# directory
35
36__clean-files := $(extra-y) $(EXTRA_TARGETS) $(always) \
37 $(targets) $(clean-files) \
38 $(host-progs) \
39 $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
40
41# as clean-files is given relative to the current directory, this adds
42# a $(obj) prefix, except for absolute paths
43
44__clean-files := $(wildcard \
45 $(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \
46 $(filter /%, $(__clean-files)))
47
48# as clean-dirs is given relative to the current directory, this adds
49# a $(obj) prefix, except for absolute paths
50
51__clean-dirs := $(wildcard \
52 $(addprefix $(obj)/, $(filter-out /%, $(clean-dirs))) \
53 $(filter /%, $(clean-dirs)))
54
55# ==========================================================================
56
57quiet_cmd_clean = CLEAN $(obj)
58 cmd_clean = rm -f $(__clean-files)
59quiet_cmd_cleandir = CLEAN $(__clean-dirs)
60 cmd_cleandir = rm -rf $(__clean-dirs)
61
62
63__clean: $(subdir-ymn)
64ifneq ($(strip $(__clean-files)),)
65 +$(call cmd,clean)
66endif
67ifneq ($(strip $(__clean-dirs)),)
68 +$(call cmd,cleandir)
69endif
70ifneq ($(strip $(clean-rule)),)
71 +$(clean-rule)
72endif
73 @:
74
75
76# ===========================================================================
77# Generic stuff
78# ===========================================================================
79
80# Descending
81# ---------------------------------------------------------------------------
82
83.PHONY: $(subdir-ymn)
84$(subdir-ymn):
85 $(Q)$(MAKE) $(clean)=$@
86
87# If quiet is set, only print short version of command
88
89cmd = @$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
90
91# Shorthand for $(Q)$(MAKE) scripts/Makefile.clean obj=dir
92# Usage:
93# $(Q)$(MAKE) $(clean)=dir
94clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj