1 | # |
---|
2 | # Copyright (c) 2015-2016 Chris Johns <chrisj@rtems.org>. All rights reserved. |
---|
3 | # |
---|
4 | # Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. |
---|
5 | # |
---|
6 | # embedded brains GmbH |
---|
7 | # Dornierstr. 4 |
---|
8 | # 82178 Puchheim |
---|
9 | # Germany |
---|
10 | # <info@embedded-brains.de> |
---|
11 | # |
---|
12 | # Copyright (c) 2012 OAR Corporation. All rights reserved. |
---|
13 | # |
---|
14 | # Redistribution and use in source and binary forms, with or without |
---|
15 | # modification, are permitted provided that the following conditions |
---|
16 | # are met: |
---|
17 | # 1. Redistributions of source code must retain the above copyright |
---|
18 | # notice, this list of conditions and the following disclaimer. |
---|
19 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
20 | # notice, this list of conditions and the following disclaimer in the |
---|
21 | # documentation and/or other materials provided with the distribution. |
---|
22 | # |
---|
23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
27 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
34 | |
---|
35 | from __future__ import print_function |
---|
36 | |
---|
37 | import os |
---|
38 | import sys |
---|
39 | import tempfile |
---|
40 | |
---|
41 | import builder |
---|
42 | |
---|
43 | # |
---|
44 | # Dump the data created from the fragments returned from the builder composers. |
---|
45 | # |
---|
46 | trace = False |
---|
47 | |
---|
48 | data = { } |
---|
49 | |
---|
50 | def _addFiles(name, files): |
---|
51 | if type(files) is not list: |
---|
52 | files = [files] |
---|
53 | if name not in data: |
---|
54 | data[name] = [] |
---|
55 | data[name] += files |
---|
56 | |
---|
57 | def _cflagsIncludes(cflags, includes): |
---|
58 | if type(cflags) is not list: |
---|
59 | if cflags is not None: |
---|
60 | _cflags = cflags.split(' ') |
---|
61 | else: |
---|
62 | _cflags = [None] |
---|
63 | else: |
---|
64 | _cflags = cflags |
---|
65 | if type(includes) is not list: |
---|
66 | _includes = [includes] |
---|
67 | else: |
---|
68 | _includes = includes |
---|
69 | return _cflags, _includes |
---|
70 | |
---|
71 | class SourceFileFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
72 | |
---|
73 | def __init__(self, cflags = "default", includes = None): |
---|
74 | self.cflags, self.includes = _cflagsIncludes(cflags, includes) |
---|
75 | |
---|
76 | def compose(self, path): |
---|
77 | if None in self.includes: |
---|
78 | flags = self.cflags |
---|
79 | else: |
---|
80 | flags = self.cflags + self.includes |
---|
81 | return ['sources', flags, ('default', None)], [path], self.cflags, self.includes |
---|
82 | |
---|
83 | class SourceFileIfHeaderComposer(SourceFileFragmentComposer): |
---|
84 | |
---|
85 | def __init__(self, headers, cflags = "default", includes = None): |
---|
86 | if headers is not list: |
---|
87 | headers = [headers] |
---|
88 | self.headers = headers |
---|
89 | super(SourceFileIfHeaderComposer, self).__init__(cflags = cflags, includes = includes) |
---|
90 | |
---|
91 | def compose(self, path): |
---|
92 | r = SourceFileFragmentComposer.compose(self, path) |
---|
93 | define_keys = '' |
---|
94 | for h in self.headers: |
---|
95 | h = h.upper() |
---|
96 | for c in '\/-.': |
---|
97 | h = h.replace(c, '_') |
---|
98 | define_keys += ' ' + h |
---|
99 | r[0][2] = (define_keys.strip(), self.headers) |
---|
100 | return r |
---|
101 | |
---|
102 | class TestFragementComposer(builder.BuildSystemFragmentComposer): |
---|
103 | |
---|
104 | def __init__(self, testName, fileFragments, runTest = True, netTest = False): |
---|
105 | self.testName = testName |
---|
106 | self.fileFragments = fileFragments |
---|
107 | self.runTest = runTest |
---|
108 | self.netTest = netTest |
---|
109 | |
---|
110 | def compose(self, path): |
---|
111 | return ['tests', self.testName, ('default', None)], { 'files': self.fileFragments, |
---|
112 | 'run': self.runTest, |
---|
113 | 'net': self.netTest } |
---|
114 | |
---|
115 | class TestIfHeaderComposer(TestFragementComposer): |
---|
116 | |
---|
117 | def __init__(self, testName, headers, fileFragments, runTest = True, netTest = False): |
---|
118 | if headers is not list: |
---|
119 | headers = [headers] |
---|
120 | self.headers = headers |
---|
121 | super(TestIfHeaderComposer, self).__init__(testName, fileFragments, |
---|
122 | runTest = runTest, netTest = netTest) |
---|
123 | |
---|
124 | def compose(self, path): |
---|
125 | r = TestFragementComposer.compose(self, path) |
---|
126 | define_keys = '' |
---|
127 | for h in self.headers: |
---|
128 | h = h.upper() |
---|
129 | for c in '\/-.': |
---|
130 | h = h.replace(c, '_') |
---|
131 | define_keys += ' ' + h |
---|
132 | r[0][2] = (define_keys.strip(), self.headers) |
---|
133 | return r |
---|
134 | |
---|
135 | class KVMSymbolsFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
136 | |
---|
137 | def compose(self, path): |
---|
138 | return ['KVMSymbols', 'files', ('default', None)], [path], self.includes |
---|
139 | |
---|
140 | class RPCGENFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
141 | |
---|
142 | def compose(self, path): |
---|
143 | return ['RPCGen', 'files', ('default', None)], [path] |
---|
144 | |
---|
145 | class RouteKeywordsFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
146 | |
---|
147 | def compose(self, path): |
---|
148 | return ['RouteKeywords', 'files', ('default', None)], [path] |
---|
149 | |
---|
150 | class LexFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
151 | |
---|
152 | def __init__(self, sym, dep, cflags = None, includes = None): |
---|
153 | self.sym = sym |
---|
154 | self.dep = dep |
---|
155 | self.cflags, self.includes = _cflagsIncludes(cflags, includes) |
---|
156 | |
---|
157 | def compose(self, path): |
---|
158 | d = { 'file': path, |
---|
159 | 'sym': self.sym, |
---|
160 | 'dep': self.dep } |
---|
161 | if None not in self.cflags: |
---|
162 | d['cflags'] = self.cflags |
---|
163 | if None not in self.includes: |
---|
164 | d['includes'] = self.includes |
---|
165 | return ['lex', path, ('default', None)], d |
---|
166 | |
---|
167 | class YaccFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
168 | |
---|
169 | def __init__(self, sym, header, cflags = None, includes = None): |
---|
170 | self.sym = sym |
---|
171 | self.header = header |
---|
172 | self.cflags, self.includes = _cflagsIncludes(cflags, includes) |
---|
173 | |
---|
174 | def compose(self, path): |
---|
175 | d = { 'file': path, |
---|
176 | 'sym': self.sym, |
---|
177 | 'header': self.header } |
---|
178 | if None not in self.cflags: |
---|
179 | d['cflags'] = self.cflags |
---|
180 | if None not in self.includes: |
---|
181 | d['includes'] = self.includes |
---|
182 | return ['yacc', path, ('default', None)], d |
---|
183 | |
---|
184 | # Module Manager - Collection of Modules |
---|
185 | class ModuleManager(builder.ModuleManager): |
---|
186 | |
---|
187 | def restart(self): |
---|
188 | self.script = '' |
---|
189 | |
---|
190 | def add(self, line = ''): |
---|
191 | self.script += line + os.linesep |
---|
192 | |
---|
193 | def write(self): |
---|
194 | name = os.path.join(builder.RTEMS_DIR, 'libbsd_waf.py') |
---|
195 | converter = builder.Converter() |
---|
196 | converter.convert(name, name, srcContents = self.script) |
---|
197 | |
---|
198 | def setGenerators(self): |
---|
199 | self.generator['convert'] = builder.Converter |
---|
200 | self.generator['no-convert'] = builder.NoConverter |
---|
201 | |
---|
202 | self.generator['file'] = builder.File |
---|
203 | |
---|
204 | self.generator['path'] = builder.PathComposer |
---|
205 | self.generator['freebsd-path'] = builder.FreeBSDPathComposer |
---|
206 | self.generator['rtems-path'] = builder.RTEMSPathComposer |
---|
207 | self.generator['cpu-path'] = builder.CPUDependentPathComposer |
---|
208 | self.generator['target-src-cpu--path'] = builder.TargetSourceCPUDependentPathComposer |
---|
209 | |
---|
210 | self.generator['source'] = SourceFileFragmentComposer |
---|
211 | self.generator['test'] = TestFragementComposer |
---|
212 | self.generator['kvm-symbols'] = KVMSymbolsFragmentComposer |
---|
213 | self.generator['rpc-gen'] = RPCGENFragmentComposer |
---|
214 | self.generator['route-keywords'] = RouteKeywordsFragmentComposer |
---|
215 | self.generator['lex'] = LexFragmentComposer |
---|
216 | self.generator['yacc'] = YaccFragmentComposer |
---|
217 | |
---|
218 | self.generator['source-if-header'] = SourceFileIfHeaderComposer |
---|
219 | self.generator['test-if-header'] = TestIfHeaderComposer |
---|
220 | |
---|
221 | def generate(self, rtems_version): |
---|
222 | |
---|
223 | def _sourceListSources(lhs, sources, append = False, block = 0): |
---|
224 | indent = block * 4 |
---|
225 | if append: |
---|
226 | adder = '+' |
---|
227 | adderSpace = ' ' |
---|
228 | else: |
---|
229 | adder = '' |
---|
230 | adderSpace = '' |
---|
231 | ll = len(lhs) |
---|
232 | if len(sources) == 1: |
---|
233 | self.add('%s%s %s= [%r]' % (' ' * indent, lhs, adder, sources[0])) |
---|
234 | elif len(sources) == 2: |
---|
235 | self.add('%s%s %s= [%r,' % (' ' * indent, lhs, adder, sources[0])) |
---|
236 | self.add('%s%s %s %r]' % (' ' * indent, ' ' * ll, adderSpace, sources[-1])) |
---|
237 | elif len(sources) > 0: |
---|
238 | self.add('%s%s %s= [%r,' % (' ' * indent, lhs, adder, sources[0])) |
---|
239 | for f in sources[1:-1]: |
---|
240 | self.add('%s%s %s %r,' % (' ' * indent, ' ' * ll, adderSpace, f)) |
---|
241 | self.add('%s%s %s %r]' % (' ' * indent, ' ' * ll, adderSpace, sources[-1])) |
---|
242 | |
---|
243 | def _sourceList(lhs, files, append = False): |
---|
244 | if type(files) is dict: |
---|
245 | appending = False |
---|
246 | for cfg in files: |
---|
247 | if cfg in ['cflags', 'includes']: |
---|
248 | continue |
---|
249 | if cfg != 'default': |
---|
250 | cs = '' |
---|
251 | ors = '' |
---|
252 | for c in cfg.split(' '): |
---|
253 | cs += '%s bld.env["HAVE_%s"]' % (ors, c) |
---|
254 | ors = ' and' |
---|
255 | self.add(' if%s:' % (cs)) |
---|
256 | _sourceListSources(lhs, sorted(files[cfg]), append = appending, block = 1) |
---|
257 | else: |
---|
258 | _sourceListSources(lhs, sorted(files[cfg]), append) |
---|
259 | appending = True |
---|
260 | else: |
---|
261 | _sourceListSources(lhs, sorted(files), append) |
---|
262 | |
---|
263 | def _dataInsert(data, cpu, frag): |
---|
264 | # |
---|
265 | # The default handler returns an empty string. Skip it. |
---|
266 | # |
---|
267 | if type(frag) is not str: |
---|
268 | # Start at the top of the tree |
---|
269 | d = data |
---|
270 | path = frag[0] |
---|
271 | if path[0] not in d: |
---|
272 | d[path[0]] = {} |
---|
273 | # Select the sub-part of the tree as the compile options |
---|
274 | # specialise how files are built. |
---|
275 | d = d[path[0]] |
---|
276 | if type(path[1]) is list: |
---|
277 | p = ' '.join(path[1]) |
---|
278 | else: |
---|
279 | p = path[1] |
---|
280 | if p not in d: |
---|
281 | d[p] = {} |
---|
282 | d = d[p] |
---|
283 | if cpu not in d: |
---|
284 | d[cpu] = { } |
---|
285 | config = frag[0][2][0] |
---|
286 | if config != 'default': |
---|
287 | if 'configure' not in data: |
---|
288 | data['configure'] = { } |
---|
289 | data['configure'][config] = frag[0][2][1] |
---|
290 | if type(frag[1]) is list: |
---|
291 | if config not in d[cpu]: |
---|
292 | d[cpu][config] = [] |
---|
293 | d[cpu][config] += frag[1] |
---|
294 | else: |
---|
295 | d[cpu][config] = frag[1] |
---|
296 | # |
---|
297 | # The CPU is for files and the flags and includes are common. |
---|
298 | # |
---|
299 | if len(frag) > 3: |
---|
300 | if 'cflags' not in d: |
---|
301 | d['cflags'] = [] |
---|
302 | d['cflags'] += frag[2] |
---|
303 | d['cflags'] = list(set(d['cflags'])) |
---|
304 | if len(frag) >= 3 and None not in frag[-1]: |
---|
305 | if 'includes' not in d: |
---|
306 | d['includes'] = [] |
---|
307 | d['includes'] += frag[-1] |
---|
308 | d['includes'] = list(set(d['includes'])) |
---|
309 | |
---|
310 | data = { } |
---|
311 | |
---|
312 | for mn in self.getModules(): |
---|
313 | m = self[mn] |
---|
314 | if m.conditionalOn == "none": |
---|
315 | for f in m.files: |
---|
316 | _dataInsert(data, 'all', f.getFragment()) |
---|
317 | for cpu, files in sorted(m.cpuDependentSourceFiles.items()): |
---|
318 | for f in files: |
---|
319 | _dataInsert(data, cpu, f.getFragment()) |
---|
320 | |
---|
321 | if trace: |
---|
322 | import pprint |
---|
323 | pprint.pprint(data) |
---|
324 | |
---|
325 | self.restart() |
---|
326 | |
---|
327 | self.add('#') |
---|
328 | self.add('# RTEMS Project (https://www.rtems.org)') |
---|
329 | self.add('#') |
---|
330 | self.add('# Generated waf script. Do not edit, run ./freebsd-to-rtems.py -m') |
---|
331 | self.add('#') |
---|
332 | self.add('# To use see README.waf shipped with this file.') |
---|
333 | self.add('#') |
---|
334 | self.add('') |
---|
335 | self.add('from __future__ import print_function') |
---|
336 | self.add('') |
---|
337 | self.add('import os') |
---|
338 | self.add('import os.path') |
---|
339 | # Import check done in the top level wscript file. |
---|
340 | self.add('import rtems_waf.rtems as rtems') |
---|
341 | self.add('') |
---|
342 | self.add('windows = os.name == "nt"') |
---|
343 | self.add('') |
---|
344 | self.add('if windows:') |
---|
345 | self.add(' host_shell = "sh -c "') |
---|
346 | self.add('else:') |
---|
347 | self.add(' host_shell = ""') |
---|
348 | self.add('') |
---|
349 | self.add('def init(ctx):') |
---|
350 | self.add(' pass') |
---|
351 | self.add('') |
---|
352 | self.add('def options(opt):') |
---|
353 | self.add(' pass') |
---|
354 | self.add('') |
---|
355 | self.add('def bsp_configure(conf, arch_bsp):') |
---|
356 | |
---|
357 | if 'configure' in data: |
---|
358 | for cfg in data['configure']: |
---|
359 | for h in data['configure'][cfg]: |
---|
360 | self.add(' conf.check(header_name = "%s", features = "c", includes = conf.env.IFLAGS, mandatory = False)' % h) |
---|
361 | else: |
---|
362 | self.add(' pass') |
---|
363 | |
---|
364 | self.add('') |
---|
365 | self.add('def configure(conf):') |
---|
366 | self.add(' rtems.configure(conf, bsp_configure)') |
---|
367 | self.add('') |
---|
368 | self.add('def build(bld):') |
---|
369 | self.add(' # C/C++ flags') |
---|
370 | self.add(' common_flags = []') |
---|
371 | for f in builder.commonFlags(): |
---|
372 | self.add(' common_flags += ["%s"]' % (f)) |
---|
373 | self.add(' if bld.env.WARNINGS:') |
---|
374 | for f in builder.commonWarnings(): |
---|
375 | self.add(' common_flags += ["%s"]' % (f)) |
---|
376 | self.add(' else:') |
---|
377 | for f in builder.commonNoWarnings(): |
---|
378 | self.add(' common_flags += ["%s"]' % (f)) |
---|
379 | self.add(' cflags = %r + common_flags' % (builder.cflags())) |
---|
380 | self.add(' cxxflags = %r + common_flags' % (builder.cxxflags())) |
---|
381 | self.add('') |
---|
382 | self.add(' # Defines') |
---|
383 | self.add(' defines = []') |
---|
384 | self.add(' if len(bld.env.FREEBSD_OPTIONS) > 0:') |
---|
385 | self.add(' for o in bld.env.FREEBSD_OPTIONS.split(","):') |
---|
386 | self.add(' defines += ["%s=1" % (o.strip().upper())]') |
---|
387 | self.add('') |
---|
388 | self.add(' # Include paths') |
---|
389 | self.add(' includes = []') |
---|
390 | self.add(' for i in %r:' % (builder.cpuIncludes())) |
---|
391 | self.add(' includes += ["%s" % (i[2:].replace("@CPU@", bld.get_env()["RTEMS_ARCH"]))]') |
---|
392 | self.add(' if bld.get_env()["RTEMS_ARCH"] == "i386":') |
---|
393 | self.add(' for i in %r:' % (builder.cpuIncludes())) |
---|
394 | self.add(' includes += ["%s" % (i[2:].replace("@CPU@", "x86"))]') |
---|
395 | for i in builder.includes(): |
---|
396 | self.add(' includes += ["%s"]' % (i[2:])) |
---|
397 | self.add('') |
---|
398 | self.add(' # Collect the libbsd uses') |
---|
399 | self.add(' libbsd_use = []') |
---|
400 | self.add('') |
---|
401 | |
---|
402 | # |
---|
403 | # Support the existing Makefile based network configuration file. |
---|
404 | # |
---|
405 | self.add(' # Network test configuration') |
---|
406 | self.add(' if not os.path.exists(bld.env.NET_CONFIG):') |
---|
407 | self.add(' bld.fatal("network configuraiton \'%s\' not found" % (bld.env.NET_CONFIG))') |
---|
408 | self.add(' net_cfg_self_ip = None') |
---|
409 | self.add(' net_cfg_netmask = None') |
---|
410 | self.add(' net_cfg_peer_ip = None') |
---|
411 | self.add(' net_cfg_gateway_ip = None') |
---|
412 | self.add(' net_tap_interface = None') |
---|
413 | self.add(' try:') |
---|
414 | self.add(' net_cfg_lines = open(bld.env.NET_CONFIG).readlines()') |
---|
415 | self.add(' except:') |
---|
416 | self.add(' bld.fatal("network configuraiton \'%s\' read failed" % (bld.env.NET_CONFIG))') |
---|
417 | self.add(' lc = 0') |
---|
418 | self.add(' for l in net_cfg_lines:') |
---|
419 | self.add(' lc += 1') |
---|
420 | self.add(' if l.strip().startswith("NET_CFG_"):') |
---|
421 | self.add(' ls = l.split("=")') |
---|
422 | self.add(' if len(ls) != 2:') |
---|
423 | self.add(' bld.fatal("network configuraiton \'%s\' parse error: %d: %s" % ' + \ |
---|
424 | '(bld.env.NET_CONFIG, lc, l))') |
---|
425 | self.add(' lhs = ls[0].strip()') |
---|
426 | self.add(' rhs = ls[1].strip()') |
---|
427 | self.add(' if lhs == "NET_CFG_SELF_IP":') |
---|
428 | self.add(' net_cfg_self_ip = rhs') |
---|
429 | self.add(' if lhs == "NET_CFG_NETMASK":') |
---|
430 | self.add(' net_cfg_netmask = rhs') |
---|
431 | self.add(' if lhs == "NET_CFG_PEER_IP":') |
---|
432 | self.add(' net_cfg_peer_ip = rhs') |
---|
433 | self.add(' if lhs == "NET_CFG_GATEWAY_IP":') |
---|
434 | self.add(' net_cfg_gateway_ip = rhs') |
---|
435 | self.add(' if lhs == "NET_TAP_INTERFACE":') |
---|
436 | self.add(' net_tap_interface = rhs') |
---|
437 | self.add(' bld(target = "testsuite/include/rtems/bsd/test/network-config.h",') |
---|
438 | self.add(' source = "testsuite/include/rtems/bsd/test/network-config.h.in",') |
---|
439 | self.add(' rule = "sed -e \'s/@NET_CFG_SELF_IP@/%s/\' ' + \ |
---|
440 | '-e \'s/@NET_CFG_NETMASK@/%s/\' ' + \ |
---|
441 | '-e \'s/@NET_CFG_PEER_IP@/%s/\' ' + \ |
---|
442 | '-e \'s/@NET_CFG_GATEWAY_IP@/%s/\' < ${SRC} > ${TGT}" % ' + \ |
---|
443 | '(net_cfg_self_ip, net_cfg_netmask, net_cfg_peer_ip, net_cfg_gateway_ip),') |
---|
444 | self.add(' update_outputs = True)') |
---|
445 | self.add('') |
---|
446 | |
---|
447 | # |
---|
448 | # Add the specific rule based builders for generating files. |
---|
449 | # |
---|
450 | if 'KVMSymbols' in data: |
---|
451 | kvmsymbols = data['KVMSymbols'] |
---|
452 | if 'includes' in kvmsymbols['files']: |
---|
453 | includes = kvmsymbols['files']['includes'] |
---|
454 | else: |
---|
455 | includes = [] |
---|
456 | self.add(' # KVM Symbols') |
---|
457 | self.add(' bld(target = "%s",' % (kvmsymbols['files']['all']['default'][0])) |
---|
458 | self.add(' source = "rtemsbsd/rtems/generate_kvm_symbols",') |
---|
459 | self.add(' rule = host_shell + "./${SRC} > ${TGT}",') |
---|
460 | self.add(' update_outputs = True)') |
---|
461 | self.add(' bld.objects(target = "kvmsymbols",') |
---|
462 | self.add(' features = "c",') |
---|
463 | self.add(' cflags = cflags,') |
---|
464 | self.add(' includes = %r + includes,' % (includes)) |
---|
465 | self.add(' source = "%s")' % (kvmsymbols['files']['all']['default'][0])) |
---|
466 | self.add(' libbsd_use += ["kvmsymbols"]') |
---|
467 | self.add('') |
---|
468 | |
---|
469 | self.add(' bld.add_group()') |
---|
470 | |
---|
471 | if 'RPCGen' in data: |
---|
472 | rpcgen = data['RPCGen'] |
---|
473 | rpcname = rpcgen['files']['all']['default'][0][:-2] |
---|
474 | self.add(' # RPC Generation') |
---|
475 | self.add(' if bld.env.AUTO_REGEN:') |
---|
476 | self.add(' bld(target = "%s.h",' % (rpcname)) |
---|
477 | self.add(' source = "%s.x",' % (rpcname)) |
---|
478 | self.add(' rule = host_shell + "${RPCGEN} -h -o ${TGT} ${SRC}")') |
---|
479 | self.add('') |
---|
480 | |
---|
481 | if 'RouteKeywords' in data: |
---|
482 | routekw = data['RouteKeywords'] |
---|
483 | rkwname = routekw['files']['all']['default'][0] |
---|
484 | self.add(' # Route keywords') |
---|
485 | self.add(' if bld.env.AUTO_REGEN:') |
---|
486 | self.add(' rkw_rule = host_shell + "cat ${SRC} | ' + \ |
---|
487 | 'awk \'BEGIN { r = 0 } { if (NF == 1) ' + \ |
---|
488 | 'printf \\"#define\\\\tK_%%s\\\\t%%d\\\\n\\\\t{\\\\\\"%%s\\\\\\", K_%%s},\\\\n\\", ' + \ |
---|
489 | 'toupper($1), ++r, $1, toupper($1)}\' > ${TGT}"') |
---|
490 | self.add(' bld(target = "%s.h",' % (rkwname)) |
---|
491 | self.add(' source = "%s",' % (rkwname)) |
---|
492 | self.add(' rule = rkw_rule)') |
---|
493 | self.add('') |
---|
494 | |
---|
495 | if 'lex' in data: |
---|
496 | lexes = data['lex'] |
---|
497 | self.add(' # Lex') |
---|
498 | for l in sorted(lexes.keys()): |
---|
499 | lex = lexes[l]['all']['default'] |
---|
500 | if 'cflags' in lex: |
---|
501 | lexDefines = [d[2:] for d in lex['cflags']] |
---|
502 | else: |
---|
503 | lexDefines = [] |
---|
504 | if 'includes' in lex: |
---|
505 | lexIncludes = lex['includes'] |
---|
506 | else: |
---|
507 | lexIncludes = [] |
---|
508 | self.add(' if bld.env.AUTO_REGEN:') |
---|
509 | self.add(' bld(target = "%s.c",' % (lex['file'][:-2])) |
---|
510 | self.add(' source = "%s",' % (lex['file'])) |
---|
511 | self.add(' rule = host_shell + "${LEX} -P %s -t ${SRC} | ' % (lex['sym']) + \ |
---|
512 | 'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' > ${TGT}")') |
---|
513 | self.add(' bld.objects(target = "lex_%s",' % (lex['sym'])) |
---|
514 | self.add(' features = "c",') |
---|
515 | self.add(' cflags = cflags,') |
---|
516 | self.add(' includes = %r + includes,' % (lexIncludes)) |
---|
517 | self.add(' defines = defines + %r,' % (lexDefines)) |
---|
518 | self.add(' source = "%s.c")' % (lex['file'][:-2])) |
---|
519 | self.add(' libbsd_use += ["lex_%s"]' % (lex['sym'])) |
---|
520 | self.add('') |
---|
521 | |
---|
522 | if 'yacc' in data: |
---|
523 | yaccs = data['yacc'] |
---|
524 | self.add(' # Yacc') |
---|
525 | for y in sorted(yaccs.keys()): |
---|
526 | yacc = yaccs[y]['all']['default'] |
---|
527 | yaccFile = yacc['file'] |
---|
528 | if yacc['sym'] is not None: |
---|
529 | yaccSym = yacc['sym'] |
---|
530 | else: |
---|
531 | yaccSym = os.path.basename(yaccFile)[:-2] |
---|
532 | yaccHeader = '%s/%s' % (os.path.dirname(yaccFile), yacc['header']) |
---|
533 | if 'cflags' in yacc: |
---|
534 | yaccDefines = [d[2:] for d in yacc['cflags']] |
---|
535 | else: |
---|
536 | yaccDefines = [] |
---|
537 | if 'includes' in yacc: |
---|
538 | yaccIncludes = yacc['includes'] |
---|
539 | else: |
---|
540 | yaccIncludes = [] |
---|
541 | self.add(' if bld.env.AUTO_REGEN:') |
---|
542 | self.add(' bld(target = "%s.c",' % (yaccFile[:-2])) |
---|
543 | self.add(' source = "%s",' % (yaccFile)) |
---|
544 | self.add(' rule = host_shell + "${YACC} -b %s -d -p %s ${SRC} && ' % \ |
---|
545 | (yaccSym, yaccSym) + \ |
---|
546 | 'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' < %s.tab.c > ${TGT} && ' % (yaccSym) + \ |
---|
547 | 'rm -f %s.tab.c && mv %s.tab.h %s")' % (yaccSym, yaccSym, yaccHeader)) |
---|
548 | self.add(' bld.objects(target = "yacc_%s",' % (yaccSym)) |
---|
549 | self.add(' features = "c",') |
---|
550 | self.add(' cflags = cflags,') |
---|
551 | self.add(' includes = %r + includes,' % (yaccIncludes)) |
---|
552 | self.add(' defines = defines + %r,' % (yaccDefines)) |
---|
553 | self.add(' source = "%s.c")' % (yaccFile[:-2])) |
---|
554 | self.add(' libbsd_use += ["yacc_%s"]' % (yaccSym)) |
---|
555 | self.add('') |
---|
556 | |
---|
557 | # |
---|
558 | # We have 'm' different sets of flags and there can be 'n' cpus |
---|
559 | # specific files for those flags. |
---|
560 | # |
---|
561 | objs = 0 |
---|
562 | self.add(' # Objects built with different CFLAGS') |
---|
563 | sources = sorted(data['sources']) |
---|
564 | if 'default' in sources: |
---|
565 | sources.remove('default') |
---|
566 | for flags in sources: |
---|
567 | objs += 1 |
---|
568 | build = data['sources'][flags] |
---|
569 | _sourceList(' objs%02d_source' % objs, build['all']) |
---|
570 | archs = sorted(build) |
---|
571 | for i in ['all', 'cflags', 'includes']: |
---|
572 | if i in archs: |
---|
573 | archs.remove(i) |
---|
574 | for arch in archs: |
---|
575 | self.add(' if bld.get_env()["RTEMS_ARCH"] == "%s":' % arch) |
---|
576 | _sourceList(' objs%02d_source' % objs, build[arch], append = True) |
---|
577 | if 'cflags' in build: |
---|
578 | defines = [d[2:] for d in build['cflags']] |
---|
579 | else: |
---|
580 | defines = [] |
---|
581 | if 'includes' in build: |
---|
582 | includes = build['includes'] |
---|
583 | else: |
---|
584 | includes = [] |
---|
585 | self.add(' bld.objects(target = "objs%02d",' % (objs)) |
---|
586 | self.add(' features = "c",') |
---|
587 | self.add(' cflags = cflags,') |
---|
588 | self.add(' includes = %r + includes,' % (sorted(includes))) |
---|
589 | self.add(' defines = defines + %r,' % (sorted(defines))) |
---|
590 | self.add(' source = objs%02d_source)' % objs) |
---|
591 | self.add(' libbsd_use += ["objs%02d"]' % (objs)) |
---|
592 | self.add('') |
---|
593 | |
---|
594 | # |
---|
595 | # We hold the 'default' cflags set of files to the end to create the |
---|
596 | # static library with. |
---|
597 | # |
---|
598 | build = data['sources']['default'] |
---|
599 | _sourceList(' source', build['all']) |
---|
600 | archs = sorted(build) |
---|
601 | archs.remove('all') |
---|
602 | for arch in archs: |
---|
603 | self.add(' if bld.get_env()["RTEMS_ARCH"] == "%s":' % arch) |
---|
604 | _sourceList(' source', build[arch], append = True) |
---|
605 | self.add(' bld.stlib(target = "bsd",') |
---|
606 | self.add(' features = "c cxx",') |
---|
607 | self.add(' cflags = cflags,') |
---|
608 | self.add(' cxxflags = cxxflags,') |
---|
609 | self.add(' includes = includes,') |
---|
610 | self.add(' defines = defines,') |
---|
611 | self.add(' source = source,') |
---|
612 | self.add(' use = libbsd_use)') |
---|
613 | self.add('') |
---|
614 | |
---|
615 | # |
---|
616 | # Header file collector. |
---|
617 | # |
---|
618 | self.add(' # Installs. ') |
---|
619 | self.add(' bld.install_files("${PREFIX}/" + rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), ["libbsd.a"])') |
---|
620 | headerPaths = builder.headerPaths() |
---|
621 | self.add(' header_paths = [%s,' % (str(headerPaths[0]))) |
---|
622 | for hp in headerPaths[1:-1]: |
---|
623 | self.add(' %s,' % (str(hp))) |
---|
624 | self.add(' %s]' % (str(headerPaths[-1]))) |
---|
625 | self.add(' for headers in header_paths:') |
---|
626 | self.add(' ipath = os.path.join(rtems.arch_bsp_include_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), headers[2])') |
---|
627 | self.add(' start_dir = bld.path.find_dir(headers[0])') |
---|
628 | self.add(' bld.install_files("${PREFIX}/" + ipath,') |
---|
629 | self.add(' start_dir.ant_glob("**/" + headers[1]),') |
---|
630 | self.add(' cwd = start_dir,') |
---|
631 | self.add(' relative_trick = True)') |
---|
632 | self.add('') |
---|
633 | |
---|
634 | self.add(' # Tests') |
---|
635 | tests = data['tests'] |
---|
636 | for testName in sorted(tests): |
---|
637 | test = data['tests'][testName]['all'] |
---|
638 | block = 0 |
---|
639 | files = [] |
---|
640 | for cfg in test: |
---|
641 | if cfg != 'default': |
---|
642 | cs = '' |
---|
643 | ors = '' |
---|
644 | for c in cfg.split(' '): |
---|
645 | cs += '%s bld.env["HAVE_%s"]' % (ors, c) |
---|
646 | ors = ' and' |
---|
647 | self.add(' if%s:' % (cs)) |
---|
648 | block = 1 |
---|
649 | files = ['testsuite/%s/%s.c' % (testName, f) \ |
---|
650 | for f in test[cfg]['files']] |
---|
651 | indent = ' ' * block * 4 |
---|
652 | _sourceList('%s test_%s' % (indent, testName), files) |
---|
653 | self.add('%s bld.program(target = "%s.exe",' % (indent, testName)) |
---|
654 | self.add('%s features = "cprogram",' % (indent)) |
---|
655 | self.add('%s cflags = cflags,' % (indent)) |
---|
656 | self.add('%s includes = includes,' % (indent)) |
---|
657 | self.add('%s source = test_%s,' % (indent, testName)) |
---|
658 | self.add('%s use = ["bsd"],' % (indent)) |
---|
659 | self.add('%s lib = ["m", "z"],' % (indent)) |
---|
660 | self.add('%s install_path = None)' % (indent)) |
---|
661 | self.add('') |
---|
662 | |
---|
663 | self.write() |
---|