1 | # |
---|
2 | # Copyright (c) 2015-2018 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 | import rtems_waf.rtems as rtems |
---|
44 | |
---|
45 | windows = os.name == 'nt' |
---|
46 | |
---|
47 | if windows: |
---|
48 | host_shell = 'sh -c ' |
---|
49 | else: |
---|
50 | host_shell = '' |
---|
51 | |
---|
52 | def _cflagsIncludes(cflags, includes): |
---|
53 | if type(cflags) is not list: |
---|
54 | if cflags is not None: |
---|
55 | _cflags = cflags.split(' ') |
---|
56 | else: |
---|
57 | _cflags = [None] |
---|
58 | else: |
---|
59 | _cflags = cflags |
---|
60 | if type(includes) is not list: |
---|
61 | _includes = [includes] |
---|
62 | else: |
---|
63 | _includes = includes |
---|
64 | return _cflags, _includes |
---|
65 | |
---|
66 | class SourceFileFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
67 | |
---|
68 | def __init__(self, cflags = "default", includes = None): |
---|
69 | self.cflags, self.includes = _cflagsIncludes(cflags, includes) |
---|
70 | |
---|
71 | def compose(self, path): |
---|
72 | if None in self.includes: |
---|
73 | flags = self.cflags |
---|
74 | else: |
---|
75 | flags = self.cflags + self.includes |
---|
76 | return ['sources', flags, ('default', None)], [path], self.cflags, self.includes |
---|
77 | |
---|
78 | class SourceFileIfHeaderComposer(SourceFileFragmentComposer): |
---|
79 | |
---|
80 | def __init__(self, headers, cflags = "default", includes = None): |
---|
81 | if headers is not list: |
---|
82 | headers = [headers] |
---|
83 | self.headers = headers |
---|
84 | super(SourceFileIfHeaderComposer, self).__init__(cflags = cflags, includes = includes) |
---|
85 | |
---|
86 | def compose(self, path): |
---|
87 | r = SourceFileFragmentComposer.compose(self, path) |
---|
88 | define_keys = '' |
---|
89 | for h in self.headers: |
---|
90 | h = h.upper() |
---|
91 | for c in '\/-.': |
---|
92 | h = h.replace(c, '_') |
---|
93 | define_keys += ' ' + h |
---|
94 | r[0][2] = (define_keys.strip(), self.headers) |
---|
95 | return r |
---|
96 | |
---|
97 | class TestFragementComposer(builder.BuildSystemFragmentComposer): |
---|
98 | |
---|
99 | def __init__(self, testName, fileFragments, runTest = True, netTest = False): |
---|
100 | self.testName = testName |
---|
101 | self.fileFragments = fileFragments |
---|
102 | self.runTest = runTest |
---|
103 | self.netTest = netTest |
---|
104 | |
---|
105 | def compose(self, path): |
---|
106 | return ['tests', self.testName, ('default', None)], { 'files': self.fileFragments, |
---|
107 | 'run': self.runTest, |
---|
108 | 'net': self.netTest } |
---|
109 | |
---|
110 | class TestIfHeaderComposer(TestFragementComposer): |
---|
111 | |
---|
112 | def __init__(self, testName, headers, fileFragments, runTest = True, netTest = False): |
---|
113 | if headers is not list: |
---|
114 | headers = [headers] |
---|
115 | self.headers = headers |
---|
116 | super(TestIfHeaderComposer, self).__init__(testName, fileFragments, |
---|
117 | runTest = runTest, netTest = netTest) |
---|
118 | |
---|
119 | def compose(self, path): |
---|
120 | r = TestFragementComposer.compose(self, path) |
---|
121 | define_keys = '' |
---|
122 | for h in self.headers: |
---|
123 | h = h.upper() |
---|
124 | for c in '\/-.': |
---|
125 | h = h.replace(c, '_') |
---|
126 | define_keys += ' ' + h |
---|
127 | r[0][2] = (define_keys.strip(), self.headers) |
---|
128 | return r |
---|
129 | |
---|
130 | class KVMSymbolsFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
131 | |
---|
132 | def compose(self, path): |
---|
133 | return ['KVMSymbols', 'files', ('default', None)], [path], self.includes |
---|
134 | |
---|
135 | class RPCGENFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
136 | |
---|
137 | def compose(self, path): |
---|
138 | return ['RPCGen', 'files', ('default', None)], [path] |
---|
139 | |
---|
140 | class RouteKeywordsFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
141 | |
---|
142 | def compose(self, path): |
---|
143 | return ['RouteKeywords', 'files', ('default', None)], [path] |
---|
144 | |
---|
145 | class LexFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
146 | |
---|
147 | def __init__(self, sym, dep, cflags = None, includes = None): |
---|
148 | self.sym = sym |
---|
149 | self.dep = dep |
---|
150 | self.cflags, self.includes = _cflagsIncludes(cflags, includes) |
---|
151 | |
---|
152 | def compose(self, path): |
---|
153 | d = { 'file': path, |
---|
154 | 'sym': self.sym, |
---|
155 | 'dep': self.dep } |
---|
156 | if None not in self.cflags: |
---|
157 | d['cflags'] = self.cflags |
---|
158 | if None not in self.includes: |
---|
159 | d['includes'] = self.includes |
---|
160 | return ['lex', path, ('default', None)], d |
---|
161 | |
---|
162 | class YaccFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
163 | |
---|
164 | def __init__(self, sym, header, cflags = None, includes = None): |
---|
165 | self.sym = sym |
---|
166 | self.header = header |
---|
167 | self.cflags, self.includes = _cflagsIncludes(cflags, includes) |
---|
168 | |
---|
169 | def compose(self, path): |
---|
170 | d = { 'file': path, |
---|
171 | 'sym': self.sym, |
---|
172 | 'header': self.header } |
---|
173 | if None not in self.cflags: |
---|
174 | d['cflags'] = self.cflags |
---|
175 | if None not in self.includes: |
---|
176 | d['includes'] = self.includes |
---|
177 | return ['yacc', path, ('default', None)], d |
---|
178 | |
---|
179 | # |
---|
180 | # The waf builder for libbsd. |
---|
181 | # |
---|
182 | class Builder(builder.ModuleManager): |
---|
183 | |
---|
184 | def __init__(self, trace = False): |
---|
185 | super(Builder, self).__init__() |
---|
186 | self.trace = trace |
---|
187 | self.data = {} |
---|
188 | |
---|
189 | @staticmethod |
---|
190 | def _sourceList(bld, files): |
---|
191 | sources = [] |
---|
192 | if type(files) is dict: |
---|
193 | for cfg in files: |
---|
194 | if cfg in ['cflags', 'includes']: |
---|
195 | continue |
---|
196 | if cfg != 'default': |
---|
197 | for c in cfg.split(' '): |
---|
198 | if not bld.env['HAVE_%s' % (c)]: |
---|
199 | continue |
---|
200 | sources += sorted(files[cfg]) |
---|
201 | else: |
---|
202 | sources = sorted(files) |
---|
203 | return sources |
---|
204 | |
---|
205 | def setGenerators(self): |
---|
206 | # |
---|
207 | # Called when the builder.ModuleManager.__init__ is run |
---|
208 | # |
---|
209 | self.generator['convert'] = builder.Converter |
---|
210 | self.generator['no-convert'] = builder.NoConverter |
---|
211 | self.generator['from-FreeBSD-to-RTEMS-UserSpaceSourceConverter'] = builder.FromFreeBSDToRTEMSUserSpaceSourceConverter |
---|
212 | self.generator['from-RTEMS-To-FreeBSD-SourceConverter'] = builder.FromRTEMSToFreeBSDSourceConverter |
---|
213 | self.generator['buildSystemFragmentComposer'] = builder.BuildSystemFragmentComposer |
---|
214 | |
---|
215 | self.generator['file'] = builder.File |
---|
216 | |
---|
217 | self.generator['path'] = builder.PathComposer |
---|
218 | self.generator['freebsd-path'] = builder.FreeBSDPathComposer |
---|
219 | self.generator['rtems-path'] = builder.RTEMSPathComposer |
---|
220 | self.generator['cpu-path'] = builder.CPUDependentFreeBSDPathComposer |
---|
221 | self.generator['target-src-cpu--path'] = builder.TargetSourceCPUDependentPathComposer |
---|
222 | |
---|
223 | self.generator['source'] = SourceFileFragmentComposer |
---|
224 | self.generator['test'] = TestFragementComposer |
---|
225 | self.generator['kvm-symbols'] = KVMSymbolsFragmentComposer |
---|
226 | self.generator['rpc-gen'] = RPCGENFragmentComposer |
---|
227 | self.generator['route-keywords'] = RouteKeywordsFragmentComposer |
---|
228 | self.generator['lex'] = LexFragmentComposer |
---|
229 | self.generator['yacc'] = YaccFragmentComposer |
---|
230 | |
---|
231 | self.generator['source-if-header'] = SourceFileIfHeaderComposer |
---|
232 | self.generator['test-if-header'] = TestIfHeaderComposer |
---|
233 | |
---|
234 | def generate(self, rtems_version): |
---|
235 | |
---|
236 | def _dataInsert(data, cpu, frag): |
---|
237 | # |
---|
238 | # The default handler returns an empty string. Skip it. |
---|
239 | # |
---|
240 | if type(frag) is not str: |
---|
241 | # Start at the top of the tree |
---|
242 | d = data |
---|
243 | path = frag[0] |
---|
244 | if path[0] not in d: |
---|
245 | d[path[0]] = {} |
---|
246 | # Select the sub-part of the tree as the compile options |
---|
247 | # specialise how files are built. |
---|
248 | d = d[path[0]] |
---|
249 | if type(path[1]) is list: |
---|
250 | p = ' '.join(path[1]) |
---|
251 | else: |
---|
252 | p = path[1] |
---|
253 | if p not in d: |
---|
254 | d[p] = {} |
---|
255 | d = d[p] |
---|
256 | if cpu not in d: |
---|
257 | d[cpu] = { } |
---|
258 | config = frag[0][2][0] |
---|
259 | if config != 'default': |
---|
260 | if 'configure' not in data: |
---|
261 | data['configure'] = { } |
---|
262 | data['configure'][config] = frag[0][2][1] |
---|
263 | if type(frag[1]) is list: |
---|
264 | if config not in d[cpu]: |
---|
265 | d[cpu][config] = [] |
---|
266 | d[cpu][config] += frag[1] |
---|
267 | else: |
---|
268 | d[cpu][config] = frag[1] |
---|
269 | # |
---|
270 | # The CPU is for files and the flags and includes are common. |
---|
271 | # |
---|
272 | if len(frag) > 3: |
---|
273 | if 'cflags' not in d: |
---|
274 | d['cflags'] = [] |
---|
275 | d['cflags'] += frag[2] |
---|
276 | d['cflags'] = list(set(d['cflags'])) |
---|
277 | if len(frag) >= 3 and None not in frag[-1]: |
---|
278 | if 'includes' not in d: |
---|
279 | d['includes'] = [] |
---|
280 | d['includes'] += frag[-1] |
---|
281 | d['includes'] = list(set(d['includes'])) |
---|
282 | |
---|
283 | self.generateBuild() |
---|
284 | |
---|
285 | self.data = {} |
---|
286 | |
---|
287 | for mn in self.getEnabledModules(): |
---|
288 | m = self[mn] |
---|
289 | if m.conditionalOn == "none": |
---|
290 | for f in m.files: |
---|
291 | _dataInsert(self.data, 'all', f.getFragment()) |
---|
292 | for cpu, files in sorted(m.cpuDependentSourceFiles.items()): |
---|
293 | for f in files: |
---|
294 | _dataInsert(self.data, cpu, f.getFragment()) |
---|
295 | |
---|
296 | if self.trace: |
---|
297 | import pprint |
---|
298 | pprint.pprint(self.data) |
---|
299 | |
---|
300 | def init(self, ctx): |
---|
301 | pass |
---|
302 | |
---|
303 | def options(self, opt): |
---|
304 | pass |
---|
305 | |
---|
306 | def bsp_configure(self, conf, arch_bsp): |
---|
307 | if 'configure' in self.data: |
---|
308 | for cfg in self.data['configure']: |
---|
309 | for h in self.data['configure'][cfg]: |
---|
310 | conf.check(header_name = h, |
---|
311 | features = "c", |
---|
312 | includes = conf.env.IFLAGS, |
---|
313 | mandatory = False) |
---|
314 | |
---|
315 | def configure(self, conf): |
---|
316 | pass |
---|
317 | |
---|
318 | def build(self, bld): |
---|
319 | # |
---|
320 | # Localize the config. |
---|
321 | # |
---|
322 | config = self.getConfiguration() |
---|
323 | |
---|
324 | # |
---|
325 | # |
---|
326 | # C/C++ flags |
---|
327 | # |
---|
328 | common_flags = [] |
---|
329 | common_flags += ['-O%s' % (bld.env.OPTIMIZATION)] |
---|
330 | if 'common-flags' in config: |
---|
331 | common_flags += [f for f in config['common-flags']] |
---|
332 | if bld.env.WARNINGS and 'common-warnings' in config: |
---|
333 | common_flags += [f for f in config['common-warnings']] |
---|
334 | elif 'common-no-warnings' in config: |
---|
335 | common_flags += [f for f in config['common-no-warnings']] |
---|
336 | if 'cflags' in config: |
---|
337 | cflags = config['cflags'] + common_flags |
---|
338 | if 'cxxflags' in config: |
---|
339 | cxxflags = config['cxxflags'] + common_flags |
---|
340 | |
---|
341 | # |
---|
342 | # Defines |
---|
343 | # |
---|
344 | defines = [] |
---|
345 | if len(bld.env.FREEBSD_OPTIONS) > 0: |
---|
346 | for o in bld.env.FREEBSD_OPTIONS.split(','): |
---|
347 | defines += ['%s=1' % (o.strip().upper())] |
---|
348 | |
---|
349 | # |
---|
350 | # Include paths |
---|
351 | # |
---|
352 | includes = [] |
---|
353 | if 'cpu-include-paths' in config: |
---|
354 | cpu = bld.get_env()['RTEMS_ARCH'] |
---|
355 | if cpu == "i386": |
---|
356 | cpu = 'x86' |
---|
357 | for i in config['cpu-include-paths']: |
---|
358 | includes += [i.replace('@CPU@', cpu)] |
---|
359 | if 'include-paths' in config: |
---|
360 | includes += config['include-paths'] |
---|
361 | if 'build-include-path' in config: |
---|
362 | includes += config['build-include-path'] |
---|
363 | |
---|
364 | # |
---|
365 | # Collect the libbsd uses |
---|
366 | # |
---|
367 | libbsd_use = [] |
---|
368 | |
---|
369 | # |
---|
370 | # Network test configuration |
---|
371 | # |
---|
372 | if not os.path.exists(bld.env.NET_CONFIG): |
---|
373 | bld.fatal('network configuraiton \'%s\' not found' % (bld.env.NET_CONFIG)) |
---|
374 | tags = [ 'NET_CFG_SELF_IP', |
---|
375 | 'NET_CFG_NETMASK', |
---|
376 | 'NET_CFG_PEER_IP', |
---|
377 | 'NET_CFG_GATEWAY_IP' ] |
---|
378 | try: |
---|
379 | net_cfg_lines = open(bld.env.NET_CONFIG).readlines() |
---|
380 | except: |
---|
381 | bld.fatal('network configuraiton \'%s\' read failed' % (bld.env.NET_CONFIG)) |
---|
382 | lc = 0 |
---|
383 | for l in net_cfg_lines: |
---|
384 | lc += 1 |
---|
385 | if l.strip().startswith('NET_CFG_'): |
---|
386 | ls = l.split('=') |
---|
387 | if len(ls) != 2: |
---|
388 | bld.fatal('network configuraiton \'%s\' ' + \ |
---|
389 | 'parse error: %d: %s' % (bld.env.NET_CONFIG, lc, l)) |
---|
390 | lhs = ls[0].strip() |
---|
391 | rhs = ls[1].strip() |
---|
392 | sed = 'sed ' |
---|
393 | for t in tags: |
---|
394 | if lhs == t: |
---|
395 | sed += "-e 's/@%s@/%s/'" % (t, rhs) |
---|
396 | bld(target = "testsuite/include/rtems/bsd/test/network-config.h", |
---|
397 | source = "testsuite/include/rtems/bsd/test/network-config.h.in", |
---|
398 | rule = sed + " < ${SRC} > ${TGT}", |
---|
399 | update_outputs = True) |
---|
400 | |
---|
401 | # |
---|
402 | # Add a copy rule for all headers where the install path and the source |
---|
403 | # path are not the same. |
---|
404 | # |
---|
405 | if 'header-paths' in config: |
---|
406 | header_build_copy_paths = [ |
---|
407 | hp for hp in config['header-paths'] if hp[2] != '' and not hp[0].endswith(hp[2]) |
---|
408 | ] |
---|
409 | for headers in header_build_copy_paths: |
---|
410 | target = os.path.join("build-include", headers[2]) |
---|
411 | start_dir = bld.path.find_dir(headers[0]) |
---|
412 | for header in start_dir.ant_glob(headers[1]): |
---|
413 | relsourcepath = header.path_from(start_dir) |
---|
414 | targetheader = os.path.join(target, relsourcepath) |
---|
415 | bld(features = 'subst', |
---|
416 | target = targetheader, |
---|
417 | source = header, |
---|
418 | is_copy = True) |
---|
419 | |
---|
420 | # |
---|
421 | # Add the specific rule based builders |
---|
422 | # |
---|
423 | |
---|
424 | # |
---|
425 | # KVM Symbols |
---|
426 | # |
---|
427 | if 'KVMSymbols' in self.data: |
---|
428 | kvmsymbols = self.data['KVMSymbols'] |
---|
429 | if 'includes' in kvmsymbols['files']: |
---|
430 | kvmsymbols_includes = kvmsymbols['files']['includes'] |
---|
431 | else: |
---|
432 | kvmsymbols_includes = [] |
---|
433 | bld(target = kvmsymbols['files']['all']['default'][0], |
---|
434 | source = 'rtemsbsd/rtems/generate_kvm_symbols', |
---|
435 | rule = host_shell + './${SRC} > ${TGT}', |
---|
436 | update_outputs = True) |
---|
437 | bld.objects(target = 'kvmsymbols', |
---|
438 | features = 'c', |
---|
439 | cflags = cflags, |
---|
440 | includes = kvmsymbols_includes + includes, |
---|
441 | source = kvmsymbols['files']['all']['default'][0]) |
---|
442 | libbsd_use += ["kvmsymbols"] |
---|
443 | |
---|
444 | bld.add_group() |
---|
445 | |
---|
446 | # |
---|
447 | # RPC Generation |
---|
448 | # |
---|
449 | if 'RPCGen' in self.data: |
---|
450 | if bld.env.AUTO_REGEN: |
---|
451 | rpcgen = self.data['RPCGen'] |
---|
452 | rpcname = rpcgen['files']['all']['default'][0][:-2] |
---|
453 | bld(target = rpcname + '.h', |
---|
454 | source = y + '.x', |
---|
455 | rule = host_shell + '${RPCGEN} -h -o ${TGT} ${SRC}') |
---|
456 | |
---|
457 | # |
---|
458 | # Route keywords |
---|
459 | # |
---|
460 | if 'RouteKeywords' in self.data: |
---|
461 | if bld.env.AUTO_REGEN: |
---|
462 | routekw = self.data['RouteKeywords'] |
---|
463 | rkwname = routekw['files']['all']['default'][0] |
---|
464 | rkw_rule = host_shell + 'cat ${SRC} | ' + \ |
---|
465 | 'awk \'BEGIN { r = 0 } { if (NF == 1) ' + \ |
---|
466 | 'printf \\"#define\\\\tK_%%s\\\\t%%d\\\\n\\\\t{\\\\\\"%%s\\\\\\", K_%%s},\\\\n\\", ' + \ |
---|
467 | 'toupper($1), ++r, $1, toupper($1)}\' > ${TGT}' |
---|
468 | bld(target = rkwname + '.h', |
---|
469 | source = rkwname, |
---|
470 | rule = rkw_rule) |
---|
471 | |
---|
472 | # |
---|
473 | # Lex |
---|
474 | # |
---|
475 | if 'lex' in self.data: |
---|
476 | lexes = self.data['lex'] |
---|
477 | for l in sorted(lexes.keys()): |
---|
478 | lex = lexes[l]['all']['default'] |
---|
479 | if 'cflags' in lex: |
---|
480 | lexDefines = [d[2:] for d in lex['cflags']] |
---|
481 | else: |
---|
482 | lexDefines = [] |
---|
483 | if 'includes' in lex: |
---|
484 | lexIncludes = lex['includes'] |
---|
485 | else: |
---|
486 | lexIncludes = [] |
---|
487 | lex_rule = host_shell + '${LEX} -P ' + lex['sym'] + ' -t ${SRC} | ' + \ |
---|
488 | 'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' > ${TGT}")' |
---|
489 | if bld.env.AUTO_REGEN: |
---|
490 | bld(target = lex['file'][:-2]+ '.c', |
---|
491 | source = lex['file'], |
---|
492 | rule = lex_rule) |
---|
493 | bld.objects(target = 'lex_%s' % (lex['sym']), |
---|
494 | features = 'c', |
---|
495 | cflags = cflags, |
---|
496 | includes = lexIncludes + includes, |
---|
497 | defines = defines + lexDefines, |
---|
498 | source = lex['file'][:-2] + '.c') |
---|
499 | libbsd_use += ['lex_%s' % (lex['sym'])] |
---|
500 | |
---|
501 | # |
---|
502 | # Yacc |
---|
503 | # |
---|
504 | if 'yacc' in self.data: |
---|
505 | yaccs = self.data['yacc'] |
---|
506 | for y in sorted(yaccs.keys()): |
---|
507 | yacc = yaccs[y]['all']['default'] |
---|
508 | yaccFile = yacc['file'] |
---|
509 | if yacc['sym'] is not None: |
---|
510 | yaccSym = yacc['sym'] |
---|
511 | else: |
---|
512 | yaccSym = os.path.basename(yaccFile)[:-2] |
---|
513 | yaccHeader = '%s/%s' % (os.path.dirname(yaccFile), yacc['header']) |
---|
514 | if 'cflags' in yacc: |
---|
515 | yaccDefines = [d[2:] for d in yacc['cflags']] |
---|
516 | else: |
---|
517 | yaccDefines = [] |
---|
518 | if 'includes' in yacc: |
---|
519 | yaccIncludes = yacc['includes'] |
---|
520 | else: |
---|
521 | yaccIncludes = [] |
---|
522 | yacc_rule = host_shell + '${YACC} -b ' + yaccSym + \ |
---|
523 | ' -d -p ' + yaccSym + ' ${SRC} && ' + \ |
---|
524 | 'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' < ' + yaccSym + '.tab.c > ${TGT} && ' + \ |
---|
525 | 'rm -f ' + yaccSym + '.tab.c && mv ' + yaccSym + '.tab.h ' + yaccHeader |
---|
526 | if bld.env.AUTO_REGEN: |
---|
527 | bld(target = yaccFile[:-2] + '.c', |
---|
528 | source = yaccFile, |
---|
529 | rule = yacc_rule) |
---|
530 | bld.objects(target = 'yacc_%s' % (yaccSym), |
---|
531 | features = 'c', |
---|
532 | cflags = cflags, |
---|
533 | includes = yaccIncludes + includes, |
---|
534 | defines = defines + yaccDefines, |
---|
535 | source = yaccFile[:-2] + '.c') |
---|
536 | libbsd_use += ['yacc_%s' % (yaccSym)] |
---|
537 | |
---|
538 | # |
---|
539 | # We have 'm' different sets of flags and there can be 'n' cpus |
---|
540 | # specific files for those flags. |
---|
541 | # |
---|
542 | objs = 0 |
---|
543 | sources = sorted(self.data['sources']) |
---|
544 | if 'default' in sources: |
---|
545 | sources.remove('default') |
---|
546 | for flags in sources: |
---|
547 | objs += 1 |
---|
548 | build = self.data['sources'][flags] |
---|
549 | target = 'objs%02d' % (objs) |
---|
550 | bld_sources = Builder._sourceList(bld, build['all']) |
---|
551 | archs = sorted(build) |
---|
552 | for i in ['all', 'cflags', 'includes']: |
---|
553 | if i in archs: |
---|
554 | archs.remove(i) |
---|
555 | for arch in archs: |
---|
556 | if bld.get_env()['RTEMS_ARCH'] == arch: |
---|
557 | bld_sources += Builder._sourceList(bld, build[arch]) |
---|
558 | if 'cflags' in build: |
---|
559 | bld_defines = [d[2:] for d in build['cflags']] |
---|
560 | else: |
---|
561 | bld_defines = [] |
---|
562 | if 'includes' in build: |
---|
563 | bld_includes = build['includes'] |
---|
564 | else: |
---|
565 | bld_includes = [] |
---|
566 | bld.objects(target = target, |
---|
567 | features = 'c', |
---|
568 | cflags = cflags, |
---|
569 | includes = sorted(bld_includes) + includes, |
---|
570 | defines = defines + sorted(bld_defines), |
---|
571 | source = bld_sources) |
---|
572 | libbsd_use += [target] |
---|
573 | |
---|
574 | # |
---|
575 | # We hold the 'default' cflags set of files to the end to create the |
---|
576 | # static library with. |
---|
577 | # |
---|
578 | build = self.data['sources']['default'] |
---|
579 | bld_sources = Builder._sourceList(bld, build['all']) |
---|
580 | archs = sorted(build) |
---|
581 | archs.remove('all') |
---|
582 | for arch in archs: |
---|
583 | if bld.get_env()['RTEMS_ARCH'] == arch: |
---|
584 | bld_sources += Builder._sourceList(bld, build[arch]) |
---|
585 | bld.stlib(target = 'bsd', |
---|
586 | features = 'c cxx', |
---|
587 | cflags = cflags, |
---|
588 | cxxflags = cxxflags, |
---|
589 | includes = includes, |
---|
590 | defines = defines, |
---|
591 | source = bld_sources, |
---|
592 | use = libbsd_use) |
---|
593 | |
---|
594 | # |
---|
595 | # Installs. |
---|
596 | # |
---|
597 | # Header file collector. |
---|
598 | # |
---|
599 | arch_lib_path = rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, |
---|
600 | bld.env.RTEMS_ARCH_BSP) |
---|
601 | arch_inc_path = rtems.arch_bsp_include_path(bld.env.RTEMS_VERSION, |
---|
602 | bld.env.RTEMS_ARCH_BSP) |
---|
603 | |
---|
604 | bld.install_files("${PREFIX}/" + arch_lib_path, ["libbsd.a"]) |
---|
605 | |
---|
606 | if 'header-paths' in config: |
---|
607 | headerPaths = config['header-paths'] |
---|
608 | cpu = bld.get_env()['RTEMS_ARCH'] |
---|
609 | if cpu == "i386": |
---|
610 | cpu = 'x86' |
---|
611 | for headers in headerPaths: |
---|
612 | # Get the dest path |
---|
613 | ipath = os.path.join(arch_inc_path, headers[2]) |
---|
614 | start_dir = bld.path.find_dir(headers[0].replace('@CPU@', cpu)) |
---|
615 | if start_dir != None: |
---|
616 | bld.install_files("${PREFIX}/" + ipath, |
---|
617 | start_dir.ant_glob(headers[1]), |
---|
618 | cwd = start_dir, |
---|
619 | relative_trick = True) |
---|
620 | |
---|
621 | # |
---|
622 | # Tests |
---|
623 | # |
---|
624 | tests = self.data['tests'] |
---|
625 | for testName in sorted(tests): |
---|
626 | test = self.data['tests'][testName]['all'] |
---|
627 | test_source = [] |
---|
628 | for cfg in test: |
---|
629 | build_test = True |
---|
630 | if cfg != 'default': |
---|
631 | for c in cfg.split(' '): |
---|
632 | if not bld.env['HAVE_%s' % (c)]: |
---|
633 | build_test = False |
---|
634 | break |
---|
635 | if build_test: |
---|
636 | test_sources = ['testsuite/%s/%s.c' % (testName, f) \ |
---|
637 | for f in test[cfg]['files']] |
---|
638 | if build_test: |
---|
639 | bld.program(target = '%s.exe' % (testName), |
---|
640 | features = 'cprogram', |
---|
641 | cflags = cflags, |
---|
642 | includes = includes, |
---|
643 | source = test_sources, |
---|
644 | use = ['bsd'], |
---|
645 | lib = ['m', 'z'], |
---|
646 | install_path = None) |
---|