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 | 3204a7f | 2021-02-28 15:10:26 +0900 | [diff] [blame] | 11 | include $(srctree)/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 | |
Michal Marek | ef8ff89 | 2010-03-09 16:00:20 +0100 | [diff] [blame] | 37 | __clean-files := $(filter-out $(no-clean-files), $(__clean-files)) |
| 38 | |
Michal Marek | a16c5f9 | 2014-12-31 16:29:35 +0100 | [diff] [blame] | 39 | # clean-files is given relative to the current directory, unless it |
| 40 | # starts with $(objtree)/ (which means "./", so do not add "./" unless |
| 41 | # you want to delete a file from the toplevel object directory). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | __clean-files := $(wildcard \ |
Michal Marek | a16c5f9 | 2014-12-31 16:29:35 +0100 | [diff] [blame] | 44 | $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \ |
| 45 | $(filter $(objtree)/%, $(__clean-files))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | # ========================================================================== |
| 48 | |
Masahiro Yamada | 1634f2b | 2019-08-25 10:31:27 +0900 | [diff] [blame] | 49 | quiet_cmd_clean = CLEAN $(obj) |
| 50 | cmd_clean = rm -rf $(__clean-files) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | __clean: $(subdir-ymn) |
| 53 | ifneq ($(strip $(__clean-files)),) |
Masahiro Yamada | 687ac1f | 2019-08-25 10:31:28 +0900 | [diff] [blame] | 54 | $(call cmd,clean) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | @: |
| 57 | |
| 58 | |
| 59 | # =========================================================================== |
| 60 | # Generic stuff |
| 61 | # =========================================================================== |
| 62 | |
| 63 | # Descending |
| 64 | # --------------------------------------------------------------------------- |
| 65 | |
Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 66 | PHONY += $(subdir-ymn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | $(subdir-ymn): |
| 68 | $(Q)$(MAKE) $(clean)=$@ |
| 69 | |
Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 70 | .PHONY: $(PHONY) |