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