1 SubDir HAIKU_TOP src tools gensyscalls ;
4 # What want to do here is analyze the <syscalls.h> header and generate headers
5 # and sources containing information about the syscalls (like what parameters
6 # of what sizes and types they take, etc.) which will be used in other places
7 # (e.g. the kernel code or the strace tool).
9 # The strategy to achieve this is:
10 # * Preprocess the <syscalls.h> header, so that it is easier to parse.
11 # * Feed the preprocessed header to the gensyscallinfos tool. It will generate
12 # a source file, gensyscalls_infos.cpp, which implements a function that
13 # builds a table with all the syscall info information we need. The source
14 # file needs specific infos about sizes of types, which aren't easily
15 # available. That's why gensyscallinfos also generates a source file which
16 # via the CreateAsmStructOffsetsHeader rule is turned into a header with
17 # macro definitions for those type size. The header is included by
18 # gensyscalls_infos.cpp.
19 # * gensyscalls.cpp and the generated gensyscalls_infos.cpp are compiled into
20 # the gensyscalls tool.
21 # * gensyscalls has options to generate the various output files:
22 # - <syscalls!$(architecture>syscalls.S.inc: Used to define the syscall
23 # functions in libroot.
24 # - <syscalls!$(architecture>syscall_dispatcher.h: Big "switch" statement for
25 # the syscall dispatcher in the kernel.
26 # - <syscalls!$(architecture>syscall_numbers.h: Macro definitions assigning
27 # indices to the syscalls.
28 # - <syscalls!$(architecture>syscall_table.h: An array with syscall
29 # information in the kernel. Used for dispatching syscalls e.g. for x86.
30 # - <syscalls!$(architecture>strace_syscalls.h: Syscall information needed by
34 rule PreprocessSyscalls preprocessedHeader : header : architecture
36 # PreprocessSyscalls <preprocessedHeader> : <header> : <architecture> ;
38 Depends $(preprocessedHeader) : $(header) $(PLATFORM) ;
40 local headers = [ on $(preprocessedHeader)
41 return $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
43 $(TARGET_PRIVATE_SYSTEM_HEADERS_$(architecture))
44 [ ArchHeaders $(TARGET_ARCH_$(architecture)) ]
45 [ on $(preprocessedHeader) return $(SUBDIRSYSHDRS) $(SYSHDRS) ]
46 [ FStandardHeaders $(architecture) ]
47 $(TARGET_HDRS_$(architecture)) ;
49 HDRS on $(preprocessedHeader) = $(headers) ;
50 SYSHDRS on $(preprocessedHeader) = $(sysHeaders) ;
52 HDRRULE on $(header) = HdrRule ;
53 HDRSCAN on $(header) = $(HDRPATTERN) ;
54 HDRSEARCH on $(header) = $(headers) $(sysHeaders) $(STDHDRS) ;
55 HDRGRIST on $(header) = $(HDRGRIST) ;
57 DEFINES on $(preprocessedHeader) += $(TARGET_DEFINES_$(architecture))
58 $(TARGET_DEFINES) GEN_SYSCALL_INFOS_PROCESSING ;
60 CC on $(preprocessedHeader) = $(TARGET_C++_$(architecture)) ;
61 CCFLAGS on $(preprocessedHeader) += $(TARGET_CCFLAGS_$(architecture))
62 $(SUBDIRCCFLAGS) $(OPTIM) ;
63 CCHDRS on $(preprocessedHeader) =
64 [ FIncludes $(headers)
65 : $(TARGET_LOCAL_INCLUDES_OPTION_$(architecture)) ]
66 $(TARGET_INCLUDES_SEPARATOR_$(architecture))
67 [ FSysIncludes $(sysHeaders)
68 : $(TARGET_SYSTEM_INCLUDES_OPTION_$(architecture)) ] ;
69 CCDEFS on $(preprocessedHeader)
70 = [ on $(preprocessedHeader) FDefines $(DEFINES) ] ;
74 actions PreprocessSyscalls
76 $(CC) -xc++ -E "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
80 rule GenSyscallInfos targets : sources : gensyscallinfos
82 Depends $(targets) : $(gensyscallinfos) $(sources) ;
83 GenSyscallInfos1 $(targets) : $(gensyscallinfos) $(sources) ;
87 actions GenSyscallInfos1
93 rule GenSyscallsFile file : gensyscalls : option
95 GENSYSCALLS_FILE_OPTION on $(file) = $(option) ;
96 Depends $(file) : $(gensyscalls) ;
97 GenSyscallsFile1 $(file) : $(gensyscalls) ;
101 actions GenSyscallsFile1
103 $(2[1]) $(GENSYSCALLS_FILE_OPTION) $(1)
107 local syscallsHeader = [ FGristFiles syscalls.h ] ;
108 SEARCH on $(syscallsHeader) = [ FDirName $(HAIKU_TOP) headers private system ] ;
110 local architectureObject ;
111 for architectureObject in [ MultiArchSubDirSetup ] {
112 on $(architectureObject) {
113 local architecture = $(TARGET_PACKAGING_ARCH) ;
115 # Generate the preprocessed syscalls.h header. It will be parsed by
116 # gensyscallinfos (it contains marker #pragmas).
117 local syscallsHeaderPPParsable
118 = [ FGristFiles syscalls.h.pp.parsable ] ;
119 MakeLocateArch $(syscallsHeaderPPParsable) ;
120 PreprocessSyscalls $(syscallsHeaderPPParsable) : $(syscallsHeader)
123 # build gensyscallinfos
125 local gensyscallinfos = gensyscallinfos_$(architecture) ;
126 SourceHdrs gensyscallinfos.cpp
127 : [ FDirName $(SUBDIR) arch $(TARGET_ARCH_$(architecture)) ] ;
128 BuildPlatformMain $(gensyscallinfos)
129 : gensyscallinfos.cpp
130 : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++)
133 # generate the syscall infos source file and the source for the header
136 local syscallInfos = [ FGristFiles gensyscalls_infos.cpp ] ;
137 local syscallTypesSizesSource
138 = [ FGristFiles syscall_types_sizes.h.cpp ] ;
139 local syscallTypesSizes = [ FGristFiles syscall_types_sizes.h ] ;
140 MakeLocateArch $(syscallInfos) $(syscallTypesSizesSource)
141 $(syscallTypesSizes) ;
143 GenSyscallInfos $(syscallInfos) $(syscallTypesSizesSource)
144 : $(syscallsHeaderPPParsable) : $(gensyscallinfos) ;
146 TARGET_HDRS_$(architecture) on $(syscallTypesSizes)
147 = [ on $(syscallTypesSizes) return $(TARGET_HDRS_$(architecture)) ]
148 [ FDirName $(SUBDIR) arch $(TARGET_ARCH_$(architecture)) ]
149 $(TARGET_PRIVATE_SYSTEM_HEADERS_$(architecture)) ;
150 CreateAsmStructOffsetsHeader $(syscallTypesSizes)
151 : $(syscallTypesSizesSource) ;
153 #Includes $(syscallInfos) : $(syscallTypesSizes) ;
154 # explicitly tell jam about the inclusion of the generated header
155 Depends $(syscallInfos:S=$(SUFOBJ)) : $(syscallTypesSizes) ;
156 # NOTE: Jam messes up the "Includes" declaration, so we have to declare
157 # the dependency more directly.
161 local gensyscalls = gensyscalls_$(architecture) ;
162 BuildPlatformMain $(gensyscalls)
163 : gensyscalls.cpp $(syscallInfos) ;
164 LinkAgainst $(gensyscalls) : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ;
166 # generate the output files
168 # place them where they are needed
169 local dir = $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(architecture)) ;
170 MakeLocate <syscalls!$(architecture)>syscalls.S.inc
171 : [ FDirName $(dir) system libroot os ] ;
172 MakeLocate <syscalls!$(architecture)>syscall_dispatcher.h
173 : [ FDirName $(dir) system kernel ] ;
174 MakeLocate <syscalls!$(architecture)>syscall_numbers.h
175 : [ FDirName $(dir) system kernel ] ;
176 MakeLocate <syscalls!$(architecture)>syscall_table.h
177 : [ FDirName $(dir) system kernel ] ;
178 MakeLocate <syscalls!$(architecture)>strace_syscalls.h
179 : [ FDirName $(dir) bin debug strace ] ;
181 GenSyscallsFile <syscalls!$(architecture)>syscalls.S.inc
182 : $(gensyscalls) : -c ;
183 GenSyscallsFile <syscalls!$(architecture)>syscall_dispatcher.h
184 : $(gensyscalls) : -d ;
185 GenSyscallsFile <syscalls!$(architecture)>syscall_numbers.h
186 : $(gensyscalls) : -n ;
187 GenSyscallsFile <syscalls!$(architecture)>syscall_table.h
188 : $(gensyscalls) : -t ;
189 GenSyscallsFile <syscalls!$(architecture)>strace_syscalls.h
190 : $(gensyscalls) : -s ;