| 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # include/asm-generic contains a lot of files that are used |
| 3 | # verbatim by several architectures. |
| 4 | # |
| 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. |
| 8 | |
| 9 | PHONY := all |
| 10 | all: |
| 11 | |
| 12 | src := $(subst /generated,,$(obj)) |
| 13 | -include $(src)/Kbuild |
| 14 | |
| 15 | include scripts/Kbuild.include |
| 16 | |
| 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))) |
| 20 | |
| 21 | generic-y := $(addprefix $(obj)/, $(generic-y)) |
| 22 | generated-y := $(addprefix $(obj)/, $(generated-y)) |
| 23 | |
| 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)) |
| 27 | |
| 28 | quiet_cmd_wrap = WRAP $@ |
| 29 | cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@ |
| 30 | |
| 31 | quiet_cmd_remove = REMOVE $(unwanted) |
| 32 | cmd_remove = rm -f $(unwanted) |
| 33 | |
| 34 | all: $(generic-y) |
| 35 | $(if $(unwanted),$(call cmd,remove)) |
| 36 | @: |
| 37 | |
| 38 | $(obj)/%.h: |
| 39 | $(call cmd,wrap) |
| 40 | |
| 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)) |
| 45 | endif |
| 46 | |
| 47 | .PHONY: $(PHONY) |