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