18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci# include/asm-generic contains a lot of files that are used
38c2ecf20Sopenharmony_ci# verbatim by several architectures.
48c2ecf20Sopenharmony_ci#
58c2ecf20Sopenharmony_ci# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
68c2ecf20Sopenharmony_ci# and for each file listed in this file with generic-y creates
78c2ecf20Sopenharmony_ci# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciPHONY := all
108c2ecf20Sopenharmony_ciall:
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cisrc := $(subst /generated,,$(obj))
138c2ecf20Sopenharmony_ci-include $(src)/Kbuild
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
168c2ecf20Sopenharmony_ciifneq ($(SRCARCH),um)
178c2ecf20Sopenharmony_ciinclude $(generic)/Kbuild
188c2ecf20Sopenharmony_ciendif
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciinclude scripts/Kbuild.include
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciredundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
238c2ecf20Sopenharmony_ciredundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
248c2ecf20Sopenharmony_ciredundant := $(sort $(redundant))
258c2ecf20Sopenharmony_ci$(if $(redundant),\
268c2ecf20Sopenharmony_ci	$(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci# If arch does not implement mandatory headers, fallback to asm-generic ones.
298c2ecf20Sopenharmony_cimandatory-y := $(filter-out $(generated-y), $(mandatory-y))
308c2ecf20Sopenharmony_cigeneric-y   += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cigeneric-y   := $(addprefix $(obj)/, $(generic-y))
338c2ecf20Sopenharmony_cigenerated-y := $(addprefix $(obj)/, $(generated-y))
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci# Remove stale wrappers when the corresponding files are removed from generic-y
368c2ecf20Sopenharmony_ciold-headers := $(wildcard $(obj)/*.h)
378c2ecf20Sopenharmony_ciunwanted    := $(filter-out $(generic-y) $(generated-y),$(old-headers))
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciquiet_cmd_wrap = WRAP    $@
408c2ecf20Sopenharmony_ci      cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciquiet_cmd_remove = REMOVE  $(unwanted)
438c2ecf20Sopenharmony_ci      cmd_remove = rm -f $(unwanted)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciall: $(generic-y)
468c2ecf20Sopenharmony_ci	$(if $(unwanted),$(call cmd,remove))
478c2ecf20Sopenharmony_ci	@:
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci$(obj)/%.h:
508c2ecf20Sopenharmony_ci	$(call cmd,wrap)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci# Create output directory. Skip it if at least one old header exists
538c2ecf20Sopenharmony_ci# since we know the output directory already exists.
548c2ecf20Sopenharmony_ciifeq ($(old-headers),)
558c2ecf20Sopenharmony_ci$(shell mkdir -p $(obj))
568c2ecf20Sopenharmony_ciendif
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci.PHONY: $(PHONY)
59