xref: /linux/scripts/Makefile.asm-headers (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
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
51fbb5c060SArnd Bergmannold-headers := $(wildcard $(obj)/*.h)
52fbb5c060SArnd Bergmannunwanted    := $(filter-out $(generic-y) $(generated-y) $(syscall-y),$(old-headers))
53fbb5c060SArnd Bergmann
54fbb5c060SArnd Bergmannquiet_cmd_wrap = WRAP    $@
55fbb5c060SArnd Bergmann      cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
56fbb5c060SArnd Bergmann
57fbb5c060SArnd Bergmannquiet_cmd_remove = REMOVE  $(unwanted)
58fbb5c060SArnd Bergmann      cmd_remove = rm -f $(unwanted)
59fbb5c060SArnd Bergmann
60fbb5c060SArnd Bergmannquiet_cmd_syshdr = SYSHDR  $@
61fbb5c060SArnd Bergmann      cmd_syshdr = $(CONFIG_SHELL) $(syshdr) \
62fbb5c060SArnd Bergmann		   $(if $(syshdr-args-$*),$(syshdr-args-$*),$(syshdr-args)) \
63fbb5c060SArnd Bergmann		   $(if $(syscall_compat),--prefix "compat$*_") \
64fbb5c060SArnd Bergmann		   --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \
65fbb5c060SArnd Bergmann		   $< $@
66fbb5c060SArnd Bergmann
67fbb5c060SArnd Bergmannquiet_cmd_systbl = SYSTBL  $@
68fbb5c060SArnd Bergmann      cmd_systbl = $(CONFIG_SHELL) $(systbl) \
69fbb5c060SArnd Bergmann		   $(if $(systbl-args-$*),$(systbl-args-$*),$(systbl-args)) \
70fbb5c060SArnd Bergmann		   --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \
71fbb5c060SArnd Bergmann		   $< $@
72fbb5c060SArnd Bergmann
73fbb5c060SArnd Bergmannall: $(generic-y) $(syscall-y)
74fbb5c060SArnd Bergmann	$(if $(unwanted),$(call cmd,remove))
75fbb5c060SArnd Bergmann	@:
76fbb5c060SArnd Bergmann
77fbb5c060SArnd Bergmann$(obj)/%.h: $(srctree)/$(generic)/%.h
78fbb5c060SArnd Bergmann	$(call cmd,wrap)
79fbb5c060SArnd Bergmann
80fbb5c060SArnd Bergmann$(obj)/unistd_%.h: $(syscalltbl) $(syshdr) FORCE
81fbb5c060SArnd Bergmann	$(call if_changed,syshdr)
82fbb5c060SArnd Bergmann
83fbb5c060SArnd Bergmann$(obj)/unistd_compat_%.h: syscall_compat:=1
84fbb5c060SArnd Bergmann$(obj)/unistd_compat_%.h: $(syscalltbl) $(syshdr) FORCE
85fbb5c060SArnd Bergmann	$(call if_changed,syshdr)
86fbb5c060SArnd Bergmann
87fbb5c060SArnd Bergmann$(obj)/syscall_table_%.h: $(syscalltbl) $(systbl) FORCE
88fbb5c060SArnd Bergmann	$(call if_changed,systbl)
89fbb5c060SArnd Bergmann
90*49208b67SMasahiro Yamadatargets := $(syscall-y)
91*49208b67SMasahiro Yamada
92fbb5c060SArnd Bergmann# Create output directory. Skip it if at least one old header exists
93fbb5c060SArnd Bergmann# since we know the output directory already exists.
94fbb5c060SArnd Bergmannifeq ($(old-headers),)
95fbb5c060SArnd Bergmann$(shell mkdir -p $(obj))
96fbb5c060SArnd Bergmannendif
97fbb5c060SArnd Bergmann
98*49208b67SMasahiro YamadaPHONY += FORCE
99*49208b67SMasahiro Yamada
100fbb5c060SArnd BergmannFORCE:
101fbb5c060SArnd Bergmann
102*49208b67SMasahiro Yamadaexisting-targets := $(wildcard $(sort $(targets)))
103*49208b67SMasahiro Yamada
104*49208b67SMasahiro Yamada-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
105*49208b67SMasahiro Yamada
106fbb5c060SArnd Bergmann.PHONY: $(PHONY)
107