1fbb5c060SArnd Bergmann# SPDX-License-Identifier: GPL-2.0 2fbb5c060SArnd Bergmann# include/asm-generic contains a lot of files that are used 3fbb5c060SArnd Bergmann# verbatim by several architectures. 4fbb5c060SArnd Bergmann# 5fbb5c060SArnd Bergmann# This Makefile generates arch/$(SRCARCH)/include/generated/(uapi/)/asm 6fbb5c060SArnd Bergmann# headers from multiple sources: 7fbb5c060SArnd Bergmann# - a small wrapper to include the corresponding asm-generic/*.h 8fbb5c060SArnd Bergmann# is generated for each file listed as generic-y 9fbb5c060SArnd Bergmann# - uapi/asm/unistd_*.h files listed as syscalls-y are generated from 10fbb5c060SArnd Bergmann# syscall.tbl with the __NR_* macros 11fbb5c060SArnd Bergmann# - Corresponding asm/syscall_table_*.h are generated from the same input 12fbb5c060SArnd Bergmann 13fbb5c060SArnd BergmannPHONY := all 14fbb5c060SArnd Bergmannall: 15fbb5c060SArnd Bergmann 16fbb5c060SArnd Bergmannsrc := $(srctree)/$(subst /generated,,$(obj)) 17fbb5c060SArnd Bergmann 18fbb5c060SArnd Bergmannsyscall_abis_32 += common,32 19fbb5c060SArnd Bergmannsyscall_abis_64 += common,64 20fbb5c060SArnd Bergmannsyscalltbl := $(srctree)/scripts/syscall.tbl 21fbb5c060SArnd Bergmannsyshdr-args := --emit-nr 22fbb5c060SArnd Bergmann 23fbb5c060SArnd Bergmann# let architectures override $(syscall_abis_%) and $(syscalltbl) 24fbb5c060SArnd Bergmann-include $(srctree)/arch/$(SRCARCH)/kernel/Makefile.syscalls 25fbb5c060SArnd Bergmanninclude $(srctree)/scripts/Kbuild.include 26fbb5c060SArnd Bergmann-include $(kbuild-file) 27fbb5c060SArnd Bergmann 28fbb5c060SArnd Bergmannsyshdr := $(srctree)/scripts/syscallhdr.sh 29fbb5c060SArnd Bergmannsystbl := $(srctree)/scripts/syscalltbl.sh 30fbb5c060SArnd Bergmann 31fbb5c060SArnd Bergmann# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case. 32fbb5c060SArnd Bergmannifneq ($(SRCARCH),um) 33fbb5c060SArnd Bergmanninclude $(srctree)/$(generic)/Kbuild 34fbb5c060SArnd Bergmannendif 35fbb5c060SArnd Bergmann 36fbb5c060SArnd Bergmannredundant := $(filter $(mandatory-y) $(generated-y), $(generic-y)) 37fbb5c060SArnd Bergmannredundant += $(foreach f, $(generic-y), $(if $(wildcard $(src)/$(f)),$(f))) 38fbb5c060SArnd Bergmannredundant := $(sort $(redundant)) 39fbb5c060SArnd Bergmann$(if $(redundant),\ 40fbb5c060SArnd Bergmann $(warning redundant generic-y found in $(src)/Kbuild: $(redundant))) 41fbb5c060SArnd Bergmann 42fbb5c060SArnd Bergmann# If arch does not implement mandatory headers, fallback to asm-generic ones. 43fbb5c060SArnd Bergmannmandatory-y := $(filter-out $(generated-y), $(mandatory-y)) 44fbb5c060SArnd Bergmanngeneric-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(src)/$(f)),,$(f))) 45fbb5c060SArnd Bergmann 46fbb5c060SArnd Bergmanngeneric-y := $(addprefix $(obj)/, $(generic-y)) 47fbb5c060SArnd Bergmannsyscall-y := $(addprefix $(obj)/, $(syscall-y)) 48fbb5c060SArnd Bergmanngenerated-y := $(addprefix $(obj)/, $(generated-y)) 49fbb5c060SArnd Bergmann 50fbb5c060SArnd Bergmann# Remove stale wrappers when the corresponding files are removed from generic-y 51*2d69b891SThomas Weißschuhold-headers := $(shell test -d $(obj) && find $(obj) -name *.h) 52fbb5c060SArnd Bergmannunwanted := $(filter-out $(generic-y) $(generated-y) $(syscall-y),$(old-headers)) 53fbb5c060SArnd Bergmann 54*2d69b891SThomas Weißschuhfilechk_wrap = echo "\#include <asm-generic/$*.h>" 55fbb5c060SArnd Bergmann 56fbb5c060SArnd Bergmannquiet_cmd_remove = REMOVE $(unwanted) 57*2d69b891SThomas Weißschuh cmd_remove = rm -f $(unwanted); find $(obj) -type d -empty -delete 58fbb5c060SArnd Bergmann 59fbb5c060SArnd Bergmannquiet_cmd_syshdr = SYSHDR $@ 60fbb5c060SArnd Bergmann cmd_syshdr = $(CONFIG_SHELL) $(syshdr) \ 61fbb5c060SArnd Bergmann $(if $(syshdr-args-$*),$(syshdr-args-$*),$(syshdr-args)) \ 62fbb5c060SArnd Bergmann $(if $(syscall_compat),--prefix "compat$*_") \ 63fbb5c060SArnd Bergmann --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \ 64fbb5c060SArnd Bergmann $< $@ 65fbb5c060SArnd Bergmann 66fbb5c060SArnd Bergmannquiet_cmd_systbl = SYSTBL $@ 67fbb5c060SArnd Bergmann cmd_systbl = $(CONFIG_SHELL) $(systbl) \ 68fbb5c060SArnd Bergmann $(if $(systbl-args-$*),$(systbl-args-$*),$(systbl-args)) \ 69fbb5c060SArnd Bergmann --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \ 70fbb5c060SArnd Bergmann $< $@ 71fbb5c060SArnd Bergmann 72fbb5c060SArnd Bergmannall: $(generic-y) $(syscall-y) 73fbb5c060SArnd Bergmann $(if $(unwanted),$(call cmd,remove)) 74fbb5c060SArnd Bergmann @: 75fbb5c060SArnd Bergmann 76*2d69b891SThomas Weißschuh$(obj)/%.h: $(srctree)/$(generic)/%.h FORCE 77*2d69b891SThomas Weißschuh $(call filechk,wrap) 78fbb5c060SArnd Bergmann 79fbb5c060SArnd Bergmann$(obj)/unistd_%.h: $(syscalltbl) $(syshdr) FORCE 80fbb5c060SArnd Bergmann $(call if_changed,syshdr) 81fbb5c060SArnd Bergmann 82fbb5c060SArnd Bergmann$(obj)/unistd_compat_%.h: syscall_compat:=1 83fbb5c060SArnd Bergmann$(obj)/unistd_compat_%.h: $(syscalltbl) $(syshdr) FORCE 84fbb5c060SArnd Bergmann $(call if_changed,syshdr) 85fbb5c060SArnd Bergmann 86fbb5c060SArnd Bergmann$(obj)/syscall_table_%.h: $(syscalltbl) $(systbl) FORCE 87fbb5c060SArnd Bergmann $(call if_changed,systbl) 88fbb5c060SArnd Bergmann 8949208b67SMasahiro Yamadatargets := $(syscall-y) 9049208b67SMasahiro Yamada 91fbb5c060SArnd Bergmann# Create output directory. Skip it if at least one old header exists 92fbb5c060SArnd Bergmann# since we know the output directory already exists. 93fbb5c060SArnd Bergmannifeq ($(old-headers),) 94fbb5c060SArnd Bergmann$(shell mkdir -p $(obj)) 95fbb5c060SArnd Bergmannendif 96fbb5c060SArnd Bergmann 9749208b67SMasahiro YamadaPHONY += FORCE 9849208b67SMasahiro Yamada 99fbb5c060SArnd BergmannFORCE: 100fbb5c060SArnd Bergmann 10149208b67SMasahiro Yamadaexisting-targets := $(wildcard $(sort $(targets))) 10249208b67SMasahiro Yamada 10349208b67SMasahiro Yamada-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 10449208b67SMasahiro Yamada 105fbb5c060SArnd Bergmann.PHONY: $(PHONY) 106