Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 # ==========================================================================
0003 # Cleaning up
0004 # ==========================================================================
0005 
0006 src := $(obj)
0007 
0008 PHONY := __clean
0009 __clean:
0010 
0011 include $(srctree)/scripts/Kbuild.include
0012 
0013 # The filename Kbuild has precedence over Makefile
0014 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
0015 include $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile) 
0016 
0017 # Figure out what we need to build from the various variables
0018 # ==========================================================================
0019 
0020 subdir-ymn := $(sort $(subdir-y) $(subdir-m) $(subdir-) \
0021                 $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m) $(obj-))))
0022 
0023 # Add subdir path
0024 
0025 subdir-ymn      := $(addprefix $(obj)/,$(subdir-ymn))
0026 
0027 # build a list of files to remove, usually relative to the current
0028 # directory
0029 
0030 __clean-files   := \
0031         $(clean-files) $(targets) $(hostprogs) $(userprogs) \
0032         $(extra-y) $(extra-m) $(extra-) \
0033         $(always-y) $(always-m) $(always-) \
0034         $(hostprogs-always-y) $(hostprogs-always-m) $(hostprogs-always-) \
0035         $(userprogs-always-y) $(userprogs-always-m) $(userprogs-always-)
0036 
0037 __clean-files   := $(filter-out $(no-clean-files), $(__clean-files))
0038 
0039 __clean-files   := $(wildcard $(addprefix $(obj)/, $(__clean-files)))
0040 
0041 # ==========================================================================
0042 
0043 quiet_cmd_clean = CLEAN   $(obj)
0044       cmd_clean = rm -rf $(__clean-files)
0045 
0046 __clean: $(subdir-ymn)
0047 ifneq ($(strip $(__clean-files)),)
0048         $(call cmd,clean)
0049 endif
0050         @:
0051 
0052 
0053 # ===========================================================================
0054 # Generic stuff
0055 # ===========================================================================
0056 
0057 # Descending
0058 # ---------------------------------------------------------------------------
0059 
0060 PHONY += $(subdir-ymn)
0061 $(subdir-ymn):
0062         $(Q)$(MAKE) $(clean)=$@
0063 
0064 .PHONY: $(PHONY)