blob: 1486abf34c7c9063fa9ffc0a417ddb64f5b346a1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +02002# include/asm-generic contains a lot of files that are used
3# verbatim by several architectures.
4#
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +09005# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +02006# and for each file listed in this file with generic-y creates
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +09007# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +02008
Masahiro Yamadaa7d34df2017-10-11 12:52:29 +09009PHONY := all
10all:
11
Masahiro Yamadab1992c32024-04-27 23:55:02 +090012src := $(srctree)/$(subst /generated,,$(obj))
Masahiro Yamadaa2430b22022-11-19 04:15:50 +090013
14include $(srctree)/scripts/Kbuild.include
15-include $(kbuild-file)
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020016
Masahiro Yamada037fc332019-03-17 11:01:09 +090017# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
18ifneq ($(SRCARCH),um)
Masahiro Yamada3204a7f2021-02-28 15:10:26 +090019include $(srctree)/$(generic)/Kbuild
Masahiro Yamada037fc332019-03-17 11:01:09 +090020endif
21
Masahiro Yamada7cbbbb82019-03-17 11:01:08 +090022redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
Masahiro Yamadab1992c32024-04-27 23:55:02 +090023redundant += $(foreach f, $(generic-y), $(if $(wildcard $(src)/$(f)),$(f)))
Masahiro Yamada7cbbbb82019-03-17 11:01:08 +090024redundant := $(sort $(redundant))
25$(if $(redundant),\
26 $(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
27
Masahiro Yamada91998732019-01-03 10:10:38 +090028# If arch does not implement mandatory headers, fallback to asm-generic ones.
29mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
Masahiro Yamadab1992c32024-04-27 23:55:02 +090030generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(src)/$(f)),,$(f)))
Masahiro Yamada91998732019-01-03 10:10:38 +090031
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090032generic-y := $(addprefix $(obj)/, $(generic-y))
33generated-y := $(addprefix $(obj)/, $(generated-y))
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020034
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090035# Remove stale wrappers when the corresponding files are removed from generic-y
36old-headers := $(wildcard $(obj)/*.h)
37unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
James Hogancda2c652016-06-24 23:42:24 +010038
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020039quiet_cmd_wrap = WRAP $@
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090040 cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020041
James Hogancda2c652016-06-24 23:42:24 +010042quiet_cmd_remove = REMOVE $(unwanted)
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090043 cmd_remove = rm -f $(unwanted)
James Hogancda2c652016-06-24 23:42:24 +010044
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090045all: $(generic-y)
46 $(if $(unwanted),$(call cmd,remove))
Peter Foley181e9762011-06-08 20:58:32 -040047 @:
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020048
49$(obj)/%.h:
50 $(call cmd,wrap)
James Hogancda2c652016-06-24 23:42:24 +010051
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090052# Create output directory. Skip it if at least one old header exists
53# since we know the output directory already exists.
54ifeq ($(old-headers),)
55$(shell mkdir -p $(obj))
56endif
57
James Hogancda2c652016-06-24 23:42:24 +010058.PHONY: $(PHONY)