blob: 82ad63dcd62b4733ab7370306ceb4407575651eb [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001# SPDX-License-Identifier: GPL-2.0
2# include/asm-generic contains a lot of files that are used
3# verbatim by several architectures.
4#
David Brazdil0f672f62019-12-10 10:32:29 +00005# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006# and for each file listed in this file with generic-y creates
David Brazdil0f672f62019-12-10 10:32:29 +00007# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00008
9PHONY := all
10all:
11
David Brazdil0f672f62019-12-10 10:32:29 +000012src := $(subst /generated,,$(obj))
13-include $(src)/Kbuild
14
15# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
16ifneq ($(SRCARCH),um)
17include $(generic)/Kbuild
18endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000019
20include scripts/Kbuild.include
21
David Brazdil0f672f62019-12-10 10:32:29 +000022redundant := $(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)))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000027
David Brazdil0f672f62019-12-10 10:32:29 +000028# 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
32generic-y := $(addprefix $(obj)/, $(generic-y))
33generated-y := $(addprefix $(obj)/, $(generated-y))
34
35# 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))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000038
39quiet_cmd_wrap = WRAP $@
David Brazdil0f672f62019-12-10 10:32:29 +000040 cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000041
42quiet_cmd_remove = REMOVE $(unwanted)
David Brazdil0f672f62019-12-10 10:32:29 +000043 cmd_remove = rm -f $(unwanted)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000044
David Brazdil0f672f62019-12-10 10:32:29 +000045all: $(generic-y)
46 $(if $(unwanted),$(call cmd,remove))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000047 @:
48
49$(obj)/%.h:
50 $(call cmd,wrap)
51
David Brazdil0f672f62019-12-10 10:32:29 +000052# 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
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000058.PHONY: $(PHONY)