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 generates arch/$(SRCARCH)/include/generated/(uapi/)/asm 6# headers from multiple sources: 7# - a small wrapper to include the corresponding asm-generic/*.h 8# is generated for each file listed as generic-y 9# - uapi/asm/unistd_*.h files listed as syscalls-y are generated from 10# syscall.tbl with the __NR_* macros 11# - Corresponding asm/syscall_table_*.h are generated from the same input 12 13PHONY := all 14all: 15 16src := $(srctree)/$(subst /generated,,$(obj)) 17 18syscall_abis_32 += common,32 19syscall_abis_64 += common,64 20syscalltbl := $(srctree)/scripts/syscall.tbl 21syshdr-args := --emit-nr 22 23# let architectures override $(syscall_abis_%) and $(syscalltbl) 24-include $(srctree)/arch/$(SRCARCH)/kernel/Makefile.syscalls 25include $(srctree)/scripts/Kbuild.include 26-include $(kbuild-file) 27 28syshdr := $(srctree)/scripts/syscallhdr.sh 29systbl := $(srctree)/scripts/syscalltbl.sh 30 31# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case. 32ifneq ($(SRCARCH),um) 33include $(srctree)/$(generic)/Kbuild 34endif 35 36redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y)) 37redundant += $(foreach f, $(generic-y), $(if $(wildcard $(src)/$(f)),$(f))) 38redundant := $(sort $(redundant)) 39$(if $(redundant),\ 40 $(warning redundant generic-y found in $(src)/Kbuild: $(redundant))) 41 42# If arch does not implement mandatory headers, fallback to asm-generic ones. 43mandatory-y := $(filter-out $(generated-y), $(mandatory-y)) 44generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(src)/$(f)),,$(f))) 45 46generic-y := $(addprefix $(obj)/, $(generic-y)) 47syscall-y := $(addprefix $(obj)/, $(syscall-y)) 48generated-y := $(addprefix $(obj)/, $(generated-y)) 49 50# Remove stale wrappers when the corresponding files are removed from generic-y 51old-headers := $(shell test -d $(obj) && find $(obj) -name *.h) 52unwanted := $(filter-out $(generic-y) $(generated-y) $(syscall-y),$(old-headers)) 53 54filechk_wrap = echo "\#include <asm-generic/$*.h>" 55 56quiet_cmd_remove = REMOVE $(unwanted) 57 cmd_remove = rm -f $(unwanted); find $(obj) -type d -empty -delete 58 59quiet_cmd_syshdr = SYSHDR $@ 60 cmd_syshdr = $(CONFIG_SHELL) $(syshdr) \ 61 $(if $(syshdr-args-$*),$(syshdr-args-$*),$(syshdr-args)) \ 62 $(if $(syscall_compat),--prefix "compat$*_") \ 63 --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \ 64 $< $@ 65 66quiet_cmd_systbl = SYSTBL $@ 67 cmd_systbl = $(CONFIG_SHELL) $(systbl) \ 68 $(if $(systbl-args-$*),$(systbl-args-$*),$(systbl-args)) \ 69 --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \ 70 $< $@ 71 72all: $(generic-y) $(syscall-y) 73 $(if $(unwanted),$(call cmd,remove)) 74 @: 75 76$(obj)/%.h: $(srctree)/$(generic)/%.h FORCE 77 $(call filechk,wrap) 78 79$(obj)/unistd_%.h: $(syscalltbl) $(syshdr) FORCE 80 $(call if_changed,syshdr) 81 82$(obj)/unistd_compat_%.h: syscall_compat:=1 83$(obj)/unistd_compat_%.h: $(syscalltbl) $(syshdr) FORCE 84 $(call if_changed,syshdr) 85 86$(obj)/syscall_table_%.h: $(syscalltbl) $(systbl) FORCE 87 $(call if_changed,systbl) 88 89targets := $(syscall-y) 90 91# Create output directory. Skip it if at least one old header exists 92# since we know the output directory already exists. 93ifeq ($(old-headers),) 94$(shell mkdir -p $(obj)) 95endif 96 97PHONY += FORCE 98 99FORCE: 100 101existing-targets := $(wildcard $(sort $(targets))) 102 103-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 104 105.PHONY: $(PHONY) 106