1 # SPDX-License-Identifier: GPL-2.0
2 # include/asm-generic contains a lot of files that are used
3 # verbatim by several architectures.
5 # This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
6 # and for each file listed in this file with generic-y creates
7 # a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
12 src := $(subst /generated,,$(obj))
13 -include $(src)/Kbuild
15 include scripts/Kbuild.include
17 # If arch does not implement mandatory headers, fallback to asm-generic ones.
18 mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
19 generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
21 generic-y := $(addprefix $(obj)/, $(generic-y))
22 generated-y := $(addprefix $(obj)/, $(generated-y))
24 # Remove stale wrappers when the corresponding files are removed from generic-y
25 old-headers := $(wildcard $(obj)/*.h)
26 unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
28 quiet_cmd_wrap = WRAP $@
29 cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
31 quiet_cmd_remove = REMOVE $(unwanted)
32 cmd_remove = rm -f $(unwanted)
35 $(if $(unwanted),$(call cmd,remove))
41 # Create output directory. Skip it if at least one old header exists
42 # since we know the output directory already exists.
43 ifeq ($(old-headers),)
44 $(shell mkdir -p $(obj))