162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci# include/asm-generic contains a lot of files that are used 362306a36Sopenharmony_ci# verbatim by several architectures. 462306a36Sopenharmony_ci# 562306a36Sopenharmony_ci# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild 662306a36Sopenharmony_ci# and for each file listed in this file with generic-y creates 762306a36Sopenharmony_ci# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm. 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciPHONY := all 1062306a36Sopenharmony_ciall: 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_cisrc := $(subst /generated,,$(obj)) 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciinclude $(srctree)/scripts/Kbuild.include 1562306a36Sopenharmony_ci-include $(kbuild-file) 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case. 1862306a36Sopenharmony_ciifneq ($(SRCARCH),um) 1962306a36Sopenharmony_ciinclude $(srctree)/$(generic)/Kbuild 2062306a36Sopenharmony_ciendif 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciredundant := $(filter $(mandatory-y) $(generated-y), $(generic-y)) 2362306a36Sopenharmony_ciredundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f))) 2462306a36Sopenharmony_ciredundant := $(sort $(redundant)) 2562306a36Sopenharmony_ci$(if $(redundant),\ 2662306a36Sopenharmony_ci $(warning redundant generic-y found in $(src)/Kbuild: $(redundant))) 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci# If arch does not implement mandatory headers, fallback to asm-generic ones. 2962306a36Sopenharmony_cimandatory-y := $(filter-out $(generated-y), $(mandatory-y)) 3062306a36Sopenharmony_cigeneric-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f))) 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_cigeneric-y := $(addprefix $(obj)/, $(generic-y)) 3362306a36Sopenharmony_cigenerated-y := $(addprefix $(obj)/, $(generated-y)) 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci# Remove stale wrappers when the corresponding files are removed from generic-y 3662306a36Sopenharmony_ciold-headers := $(wildcard $(obj)/*.h) 3762306a36Sopenharmony_ciunwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers)) 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ciquiet_cmd_wrap = WRAP $@ 4062306a36Sopenharmony_ci cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@ 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ciquiet_cmd_remove = REMOVE $(unwanted) 4362306a36Sopenharmony_ci cmd_remove = rm -f $(unwanted) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ciall: $(generic-y) 4662306a36Sopenharmony_ci $(if $(unwanted),$(call cmd,remove)) 4762306a36Sopenharmony_ci @: 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci$(obj)/%.h: 5062306a36Sopenharmony_ci $(call cmd,wrap) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci# Create output directory. Skip it if at least one old header exists 5362306a36Sopenharmony_ci# since we know the output directory already exists. 5462306a36Sopenharmony_ciifeq ($(old-headers),) 5562306a36Sopenharmony_ci$(shell mkdir -p $(obj)) 5662306a36Sopenharmony_ciendif 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci.PHONY: $(PHONY) 59