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