Makefile.clean 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # SPDX-License-Identifier: GPL-2.0
  2. # ==========================================================================
  3. # Cleaning up
  4. # ==========================================================================
  5. src := $(srcroot)/$(obj)
  6. PHONY := __clean
  7. __clean:
  8. include $(srctree)/scripts/Kbuild.include
  9. include $(kbuild-file)
  10. # Figure out what we need to build from the various variables
  11. # ==========================================================================
  12. subdir-ymn := $(sort $(subdir-y) $(subdir-m) $(subdir-) \
  13. $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m) $(obj-))))
  14. # Add subdir path
  15. subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
  16. # build a list of files to remove, usually relative to the current
  17. # directory
  18. __clean-files := \
  19. $(clean-files) $(targets) $(hostprogs) $(userprogs) \
  20. $(extra-y) $(extra-m) $(extra-) \
  21. $(always-y) $(always-m) $(always-) \
  22. $(hostprogs-always-y) $(hostprogs-always-m) $(hostprogs-always-) \
  23. $(userprogs-always-y) $(userprogs-always-m) $(userprogs-always-)
  24. __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
  25. __clean-files := $(wildcard $(addprefix $(obj)/, $(__clean-files)))
  26. # ==========================================================================
  27. # To make this rule robust against "Argument list too long" error,
  28. # remove $(obj)/ prefix, and restore it by a shell command.
  29. quiet_cmd_clean = CLEAN $(obj)
  30. cmd_clean = printf '$(obj)/%s ' $(patsubst $(obj)/%,%,$(__clean-files)) | xargs rm -rf
  31. __clean: $(subdir-ymn)
  32. ifneq ($(strip $(__clean-files)),)
  33. $(call cmd,clean)
  34. endif
  35. @:
  36. # ===========================================================================
  37. # Generic stuff
  38. # ===========================================================================
  39. # Descending
  40. # ---------------------------------------------------------------------------
  41. PHONY += $(subdir-ymn)
  42. $(subdir-ymn):
  43. $(Q)$(MAKE) $(clean)=$@
  44. .PHONY: $(PHONY)