Makefile.clean 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # SPDX-License-Identifier: GPL-2.0
  2. # ==========================================================================
  3. # Cleaning up
  4. # ==========================================================================
  5. src := $(obj)
  6. PHONY := __clean
  7. __clean:
  8. include scripts/Kbuild.include
  9. # The filename Kbuild has precedence over Makefile
  10. kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
  11. include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
  12. # Figure out what we need to build from the various variables
  13. # ==========================================================================
  14. subdir-ymn := $(sort $(subdir-y) $(subdir-m) $(subdir-) \
  15. $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m) $(obj-))))
  16. # Add subdir path
  17. subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
  18. # build a list of files to remove, usually relative to the current
  19. # directory
  20. __clean-files := \
  21. $(clean-files) $(targets) $(hostprogs) $(userprogs) \
  22. $(extra-y) $(extra-m) $(extra-) \
  23. $(always-y) $(always-m) $(always-) \
  24. $(hostprogs-always-y) $(hostprogs-always-m) $(hostprogs-always-) \
  25. $(userprogs-always-y) $(userprogs-always-m) $(userprogs-always-)
  26. # deprecated
  27. __clean-files += $(always) $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
  28. __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
  29. # clean-files is given relative to the current directory, unless it
  30. # starts with $(objtree)/ (which means "./", so do not add "./" unless
  31. # you want to delete a file from the toplevel object directory).
  32. __clean-files := $(wildcard \
  33. $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \
  34. $(filter $(objtree)/%, $(__clean-files)))
  35. # ==========================================================================
  36. quiet_cmd_clean = CLEAN $(obj)
  37. cmd_clean = rm -rf $(__clean-files)
  38. __clean: $(subdir-ymn)
  39. ifneq ($(strip $(__clean-files)),)
  40. $(call cmd,clean)
  41. endif
  42. @:
  43. # ===========================================================================
  44. # Generic stuff
  45. # ===========================================================================
  46. # Descending
  47. # ---------------------------------------------------------------------------
  48. PHONY += $(subdir-ymn)
  49. $(subdir-ymn):
  50. $(Q)$(MAKE) $(clean)=$@
  51. .PHONY: $(PHONY)