Back to home page

LXR

 
 

    


0001 # ==========================================================================
0002 # Cleaning up
0003 # ==========================================================================
0004 
0005 src := $(obj)
0006 
0007 PHONY := __clean
0008 __clean:
0009 
0010 include scripts/Kbuild.include
0011 
0012 # The filename Kbuild has precedence over Makefile
0013 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
0014 include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile) 
0015 
0016 # Figure out what we need to build from the various variables
0017 # ==========================================================================
0018 
0019 __subdir-y      := $(patsubst %/,%,$(filter %/, $(obj-y)))
0020 subdir-y        += $(__subdir-y)
0021 __subdir-m      := $(patsubst %/,%,$(filter %/, $(obj-m)))
0022 subdir-m        += $(__subdir-m)
0023 __subdir-       := $(patsubst %/,%,$(filter %/, $(obj-)))
0024 subdir-         += $(__subdir-)
0025 
0026 # Subdirectories we need to descend into
0027 
0028 subdir-ym       := $(sort $(subdir-y) $(subdir-m))
0029 subdir-ymn      := $(sort $(subdir-ym) $(subdir-))
0030 
0031 # Add subdir path
0032 
0033 subdir-ymn      := $(addprefix $(obj)/,$(subdir-ymn))
0034 
0035 # build a list of files to remove, usually relative to the current
0036 # directory
0037 
0038 __clean-files   := $(extra-y) $(extra-m) $(extra-)       \
0039                    $(always) $(targets) $(clean-files)   \
0040                    $(host-progs)                         \
0041                    $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
0042                    $(hostlibs-y) $(hostlibs-m) $(hostlibs-) \
0043                    $(hostcxxlibs-y) $(hostcxxlibs-m)
0044 
0045 __clean-files   := $(filter-out $(no-clean-files), $(__clean-files))
0046 
0047 # clean-files is given relative to the current directory, unless it
0048 # starts with $(objtree)/ (which means "./", so do not add "./" unless
0049 # you want to delete a file from the toplevel object directory).
0050 
0051 __clean-files   := $(wildcard                                               \
0052                    $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \
0053                    $(filter $(objtree)/%, $(__clean-files)))
0054 
0055 # same as clean-files
0056 
0057 __clean-dirs    := $(wildcard                                               \
0058                    $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(clean-dirs)))    \
0059                    $(filter $(objtree)/%, $(clean-dirs)))
0060 
0061 # ==========================================================================
0062 
0063 quiet_cmd_clean    = CLEAN   $(obj)
0064       cmd_clean    = rm -f $(__clean-files)
0065 quiet_cmd_cleandir = CLEAN   $(__clean-dirs)
0066       cmd_cleandir = rm -rf $(__clean-dirs)
0067 
0068 
0069 __clean: $(subdir-ymn)
0070 ifneq ($(strip $(__clean-files)),)
0071         +$(call cmd,clean)
0072 endif
0073 ifneq ($(strip $(__clean-dirs)),)
0074         +$(call cmd,cleandir)
0075 endif
0076         @:
0077 
0078 
0079 # ===========================================================================
0080 # Generic stuff
0081 # ===========================================================================
0082 
0083 # Descending
0084 # ---------------------------------------------------------------------------
0085 
0086 PHONY += $(subdir-ymn)
0087 $(subdir-ymn):
0088         $(Q)$(MAKE) $(clean)=$@
0089 
0090 # Declare the contents of the .PHONY variable as phony.  We keep that
0091 # information in a variable se we can use it in if_changed and friends.
0092 
0093 .PHONY: $(PHONY)