Makefile.clean 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # ==========================================================================
  2. # Cleaning up
  3. # ==========================================================================
  4. src := $(obj)
  5. PHONY := __clean
  6. __clean:
  7. include scripts/Kbuild.include
  8. # The filename Kbuild has precedence over Makefile
  9. kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
  10. include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
  11. # Figure out what we need to build from the various variables
  12. # ==========================================================================
  13. __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
  14. subdir-y += $(__subdir-y)
  15. __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
  16. subdir-m += $(__subdir-m)
  17. __subdir- := $(patsubst %/,%,$(filter %/, $(obj-)))
  18. subdir- += $(__subdir-)
  19. # Subdirectories we need to descend into
  20. subdir-ym := $(sort $(subdir-y) $(subdir-m))
  21. subdir-ymn := $(sort $(subdir-ym) $(subdir-))
  22. # Add subdir path
  23. subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
  24. # build a list of files to remove, usually relative to the current
  25. # directory
  26. __clean-files := $(extra-y) $(extra-m) $(extra-) \
  27. $(always) $(targets) $(clean-files) \
  28. $(host-progs) \
  29. $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
  30. $(hostlibs-y) $(hostlibs-m) $(hostlibs-) \
  31. $(hostcxxlibs-y) $(hostcxxlibs-m)
  32. __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
  33. # clean-files is given relative to the current directory, unless it
  34. # starts with $(objtree)/ (which means "./", so do not add "./" unless
  35. # you want to delete a file from the toplevel object directory).
  36. __clean-files := $(wildcard \
  37. $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \
  38. $(filter $(objtree)/%, $(__clean-files)))
  39. # same as clean-files
  40. __clean-dirs := $(wildcard \
  41. $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(clean-dirs))) \
  42. $(filter $(objtree)/%, $(clean-dirs)))
  43. # ==========================================================================
  44. quiet_cmd_clean = CLEAN $(obj)
  45. cmd_clean = rm -f $(__clean-files)
  46. quiet_cmd_cleandir = CLEAN $(__clean-dirs)
  47. cmd_cleandir = rm -rf $(__clean-dirs)
  48. __clean: $(subdir-ymn)
  49. ifneq ($(strip $(__clean-files)),)
  50. +$(call cmd,clean)
  51. endif
  52. ifneq ($(strip $(__clean-dirs)),)
  53. +$(call cmd,cleandir)
  54. endif
  55. @:
  56. # ===========================================================================
  57. # Generic stuff
  58. # ===========================================================================
  59. # Descending
  60. # ---------------------------------------------------------------------------
  61. PHONY += $(subdir-ymn)
  62. $(subdir-ymn):
  63. $(Q)$(MAKE) $(clean)=$@
  64. # Declare the contents of the .PHONY variable as phony. We keep that
  65. # information in a variable se we can use it in if_changed and friends.
  66. .PHONY: $(PHONY)