Makefile.clean 1.88 KB
Newer Older
1 2 3
# ==========================================================================
# Cleaning up
# ==========================================================================
4 5 6 7 8 9 10 11

src := $(obj)

.PHONY: __clean
__clean:

include $(obj)/Makefile

12 13 14
# Figure out what we need to build from the various variables
# ==========================================================================

15 16 17 18 19 20 21 22 23
__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y	+= $(__subdir-y)
__subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
subdir-m	+= $(__subdir-m)
__subdir-n	:= $(patsubst %/,%,$(filter %/, $(obj-n)))
subdir-n	+= $(__subdir-n)
__subdir-	:= $(patsubst %/,%,$(filter %/, $(obj-)))
subdir-		+= $(__subdir-)

24 25
# Subdirectories we need to descend into

26 27 28
subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
subdir-ymn      := $(sort $(subdir-ym) $(subdir-n) $(subdir-))

29 30
# Add subdir path

31
subdir-ymn	:= $(addprefix $(obj)/,$(subdir-ymn))
32 33 34
__clean-files	:= $(wildcard $(addprefix $(obj)/, \
		   $(extra-y) $(EXTRA_TARGETS) $(always) $(host-progs) \
		   $(targets) $(clean-files)))
35

36 37
# ==========================================================================

38 39
quiet_cmd_clean = CLEAN   $(obj)
      cmd_clean = rm -f $(__clean-files); $(clean-rule)
40

41 42
__clean: $(subdir-ymn)
ifneq ($(strip $(__clean-files) $(clean-rule)),)
43
	+$(call cmd,clean)
44
else
45
	@:
46 47
endif

48 49 50 51 52 53
# ===========================================================================
# Generic stuff
# ===========================================================================

# Descending
# ---------------------------------------------------------------------------
54

55
.PHONY: $(subdir-ymn)
56
$(subdir-ymn):
57
	$(Q)$(MAKE) $(clean)=$@
58

59 60 61
# If quiet is set, only print short version of command

cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
62 63 64 65 66

# Shorthand for $(Q)$(MAKE) scripts/Makefile.clean obj=dir
# Usage:
# $(Q)$(MAKE) $(clean)=dir
clean := -f scripts/Makefile.clean obj