^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # include/asm-generic contains a lot of files that are used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) # verbatim by several architectures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # and for each file listed in this file with generic-y creates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) PHONY := all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) src := $(subst /generated,,$(obj))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) -include $(src)/Kbuild
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ifneq ($(SRCARCH),um)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) include $(generic)/Kbuild
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) include scripts/Kbuild.include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) redundant := $(sort $(redundant))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) $(if $(redundant),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) $(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) # If arch does not implement mandatory headers, fallback to asm-generic ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) generic-y := $(addprefix $(obj)/, $(generic-y))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) generated-y := $(addprefix $(obj)/, $(generated-y))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) # Remove stale wrappers when the corresponding files are removed from generic-y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) old-headers := $(wildcard $(obj)/*.h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) quiet_cmd_wrap = WRAP $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) quiet_cmd_remove = REMOVE $(unwanted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) cmd_remove = rm -f $(unwanted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) all: $(generic-y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) $(if $(unwanted),$(call cmd,remove))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) @:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) $(obj)/%.h:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) $(call cmd,wrap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) # Create output directory. Skip it if at least one old header exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) # since we know the output directory already exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ifeq ($(old-headers),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) $(shell mkdir -p $(obj))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .PHONY: $(PHONY)