blob: a62d2823f6cfe6ffe7f269131fd3f19f78f2516c [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
15include scripts/Kbuild.include
16
Masahiro Yamada91998732019-01-03 10:10:38 +090017# If arch does not implement mandatory headers, fallback to asm-generic ones.
18mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
19generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
20
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090021generic-y := $(addprefix $(obj)/, $(generic-y))
22generated-y := $(addprefix $(obj)/, $(generated-y))
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020023
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090024# Remove stale wrappers when the corresponding files are removed from generic-y
25old-headers := $(wildcard $(obj)/*.h)
26unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
James Hogancda2c652016-06-24 23:42:24 +010027
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020028quiet_cmd_wrap = WRAP $@
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090029 cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020030
James Hogancda2c652016-06-24 23:42:24 +010031quiet_cmd_remove = REMOVE $(unwanted)
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090032 cmd_remove = rm -f $(unwanted)
James Hogancda2c652016-06-24 23:42:24 +010033
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090034all: $(generic-y)
35 $(if $(unwanted),$(call cmd,remove))
Peter Foley181e9762011-06-08 20:58:32 -040036 @:
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020037
38$(obj)/%.h:
39 $(call cmd,wrap)
James Hogancda2c652016-06-24 23:42:24 +010040
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090041# Create output directory. Skip it if at least one old header exists
42# since we know the output directory already exists.
43ifeq ($(old-headers),)
44$(shell mkdir -p $(obj))
45endif
46
James Hogancda2c652016-06-24 23:42:24 +010047.PHONY: $(PHONY)