xref: /haiku/src/tools/gensyscalls/Jamfile (revision 268f99dd7dc4bd7474a8bd2742d3f1ec1de6752a)
1338b8dc3SIngo WeinholdSubDir HAIKU_TOP src tools gensyscalls ;
22e463a12SIngo Weinhold
359d6284bSIngo Weinhold
459d6284bSIngo Weinhold# What want to do here is analyze the <syscalls.h> header and generate headers
559d6284bSIngo Weinhold# and sources containing information about the syscalls (like what parameters
659d6284bSIngo Weinhold# of what sizes and types they take, etc.) which will be used in other places
759d6284bSIngo Weinhold# (e.g. the kernel code or the strace tool).
859d6284bSIngo Weinhold#
959d6284bSIngo Weinhold# The strategy to achieve this is:
1059d6284bSIngo Weinhold# * Preprocess the <syscalls.h> header, so that it is easier to parse.
1159d6284bSIngo Weinhold# * Feed the preprocessed header to the gensyscallinfos tool. It will generate
1259d6284bSIngo Weinhold#	a source file, gensyscalls_infos.cpp, which implements a function that
1359d6284bSIngo Weinhold#	builds a table with all the syscall info information we need. The source
1459d6284bSIngo Weinhold#	file needs specific infos about sizes of types, which aren't easily
1559d6284bSIngo Weinhold#	available. That's why gensyscallinfos also generates a source file which
1659d6284bSIngo Weinhold#	via the CreateAsmStructOffsetsHeader rule is turned into a header with
1759d6284bSIngo Weinhold#	macro definitions for those type size. The header is included by
1859d6284bSIngo Weinhold#	gensyscalls_infos.cpp.
1959d6284bSIngo Weinhold# * gensyscalls.cpp and the generated gensyscalls_infos.cpp are compiled into
2059d6284bSIngo Weinhold#	the gensyscalls tool.
2159d6284bSIngo Weinhold# * gensyscalls has options to generate the various output files:
22b0944c78SIngo Weinhold#	- <syscalls!$(architecture>syscalls.S.inc: Used to define the syscall
23b0944c78SIngo Weinhold#     functions in libroot.
24b0944c78SIngo Weinhold#	- <syscalls!$(architecture>syscall_dispatcher.h: Big "switch" statement for
25b0944c78SIngo Weinhold#     the syscall dispatcher in the kernel.
26b0944c78SIngo Weinhold#	- <syscalls!$(architecture>syscall_numbers.h: Macro definitions assigning
27b0944c78SIngo Weinhold#     indices to the syscalls.
28b0944c78SIngo Weinhold#	- <syscalls!$(architecture>syscall_table.h: An array with syscall
29b0944c78SIngo Weinhold#     information in the kernel. Used for dispatching syscalls e.g. for x86.
30b0944c78SIngo Weinhold#	- <syscalls!$(architecture>strace_syscalls.h: Syscall information needed by
31b0944c78SIngo Weinhold#     strace.
3259d6284bSIngo Weinhold
3359d6284bSIngo Weinhold
34b0944c78SIngo Weinholdrule PreprocessSyscalls preprocessedHeader : header : architecture
352ae56893SIngo Weinhold{
36b0944c78SIngo Weinhold	# PreprocessSyscalls <preprocessedHeader> : <header> : <architecture> ;
37efd87ab8SIngo Weinhold
38a07cdb6eSOliver Tappe	Depends $(preprocessedHeader) : $(header) $(PLATFORM) ;
392ae56893SIngo Weinhold
40b0944c78SIngo Weinhold	local headers = [ on $(preprocessedHeader)
41b0944c78SIngo Weinhold		return $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
422ae56893SIngo Weinhold	local sysHeaders =
43b0944c78SIngo Weinhold		$(TARGET_PRIVATE_SYSTEM_HEADERS_$(architecture))
44b0944c78SIngo Weinhold		[ ArchHeaders $(TARGET_ARCH_$(architecture)) ]
45b0944c78SIngo Weinhold		[ on $(preprocessedHeader) return $(SUBDIRSYSHDRS) $(SYSHDRS) ]
46afde4473SOliver Tappe		[ FStandardHeaders $(architecture) ]
47b0944c78SIngo Weinhold		$(TARGET_HDRS_$(architecture)) ;
482ae56893SIngo Weinhold
49b0944c78SIngo Weinhold	HDRS on $(preprocessedHeader) = $(headers) ;
50b0944c78SIngo Weinhold	SYSHDRS on $(preprocessedHeader) = $(sysHeaders) ;
512ae56893SIngo Weinhold
52b0944c78SIngo Weinhold	HDRRULE on $(header) = HdrRule ;
53b0944c78SIngo Weinhold	HDRSCAN on $(header) = $(HDRPATTERN) ;
54b0944c78SIngo Weinhold	HDRSEARCH on $(header) = $(headers) $(sysHeaders) $(STDHDRS) ;
55b0944c78SIngo Weinhold	HDRGRIST on $(header) = $(HDRGRIST) ;
562ae56893SIngo Weinhold
57b0944c78SIngo Weinhold	DEFINES on $(preprocessedHeader) += $(TARGET_DEFINES_$(architecture))
58b0944c78SIngo Weinhold		$(TARGET_DEFINES) GEN_SYSCALL_INFOS_PROCESSING ;
592ae56893SIngo Weinhold
60b0944c78SIngo Weinhold	CC on $(preprocessedHeader) = $(TARGET_C++_$(architecture)) ;
61b0944c78SIngo Weinhold	CCFLAGS on $(preprocessedHeader) += $(TARGET_CCFLAGS_$(architecture))
62b0944c78SIngo Weinhold		$(SUBDIRCCFLAGS) $(OPTIM) ;
63b0944c78SIngo Weinhold	CCHDRS on $(preprocessedHeader) =
64b0944c78SIngo Weinhold		[ FIncludes $(headers)
65b0944c78SIngo Weinhold			: $(TARGET_LOCAL_INCLUDES_OPTION_$(architecture)) ]
66b0944c78SIngo Weinhold		$(TARGET_INCLUDES_SEPARATOR_$(architecture))
67b0944c78SIngo Weinhold		[ FSysIncludes $(sysHeaders)
68b0944c78SIngo Weinhold			: $(TARGET_SYSTEM_INCLUDES_OPTION_$(architecture)) ] ;
69b0944c78SIngo Weinhold	CCDEFS on $(preprocessedHeader)
70b0944c78SIngo Weinhold		= [ on $(preprocessedHeader) FDefines $(DEFINES) ] ;
712ae56893SIngo Weinhold}
722ae56893SIngo Weinhold
73b0944c78SIngo Weinhold
742ae56893SIngo Weinholdactions PreprocessSyscalls
752ae56893SIngo Weinhold{
76b0944c78SIngo Weinhold	$(CC) -xc++ -E "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
772ae56893SIngo Weinhold}
78efd87ab8SIngo Weinhold
79efd87ab8SIngo Weinhold
80b0944c78SIngo Weinholdrule GenSyscallInfos targets : sources : gensyscallinfos
8159d6284bSIngo Weinhold{
82b0944c78SIngo Weinhold	Depends $(targets) : $(gensyscallinfos) $(sources) ;
83b0944c78SIngo Weinhold	GenSyscallInfos1 $(targets) : $(gensyscallinfos) $(sources) ;
84efd87ab8SIngo Weinhold}
85efd87ab8SIngo Weinhold
86b0944c78SIngo Weinhold
8759d6284bSIngo Weinholdactions GenSyscallInfos1
8859d6284bSIngo Weinhold{
89efd87ab8SIngo Weinhold	$(2[1]) $(2[2]) $(1)
90efd87ab8SIngo Weinhold}
91efd87ab8SIngo Weinhold
922ae56893SIngo Weinhold
93b0944c78SIngo Weinholdrule GenSyscallsFile file : gensyscalls : option
94b0944c78SIngo Weinhold{
95b0944c78SIngo Weinhold	GENSYSCALLS_FILE_OPTION on $(file) = $(option) ;
96b0944c78SIngo Weinhold	Depends $(file) : $(gensyscalls) ;
97b0944c78SIngo Weinhold	GenSyscallsFile1 $(file) : $(gensyscalls) ;
98b0944c78SIngo Weinhold}
99b0944c78SIngo Weinhold
100b0944c78SIngo Weinhold
101b0944c78SIngo Weinholdactions GenSyscallsFile1
102b0944c78SIngo Weinhold{
103b0944c78SIngo Weinhold	$(2[1]) $(GENSYSCALLS_FILE_OPTION) $(1)
104b0944c78SIngo Weinhold}
105b0944c78SIngo Weinhold
106b0944c78SIngo Weinhold
107b0944c78SIngo Weinholdlocal syscallsHeader = [ FGristFiles syscalls.h ] ;
108b0944c78SIngo WeinholdSEARCH on $(syscallsHeader) = [ FDirName $(HAIKU_TOP) headers private system ] ;
109b0944c78SIngo Weinhold
110b0944c78SIngo Weinholdlocal architectureObject ;
111b0944c78SIngo Weinholdfor architectureObject in [ MultiArchSubDirSetup ] {
112b0944c78SIngo Weinhold	on $(architectureObject) {
113b0944c78SIngo Weinhold		local architecture = $(TARGET_PACKAGING_ARCH) ;
114b0944c78SIngo Weinhold
115b0944c78SIngo Weinhold		# Generate the preprocessed syscalls.h header. It will be parsed by
116b0944c78SIngo Weinhold		# gensyscallinfos (it contains marker #pragmas).
117b0944c78SIngo Weinhold		local syscallsHeaderPPParsable
118b0944c78SIngo Weinhold			= [ FGristFiles syscalls.h.pp.parsable ] ;
119b0944c78SIngo Weinhold		MakeLocateArch $(syscallsHeaderPPParsable) ;
120b0944c78SIngo Weinhold		PreprocessSyscalls $(syscallsHeaderPPParsable) : $(syscallsHeader)
121b0944c78SIngo Weinhold			: $(architecture) ;
122b0944c78SIngo Weinhold
123b0944c78SIngo Weinhold		# build gensyscallinfos
124b0944c78SIngo Weinhold
125b0944c78SIngo Weinhold		local gensyscallinfos = gensyscallinfos_$(architecture) ;
126b0944c78SIngo Weinhold		SourceHdrs gensyscallinfos.cpp
127b0944c78SIngo Weinhold			: [ FDirName $(SUBDIR) arch $(TARGET_ARCH_$(architecture)) ] ;
128df3ac004SJérôme Duval		MakeLocate [ FGristFiles gensyscallinfos$(SUFOBJ) ]
129df3ac004SJérôme Duval			: [ FDirName $(HOST_DEBUG_$(DEBUG)_LOCATE_TARGET) $(architecture) ] ;
130b0944c78SIngo Weinhold		BuildPlatformMain $(gensyscallinfos)
131b0944c78SIngo Weinhold			: gensyscallinfos.cpp
132b0944c78SIngo Weinhold			: $(HOST_LIBSTDC++) $(HOST_LIBSUPC++)
133b0944c78SIngo Weinhold			;
134b0944c78SIngo Weinhold
135b0944c78SIngo Weinhold		# generate the syscall infos source file and the source for the header
136b0944c78SIngo Weinhold		# it includes
137b0944c78SIngo Weinhold
138b0944c78SIngo Weinhold		local syscallInfos = [ FGristFiles gensyscalls_infos.cpp ] ;
139b0944c78SIngo Weinhold		local syscallTypesSizesSource
140b0944c78SIngo Weinhold			= [ FGristFiles syscall_types_sizes.h.cpp ] ;
141b0944c78SIngo Weinhold		local syscallTypesSizes = [ FGristFiles syscall_types_sizes.h ] ;
142b0944c78SIngo Weinhold		MakeLocateArch $(syscallInfos) $(syscallTypesSizesSource)
143b0944c78SIngo Weinhold			$(syscallTypesSizes) ;
144b0944c78SIngo Weinhold
145b0944c78SIngo Weinhold		GenSyscallInfos $(syscallInfos) $(syscallTypesSizesSource)
146b0944c78SIngo Weinhold			: $(syscallsHeaderPPParsable) : $(gensyscallinfos) ;
147b0944c78SIngo Weinhold
148b0944c78SIngo Weinhold		TARGET_HDRS_$(architecture) on $(syscallTypesSizes)
149b0944c78SIngo Weinhold			= [ on $(syscallTypesSizes) return $(TARGET_HDRS_$(architecture)) ]
150b0944c78SIngo Weinhold				[ FDirName $(SUBDIR) arch $(TARGET_ARCH_$(architecture)) ]
151b0944c78SIngo Weinhold				$(TARGET_PRIVATE_SYSTEM_HEADERS_$(architecture)) ;
152b0944c78SIngo Weinhold		CreateAsmStructOffsetsHeader $(syscallTypesSizes)
153*7aa55747SAugustin Cavalier			: $(syscallTypesSizesSource) : $(TARGET_PACKAGING_ARCH) ;
15459d6284bSIngo Weinhold
15559d6284bSIngo Weinhold		#Includes $(syscallInfos) : $(syscallTypesSizes) ;
15659d6284bSIngo Weinhold			# explicitly tell jam about the inclusion of the generated header
15759d6284bSIngo Weinhold		Depends $(syscallInfos:S=$(SUFOBJ)) : $(syscallTypesSizes) ;
15859d6284bSIngo Weinhold			# NOTE: Jam messes up the "Includes" declaration, so we have to declare
15959d6284bSIngo Weinhold			# the dependency more directly.
160efd87ab8SIngo Weinhold
161efd87ab8SIngo Weinhold		# build gensyscalls
162efd87ab8SIngo Weinhold
163b0944c78SIngo Weinhold		local gensyscalls = gensyscalls_$(architecture) ;
164df3ac004SJérôme Duval		MakeLocate [ FGristFiles gensyscalls$(SUFOBJ) gensyscalls_infos$(SUFOBJ) ]
165df3ac004SJérôme Duval			: [ FDirName $(HOST_DEBUG_$(DEBUG)_LOCATE_TARGET) $(architecture) ] ;
166b0944c78SIngo Weinhold		BuildPlatformMain $(gensyscalls)
167b0944c78SIngo Weinhold			: gensyscalls.cpp $(syscallInfos) ;
168b0944c78SIngo Weinhold		LinkAgainst $(gensyscalls) : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ;
169efd87ab8SIngo Weinhold
170efd87ab8SIngo Weinhold		# generate the output files
171efd87ab8SIngo Weinhold
1722ae56893SIngo Weinhold		# place them where they are needed
173b0944c78SIngo Weinhold		local dir = $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(architecture)) ;
174b0944c78SIngo Weinhold		MakeLocate <syscalls!$(architecture)>syscalls.S.inc
175b0944c78SIngo Weinhold			: [ FDirName $(dir) system libroot os ] ;
176b0944c78SIngo Weinhold		MakeLocate <syscalls!$(architecture)>syscall_dispatcher.h
177b0944c78SIngo Weinhold			: [ FDirName $(dir) system kernel ] ;
178b0944c78SIngo Weinhold		MakeLocate <syscalls!$(architecture)>syscall_numbers.h
179b0944c78SIngo Weinhold			: [ FDirName $(dir) system kernel ] ;
180b0944c78SIngo Weinhold		MakeLocate <syscalls!$(architecture)>syscall_table.h
181b0944c78SIngo Weinhold			: [ FDirName $(dir) system kernel ] ;
182b0944c78SIngo Weinhold		MakeLocate <syscalls!$(architecture)>strace_syscalls.h
183b0944c78SIngo Weinhold			: [ FDirName $(dir) bin debug strace ] ;
184efd87ab8SIngo Weinhold
185b0944c78SIngo Weinhold		GenSyscallsFile <syscalls!$(architecture)>syscalls.S.inc
186b0944c78SIngo Weinhold			: $(gensyscalls) : -c ;
187b0944c78SIngo Weinhold		GenSyscallsFile <syscalls!$(architecture)>syscall_dispatcher.h
188b0944c78SIngo Weinhold			: $(gensyscalls) : -d ;
189b0944c78SIngo Weinhold		GenSyscallsFile <syscalls!$(architecture)>syscall_numbers.h
190b0944c78SIngo Weinhold			: $(gensyscalls) : -n ;
191b0944c78SIngo Weinhold		GenSyscallsFile <syscalls!$(architecture)>syscall_table.h
192b0944c78SIngo Weinhold			: $(gensyscalls) : -t ;
193b0944c78SIngo Weinhold		GenSyscallsFile <syscalls!$(architecture)>strace_syscalls.h
194b0944c78SIngo Weinhold			: $(gensyscalls) : -s ;
195efd87ab8SIngo Weinhold	}
196efd87ab8SIngo Weinhold}
197