Makefile.clean 3.0 KB

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