Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | # ========================================================================== |
2 | # Cleaning up | |
3 | # ========================================================================== | |
4 | ||
5 | src := $(obj) | |
6 | ||
7 | .PHONY: __clean | |
8 | __clean: | |
9 | ||
2a691470 SR |
10 | # The filename Kbuild has precedence over Makefile |
11 | include $(if $(wildcard $(srctree)/$(src)/Kbuild), \ | |
12 | $(srctree)/$(src)/Kbuild, $(srctree)/$(src)/Makefile) | |
1da177e4 LT |
13 | |
14 | # Figure out what we need to build from the various variables | |
15 | # ========================================================================== | |
16 | ||
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-) | |
25 | ||
26 | # Subdirectories we need to descend into | |
27 | ||
28 | subdir-ym := $(sort $(subdir-y) $(subdir-m)) | |
29 | subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-)) | |
30 | ||
31 | # Add subdir path | |
32 | ||
33 | subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) | |
34 | ||
35 | # build a list of files to remove, usually releative to the current | |
36 | # directory | |
37 | ||
38 | __clean-files := $(extra-y) $(EXTRA_TARGETS) $(always) \ | |
39 | $(targets) $(clean-files) \ | |
40 | $(host-progs) \ | |
41 | $(hostprogs-y) $(hostprogs-m) $(hostprogs-) | |
42 | ||
43 | # as clean-files is given relative to the current directory, this adds | |
44 | # a $(obj) prefix, except for absolute paths | |
45 | ||
46 | __clean-files := $(wildcard \ | |
47 | $(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \ | |
48 | $(filter /%, $(__clean-files))) | |
49 | ||
50 | # as clean-dirs is given relative to the current directory, this adds | |
51 | # a $(obj) prefix, except for absolute paths | |
52 | ||
53 | __clean-dirs := $(wildcard \ | |
54 | $(addprefix $(obj)/, $(filter-out /%, $(clean-dirs))) \ | |
55 | $(filter /%, $(clean-dirs))) | |
56 | ||
57 | # ========================================================================== | |
58 | ||
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) | |
63 | ||
64 | ||
65 | __clean: $(subdir-ymn) | |
66 | ifneq ($(strip $(__clean-files)),) | |
67 | +$(call cmd,clean) | |
68 | endif | |
69 | ifneq ($(strip $(__clean-dirs)),) | |
70 | +$(call cmd,cleandir) | |
71 | endif | |
72 | ifneq ($(strip $(clean-rule)),) | |
73 | +$(clean-rule) | |
74 | endif | |
75 | @: | |
76 | ||
77 | ||
78 | # =========================================================================== | |
79 | # Generic stuff | |
80 | # =========================================================================== | |
81 | ||
82 | # Descending | |
83 | # --------------------------------------------------------------------------- | |
84 | ||
85 | .PHONY: $(subdir-ymn) | |
86 | $(subdir-ymn): | |
87 | $(Q)$(MAKE) $(clean)=$@ | |
88 | ||
89 | # If quiet is set, only print short version of command | |
90 | ||
91 | cmd = @$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))' &&) $(cmd_$(1)) | |
92 | ||
93 | # Shorthand for $(Q)$(MAKE) scripts/Makefile.clean obj=dir | |
94 | # Usage: | |
95 | # $(Q)$(MAKE) $(clean)=dir | |
96 | clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj |