blob: 1d501c57f9eff9b595d79433d14a063540ba2f87 [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 Yamada7d0e5c22018-12-05 20:28:04 +090012src := $(subst /generated,,$(obj))
13-include $(src)/Kbuild
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020014
Masahiro Yamada037fc332019-03-17 11:01:09 +090015# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
16ifneq ($(SRCARCH),um)
Masahiro Yamada3204a7f2021-02-28 15:10:26 +090017include $(srctree)/$(generic)/Kbuild
Masahiro Yamada037fc332019-03-17 11:01:09 +090018endif
19
Masahiro Yamada3204a7f2021-02-28 15:10:26 +090020include $(srctree)/scripts/Kbuild.include
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020021
Masahiro Yamada7cbbbb82019-03-17 11:01:08 +090022redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
23redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
24redundant := $(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))
30generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
31
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)