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