Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 2 | # include/asm-generic contains a lot of files that are used |
| 3 | # verbatim by several architectures. |
| 4 | # |
Masahiro Yamada | 7d0e5c2 | 2018-12-05 20:28:04 +0900 | [diff] [blame] | 5 | # This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 6 | # and for each file listed in this file with generic-y creates |
Masahiro Yamada | 7d0e5c2 | 2018-12-05 20:28:04 +0900 | [diff] [blame] | 7 | # a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm. |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 8 | |
Masahiro Yamada | a7d34df | 2017-10-11 12:52:29 +0900 | [diff] [blame] | 9 | PHONY := all |
| 10 | all: |
| 11 | |
Masahiro Yamada | b1992c3 | 2024-04-27 23:55:02 +0900 | [diff] [blame] | 12 | src := $(srctree)/$(subst /generated,,$(obj)) |
Masahiro Yamada | a2430b2 | 2022-11-19 04:15:50 +0900 | [diff] [blame] | 13 | |
| 14 | include $(srctree)/scripts/Kbuild.include |
| 15 | -include $(kbuild-file) |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 16 | |
Masahiro Yamada | 037fc33 | 2019-03-17 11:01:09 +0900 | [diff] [blame] | 17 | # $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case. |
| 18 | ifneq ($(SRCARCH),um) |
Masahiro Yamada | 3204a7f | 2021-02-28 15:10:26 +0900 | [diff] [blame] | 19 | include $(srctree)/$(generic)/Kbuild |
Masahiro Yamada | 037fc33 | 2019-03-17 11:01:09 +0900 | [diff] [blame] | 20 | endif |
| 21 | |
Masahiro Yamada | 7cbbbb8 | 2019-03-17 11:01:08 +0900 | [diff] [blame] | 22 | redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y)) |
Masahiro Yamada | b1992c3 | 2024-04-27 23:55:02 +0900 | [diff] [blame] | 23 | redundant += $(foreach f, $(generic-y), $(if $(wildcard $(src)/$(f)),$(f))) |
Masahiro Yamada | 7cbbbb8 | 2019-03-17 11:01:08 +0900 | [diff] [blame] | 24 | redundant := $(sort $(redundant)) |
| 25 | $(if $(redundant),\ |
| 26 | $(warning redundant generic-y found in $(src)/Kbuild: $(redundant))) |
| 27 | |
Masahiro Yamada | 9199873 | 2019-01-03 10:10:38 +0900 | [diff] [blame] | 28 | # If arch does not implement mandatory headers, fallback to asm-generic ones. |
| 29 | mandatory-y := $(filter-out $(generated-y), $(mandatory-y)) |
Masahiro Yamada | b1992c3 | 2024-04-27 23:55:02 +0900 | [diff] [blame] | 30 | generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(src)/$(f)),,$(f))) |
Masahiro Yamada | 9199873 | 2019-01-03 10:10:38 +0900 | [diff] [blame] | 31 | |
Masahiro Yamada | 7d0e5c2 | 2018-12-05 20:28:04 +0900 | [diff] [blame] | 32 | generic-y := $(addprefix $(obj)/, $(generic-y)) |
| 33 | generated-y := $(addprefix $(obj)/, $(generated-y)) |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 34 | |
Masahiro Yamada | 7d0e5c2 | 2018-12-05 20:28:04 +0900 | [diff] [blame] | 35 | # Remove stale wrappers when the corresponding files are removed from generic-y |
| 36 | old-headers := $(wildcard $(obj)/*.h) |
| 37 | unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers)) |
James Hogan | cda2c65 | 2016-06-24 23:42:24 +0100 | [diff] [blame] | 38 | |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 39 | quiet_cmd_wrap = WRAP $@ |
Masahiro Yamada | 7d0e5c2 | 2018-12-05 20:28:04 +0900 | [diff] [blame] | 40 | cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@ |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 41 | |
James Hogan | cda2c65 | 2016-06-24 23:42:24 +0100 | [diff] [blame] | 42 | quiet_cmd_remove = REMOVE $(unwanted) |
Masahiro Yamada | 7d0e5c2 | 2018-12-05 20:28:04 +0900 | [diff] [blame] | 43 | cmd_remove = rm -f $(unwanted) |
James Hogan | cda2c65 | 2016-06-24 23:42:24 +0100 | [diff] [blame] | 44 | |
Masahiro Yamada | 7d0e5c2 | 2018-12-05 20:28:04 +0900 | [diff] [blame] | 45 | all: $(generic-y) |
| 46 | $(if $(unwanted),$(call cmd,remove)) |
Peter Foley | 181e976 | 2011-06-08 20:58:32 -0400 | [diff] [blame] | 47 | @: |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 48 | |
| 49 | $(obj)/%.h: |
| 50 | $(call cmd,wrap) |
James Hogan | cda2c65 | 2016-06-24 23:42:24 +0100 | [diff] [blame] | 51 | |
Masahiro Yamada | 7d0e5c2 | 2018-12-05 20:28:04 +0900 | [diff] [blame] | 52 | # Create output directory. Skip it if at least one old header exists |
| 53 | # since we know the output directory already exists. |
| 54 | ifeq ($(old-headers),) |
| 55 | $(shell mkdir -p $(obj)) |
| 56 | endif |
| 57 | |
James Hogan | cda2c65 | 2016-06-24 23:42:24 +0100 | [diff] [blame] | 58 | .PHONY: $(PHONY) |