blob: c7d2b7acad26c2a2bf52c0d66f5c086d6a51a99c [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 Yamada7cbbbb82019-03-17 11:01:08 +090017redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
18redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
19redundant := $(sort $(redundant))
20$(if $(redundant),\
21 $(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
22
Masahiro Yamada91998732019-01-03 10:10:38 +090023# If arch does not implement mandatory headers, fallback to asm-generic ones.
24mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
25generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
26
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090027generic-y := $(addprefix $(obj)/, $(generic-y))
28generated-y := $(addprefix $(obj)/, $(generated-y))
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020029
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090030# Remove stale wrappers when the corresponding files are removed from generic-y
31old-headers := $(wildcard $(obj)/*.h)
32unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
James Hogancda2c652016-06-24 23:42:24 +010033
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020034quiet_cmd_wrap = WRAP $@
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090035 cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020036
James Hogancda2c652016-06-24 23:42:24 +010037quiet_cmd_remove = REMOVE $(unwanted)
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090038 cmd_remove = rm -f $(unwanted)
James Hogancda2c652016-06-24 23:42:24 +010039
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090040all: $(generic-y)
41 $(if $(unwanted),$(call cmd,remove))
Peter Foley181e9762011-06-08 20:58:32 -040042 @:
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020043
44$(obj)/%.h:
45 $(call cmd,wrap)
James Hogancda2c652016-06-24 23:42:24 +010046
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +090047# Create output directory. Skip it if at least one old header exists
48# since we know the output directory already exists.
49ifeq ($(old-headers),)
50$(shell mkdir -p $(obj))
51endif
52
James Hogancda2c652016-06-24 23:42:24 +010053.PHONY: $(PHONY)