b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) # SPDX-License-Identifier: GPL-2.0
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 2) # ==========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 3) # Cleaning up
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 4) # ==========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 5)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 6) src := $(obj)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 7)
4f1933620f571 (Paul Smith 2006-03-05 17:14:10 -0500 8) PHONY := __clean
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 9) __clean:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 10)
3204a7fb98a3b (Masahiro Yamada 2021-02-28 15:10:26 +0900 11) include $(srctree)/scripts/Kbuild.include
2315c6e422781 (Sam Ravnborg 2005-07-25 22:41:12 +0000 12)
2a691470345a0 (Sam Ravnborg 2005-07-25 20:26:04 +0000 13) # The filename Kbuild has precedence over Makefile
db8c1a7b2ca25 (Sam Ravnborg 2005-07-27 22:11:01 +0200 14) kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
db8c1a7b2ca25 (Sam Ravnborg 2005-07-27 22:11:01 +0200 15) include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 16)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 17) # Figure out what we need to build from the various variables
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 18) # ==========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19)
4ca76945b037c (Masahiro Yamada 2019-08-25 10:31:39 +0900 20) subdir-ymn := $(sort $(subdir-y) $(subdir-m) $(subdir-) \
4ca76945b037c (Masahiro Yamada 2019-08-25 10:31:39 +0900 21) $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m) $(obj-))))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 22)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 23) # Add subdir path
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 24)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 25) subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 26)
3156fd0529b52 (Robert P. J. Day 2008-02-18 04:48:20 -0500 27) # build a list of files to remove, usually relative to the current
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 28) # directory
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 29)
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 30) __clean-files := \
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 31) $(clean-files) $(targets) $(hostprogs) $(userprogs) \
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 32) $(extra-y) $(extra-m) $(extra-) \
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 33) $(always-y) $(always-m) $(always-) \
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 34) $(hostprogs-always-y) $(hostprogs-always-m) $(hostprogs-always-) \
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 35) $(userprogs-always-y) $(userprogs-always-m) $(userprogs-always-)
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 36)
ef8ff89b58546 (Michal Marek 2010-03-09 16:00:20 +0100 37) __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
ef8ff89b58546 (Michal Marek 2010-03-09 16:00:20 +0100 38)
a16c5f99a28c9 (Michal Marek 2014-12-31 16:29:35 +0100 39) # clean-files is given relative to the current directory, unless it
a16c5f99a28c9 (Michal Marek 2014-12-31 16:29:35 +0100 40) # starts with $(objtree)/ (which means "./", so do not add "./" unless
a16c5f99a28c9 (Michal Marek 2014-12-31 16:29:35 +0100 41) # you want to delete a file from the toplevel object directory).
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 42)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 43) __clean-files := $(wildcard \
a16c5f99a28c9 (Michal Marek 2014-12-31 16:29:35 +0100 44) $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \
a16c5f99a28c9 (Michal Marek 2014-12-31 16:29:35 +0100 45) $(filter $(objtree)/%, $(__clean-files)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 46)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 47) # ==========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 48)
1634f2bfdb846 (Masahiro Yamada 2019-08-25 10:31:27 +0900 49) quiet_cmd_clean = CLEAN $(obj)
1634f2bfdb846 (Masahiro Yamada 2019-08-25 10:31:27 +0900 50) cmd_clean = rm -rf $(__clean-files)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 51)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 52) __clean: $(subdir-ymn)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 53) ifneq ($(strip $(__clean-files)),)
687ac1fa3164c (Masahiro Yamada 2019-08-25 10:31:28 +0900 54) $(call cmd,clean)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 55) endif
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 56) @:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 57)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 58)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 59) # ===========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 60) # Generic stuff
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 61) # ===========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 62)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 63) # Descending
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 64) # ---------------------------------------------------------------------------
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 65)
4f1933620f571 (Paul Smith 2006-03-05 17:14:10 -0500 66) PHONY += $(subdir-ymn)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 67) $(subdir-ymn):
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 68) $(Q)$(MAKE) $(clean)=$@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 69)
4f1933620f571 (Paul Smith 2006-03-05 17:14:10 -0500 70) .PHONY: $(PHONY)