source: rtems-libbsd/waf_generator.py @ b988014

55-freebsd-126-freebsd-12
Last change on this file since b988014 was d18c643, checked in by Christian Mauderer <Christian.Mauderer@…>, on 10/02/17 at 07:57:04

Allow to set optimization level during configure.

This allows to set the optimization level for libbsd via a configure
switch. Useful for building with for example no optimization during
debug or with size optimization for space restricted targets.

  • Property mode set to 100755
File size: 29.5 KB
Line 
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
35from __future__ import print_function
36
37import os
38import sys
39import tempfile
40
41import builder
42
43#
44# Dump the data created from the fragments returned from the builder composers.
45#
46trace = False
47
48data = { }
49
50def _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
57def _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
71class 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
83class 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
102class 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
115class 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
135class KVMSymbolsFragmentComposer(builder.BuildSystemFragmentComposer):
136
137    def compose(self, path):
138        return ['KVMSymbols', 'files', ('default', None)], [path], self.includes
139
140class RPCGENFragmentComposer(builder.BuildSystemFragmentComposer):
141
142    def compose(self, path):
143        return ['RPCGen', 'files', ('default', None)], [path]
144
145class RouteKeywordsFragmentComposer(builder.BuildSystemFragmentComposer):
146
147    def compose(self, path):
148        return ['RouteKeywords', 'files', ('default', None)], [path]
149
150class 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
167class 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
185class 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        self.generator['from-FreeBSD-to-RTEMS-UserSpaceSourceConverter'] = builder.FromFreeBSDToRTEMSUserSpaceSourceConverter
202        self.generator['from-RTEMS-To-FreeBSD-SourceConverter'] = builder.FromRTEMSToFreeBSDSourceConverter
203        self.generator['buildSystemFragmentComposer'] = builder.BuildSystemFragmentComposer
204
205        self.generator['file'] = builder.File
206
207        self.generator['path'] = builder.PathComposer
208        self.generator['freebsd-path'] = builder.FreeBSDPathComposer
209        self.generator['rtems-path'] = builder.RTEMSPathComposer
210        self.generator['cpu-path'] = builder.CPUDependentPathComposer
211        self.generator['target-src-cpu--path'] = builder.TargetSourceCPUDependentPathComposer
212
213        self.generator['source'] = SourceFileFragmentComposer
214        self.generator['test'] = TestFragementComposer
215        self.generator['kvm-symbols'] = KVMSymbolsFragmentComposer
216        self.generator['rpc-gen'] = RPCGENFragmentComposer
217        self.generator['route-keywords'] = RouteKeywordsFragmentComposer
218        self.generator['lex'] = LexFragmentComposer
219        self.generator['yacc'] = YaccFragmentComposer
220
221        self.generator['source-if-header'] = SourceFileIfHeaderComposer
222        self.generator['test-if-header'] = TestIfHeaderComposer
223
224    def generate(self, rtems_version):
225
226        def _sourceListSources(lhs, sources, append = False, block = 0):
227            indent = block * 4
228            if append:
229                adder = '+'
230                adderSpace = ' '
231            else:
232                adder = ''
233                adderSpace = ''
234            ll = len(lhs)
235            if len(sources) == 1:
236                self.add('%s%s %s= [%r]' % (' ' * indent, lhs, adder, sources[0]))
237            elif len(sources) == 2:
238                self.add('%s%s %s= [%r,' % (' ' * indent, lhs, adder, sources[0]))
239                self.add('%s%s %s   %r]' % (' ' * indent, ' ' * ll, adderSpace, sources[-1]))
240            elif len(sources) > 0:
241                self.add('%s%s %s= [%r,' % (' ' * indent, lhs, adder, sources[0]))
242                for f in sources[1:-1]:
243                    self.add('%s%s %s   %r,' % (' ' * indent, ' ' * ll, adderSpace, f))
244                self.add('%s%s %s   %r]' % (' ' * indent, ' ' * ll, adderSpace, sources[-1]))
245
246        def _sourceList(lhs, files, append = False):
247            if type(files) is dict:
248                appending = False
249                for cfg in files:
250                    if cfg in ['cflags', 'includes']:
251                        continue
252                    if cfg != 'default':
253                        cs = ''
254                        ors = ''
255                        for c in cfg.split(' '):
256                            cs += '%s bld.env["HAVE_%s"]' % (ors, c)
257                            ors = ' and'
258                        self.add('    if%s:' % (cs))
259                        _sourceListSources(lhs, sorted(files[cfg]), append = appending, block = 1)
260                    else:
261                        _sourceListSources(lhs, sorted(files[cfg]), append)
262                    appending = True
263            else:
264                _sourceListSources(lhs, sorted(files), append)
265
266        def _dataInsert(data, cpu, frag):
267            #
268            # The default handler returns an empty string. Skip it.
269            #
270            if type(frag) is not str:
271                # Start at the top of the tree
272                d = data
273                path = frag[0]
274                if path[0] not in d:
275                    d[path[0]] = {}
276                # Select the sub-part of the tree as the compile options
277                # specialise how files are built.
278                d = d[path[0]]
279                if type(path[1]) is list:
280                    p = ' '.join(path[1])
281                else:
282                    p = path[1]
283                if p not in d:
284                    d[p] = {}
285                d = d[p]
286                if cpu not in d:
287                    d[cpu] = { }
288                config = frag[0][2][0]
289                if config != 'default':
290                    if 'configure' not in data:
291                        data['configure'] = { }
292                    data['configure'][config] = frag[0][2][1]
293                if type(frag[1]) is list:
294                    if config not in d[cpu]:
295                        d[cpu][config] = []
296                    d[cpu][config] += frag[1]
297                else:
298                    d[cpu][config] = frag[1]
299                #
300                # The CPU is for files and the flags and includes are common.
301                #
302                if len(frag) > 3:
303                    if 'cflags' not in d:
304                        d['cflags'] = []
305                    d['cflags'] += frag[2]
306                    d['cflags'] = list(set(d['cflags']))
307                if len(frag) >= 3 and None not in frag[-1]:
308                    if 'includes' not in d:
309                        d['includes'] = []
310                    d['includes'] += frag[-1]
311                    d['includes'] = list(set(d['includes']))
312
313        data = { }
314
315        for mn in self.getModules():
316            m = self[mn]
317            if m.conditionalOn == "none":
318                for f in m.files:
319                    _dataInsert(data, 'all', f.getFragment())
320            for cpu, files in sorted(m.cpuDependentSourceFiles.items()):
321                for f in files:
322                    _dataInsert(data, cpu, f.getFragment())
323
324        if trace:
325            import pprint
326            pprint.pprint(data)
327
328        self.restart()
329
330        self.add('#')
331        self.add('# RTEMS Project (https://www.rtems.org)')
332        self.add('#')
333        self.add('# Generated waf script. Do not edit, run ./freebsd-to-rtems.py -m')
334        self.add('#')
335        self.add('# To use see README.waf shipped with this file.')
336        self.add('#')
337        self.add('')
338        self.add('from __future__ import print_function')
339        self.add('')
340        self.add('import os')
341        self.add('import os.path')
342        # Import check done in the top level wscript file.
343        self.add('import rtems_waf.rtems as rtems')
344        self.add('')
345        self.add('windows = os.name == "nt"')
346        self.add('')
347        self.add('if windows:')
348        self.add('    host_shell = "sh -c "')
349        self.add('else:')
350        self.add('    host_shell = ""')
351        self.add('')
352        self.add('def init(ctx):')
353        self.add('    pass')
354        self.add('')
355        self.add('def options(opt):')
356        self.add('    pass')
357        self.add('')
358        self.add('def bsp_configure(conf, arch_bsp):')
359
360        if 'configure' in data:
361            for cfg in data['configure']:
362                for h in data['configure'][cfg]:
363                    self.add('    conf.check(header_name = "%s", features = "c", includes = conf.env.IFLAGS, mandatory = False)' % h)
364        else:
365            self.add('    pass')
366
367        self.add('')
368        self.add('def configure(conf):')
369        self.add('    rtems.configure(conf, bsp_configure)')
370        self.add('')
371        self.add('def build(bld):')
372        self.add('    # C/C++ flags')
373        self.add('    common_flags = []')
374        self.add('    common_flags += ["-O%s" % (bld.env.OPTIMIZATION)]')
375        for f in builder.commonFlags():
376            self.add('    common_flags += ["%s"]' % (f))
377        self.add('    if bld.env.WARNINGS:')
378        for f in builder.commonWarnings():
379            self.add('        common_flags += ["%s"]' % (f))
380        self.add('    else:')
381        for f in builder.commonNoWarnings():
382            self.add('        common_flags += ["%s"]' % (f))
383        self.add('    cflags = %r + common_flags' % (builder.cflags()))
384        self.add('    cxxflags = %r + common_flags' % (builder.cxxflags()))
385        self.add('')
386        self.add('    # Defines')
387        self.add('    defines = []')
388        self.add('    if len(bld.env.FREEBSD_OPTIONS) > 0:')
389        self.add('        for o in bld.env.FREEBSD_OPTIONS.split(","):')
390        self.add('            defines += ["%s=1" % (o.strip().upper())]')
391        self.add('')
392        self.add('    # Include paths')
393        self.add('    includes = []')
394        self.add('    for i in %r:' % (builder.cpuIncludes()))
395        self.add('        includes += ["%s" % (i[2:].replace("@CPU@", bld.get_env()["RTEMS_ARCH"]))]')
396        self.add('    if bld.get_env()["RTEMS_ARCH"] == "i386":')
397        self.add('        for i in %r:' % (builder.cpuIncludes()))
398        self.add('            includes += ["%s" % (i[2:].replace("@CPU@", "x86"))]')
399        for i in builder.includes() + ['-I' + builder.buildInclude()]:
400            self.add('    includes += ["%s"]' % (i[2:]))
401        self.add('')
402        self.add('    # Collect the libbsd uses')
403        self.add('    libbsd_use = []')
404        self.add('')
405
406        #
407        # Support the existing Makefile based network configuration file.
408        #
409        self.add('    # Network test configuration')
410        self.add('    if not os.path.exists(bld.env.NET_CONFIG):')
411        self.add('        bld.fatal("network configuraiton \'%s\' not found" % (bld.env.NET_CONFIG))')
412        self.add('    net_cfg_self_ip = None')
413        self.add('    net_cfg_netmask = None')
414        self.add('    net_cfg_peer_ip = None')
415        self.add('    net_cfg_gateway_ip = None')
416        self.add('    net_tap_interface = None')
417        self.add('    try:')
418        self.add('        net_cfg_lines = open(bld.env.NET_CONFIG).readlines()')
419        self.add('    except:')
420        self.add('        bld.fatal("network configuraiton \'%s\' read failed" % (bld.env.NET_CONFIG))')
421        self.add('    lc = 0')
422        self.add('    for l in net_cfg_lines:')
423        self.add('        lc += 1')
424        self.add('        if l.strip().startswith("NET_CFG_"):')
425        self.add('            ls = l.split("=")')
426        self.add('            if len(ls) != 2:')
427        self.add('                bld.fatal("network configuraiton \'%s\' parse error: %d: %s" % ' + \
428                 '(bld.env.NET_CONFIG, lc, l))')
429        self.add('            lhs = ls[0].strip()')
430        self.add('            rhs = ls[1].strip()')
431        self.add('            if lhs == "NET_CFG_SELF_IP":')
432        self.add('                net_cfg_self_ip = rhs')
433        self.add('            if lhs == "NET_CFG_NETMASK":')
434        self.add('                net_cfg_netmask = rhs')
435        self.add('            if lhs == "NET_CFG_PEER_IP":')
436        self.add('                net_cfg_peer_ip = rhs')
437        self.add('            if lhs == "NET_CFG_GATEWAY_IP":')
438        self.add('                net_cfg_gateway_ip = rhs')
439        self.add('            if lhs == "NET_TAP_INTERFACE":')
440        self.add('                net_tap_interface = rhs')
441        self.add('    bld(target = "testsuite/include/rtems/bsd/test/network-config.h",')
442        self.add('        source = "testsuite/include/rtems/bsd/test/network-config.h.in",')
443        self.add('        rule = "sed -e \'s/@NET_CFG_SELF_IP@/%s/\' ' + \
444                 '-e \'s/@NET_CFG_NETMASK@/%s/\' ' + \
445                 '-e \'s/@NET_CFG_PEER_IP@/%s/\' ' + \
446                 '-e \'s/@NET_CFG_GATEWAY_IP@/%s/\' < ${SRC} > ${TGT}" % ' + \
447                 '(net_cfg_self_ip, net_cfg_netmask, net_cfg_peer_ip, net_cfg_gateway_ip),')
448        self.add('        update_outputs = True)')
449        self.add('')
450
451        #
452        # Add a copy rule for all headers where the install path and the source
453        # path are not the same.
454        #
455        self.add('    # copy headers if necessary')
456        self.add('    header_build_copy_paths = [')
457        for hp in builder.headerPaths():
458            if hp[2] != '' and not hp[0].endswith(hp[2]):
459                self.add('                               %s,' % (str(hp)))
460        self.add('                              ]')
461        self.add('    for headers in header_build_copy_paths:')
462        self.add('        target = os.path.join("%s", headers[2])' % (builder.buildInclude()))
463        self.add('        start_dir = bld.path.find_dir(headers[0])')
464        self.add('        for header in start_dir.ant_glob(headers[1]):')
465        self.add('            relsourcepath = header.path_from(start_dir)')
466        self.add('            targetheader = os.path.join(target, relsourcepath)')
467        self.add('            bld(features = \'subst\',')
468        self.add('                target = targetheader,')
469        self.add('                source = header,')
470        self.add('                is_copy = True)')
471        self.add('')
472
473        #
474        # Add the specific rule based builders for generating files.
475        #
476        if 'KVMSymbols' in data:
477            kvmsymbols = data['KVMSymbols']
478            if 'includes' in kvmsymbols['files']:
479                includes = kvmsymbols['files']['includes']
480            else:
481                includes = []
482            self.add('    # KVM Symbols')
483            self.add('    bld(target = "%s",' % (kvmsymbols['files']['all']['default'][0]))
484            self.add('        source = "rtemsbsd/rtems/generate_kvm_symbols",')
485            self.add('        rule = host_shell + "./${SRC} > ${TGT}",')
486            self.add('        update_outputs = True)')
487            self.add('    bld.objects(target = "kvmsymbols",')
488            self.add('                features = "c",')
489            self.add('                cflags = cflags,')
490            self.add('                includes = %r + includes,' % (includes))
491            self.add('                source = "%s")' % (kvmsymbols['files']['all']['default'][0]))
492            self.add('    libbsd_use += ["kvmsymbols"]')
493            self.add('')
494
495        self.add('    bld.add_group()')
496
497        if 'RPCGen' in data:
498            rpcgen = data['RPCGen']
499            rpcname = rpcgen['files']['all']['default'][0][:-2]
500            self.add('    # RPC Generation')
501            self.add('    if bld.env.AUTO_REGEN:')
502            self.add('        bld(target = "%s.h",' % (rpcname))
503            self.add('            source = "%s.x",' % (rpcname))
504            self.add('            rule = host_shell + "${RPCGEN} -h -o ${TGT} ${SRC}")')
505            self.add('')
506
507        if 'RouteKeywords' in data:
508            routekw = data['RouteKeywords']
509            rkwname = routekw['files']['all']['default'][0]
510            self.add('    # Route keywords')
511            self.add('    if bld.env.AUTO_REGEN:')
512            self.add('        rkw_rule = host_shell + "cat ${SRC} | ' + \
513                     'awk \'BEGIN { r = 0 } { if (NF == 1) ' + \
514                     'printf \\"#define\\\\tK_%%s\\\\t%%d\\\\n\\\\t{\\\\\\"%%s\\\\\\", K_%%s},\\\\n\\", ' + \
515                     'toupper($1), ++r, $1, toupper($1)}\' > ${TGT}"')
516            self.add('        bld(target = "%s.h",' % (rkwname))
517            self.add('            source = "%s",' % (rkwname))
518            self.add('            rule = rkw_rule)')
519            self.add('')
520
521        if 'lex' in data:
522            lexes = data['lex']
523            self.add('    # Lex')
524            for l in sorted(lexes.keys()):
525                lex = lexes[l]['all']['default']
526                if 'cflags' in lex:
527                    lexDefines = [d[2:] for d in lex['cflags']]
528                else:
529                    lexDefines = []
530                if 'includes' in lex:
531                    lexIncludes = lex['includes']
532                else:
533                    lexIncludes = []
534                self.add('    if bld.env.AUTO_REGEN:')
535                self.add('        bld(target = "%s.c",' % (lex['file'][:-2]))
536                self.add('            source = "%s",' % (lex['file']))
537                self.add('            rule = host_shell + "${LEX} -P %s -t ${SRC} | ' % (lex['sym']) + \
538                         'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' > ${TGT}")')
539                self.add('    bld.objects(target = "lex_%s",' % (lex['sym']))
540                self.add('                features = "c",')
541                self.add('                cflags = cflags,')
542                self.add('                includes = %r + includes,' % (lexIncludes))
543                self.add('                defines = defines + %r,' % (lexDefines))
544                self.add('                source = "%s.c")' % (lex['file'][:-2]))
545                self.add('    libbsd_use += ["lex_%s"]' % (lex['sym']))
546                self.add('')
547
548        if 'yacc' in data:
549            yaccs = data['yacc']
550            self.add('    # Yacc')
551            for y in sorted(yaccs.keys()):
552                yacc = yaccs[y]['all']['default']
553                yaccFile = yacc['file']
554                if yacc['sym'] is not None:
555                    yaccSym = yacc['sym']
556                else:
557                    yaccSym = os.path.basename(yaccFile)[:-2]
558                yaccHeader = '%s/%s' % (os.path.dirname(yaccFile), yacc['header'])
559                if 'cflags' in yacc:
560                    yaccDefines = [d[2:] for d in yacc['cflags']]
561                else:
562                    yaccDefines = []
563                if 'includes' in yacc:
564                    yaccIncludes = yacc['includes']
565                else:
566                    yaccIncludes = []
567                self.add('    if bld.env.AUTO_REGEN:')
568                self.add('        bld(target = "%s.c",' % (yaccFile[:-2]))
569                self.add('            source = "%s",' % (yaccFile))
570                self.add('            rule = host_shell + "${YACC} -b %s -d -p %s ${SRC} && ' % \
571                         (yaccSym, yaccSym) + \
572                         'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' < %s.tab.c > ${TGT} && ' % (yaccSym) + \
573                         'rm -f %s.tab.c && mv %s.tab.h %s")' % (yaccSym, yaccSym, yaccHeader))
574                self.add('    bld.objects(target = "yacc_%s",' % (yaccSym))
575                self.add('                features = "c",')
576                self.add('                cflags = cflags,')
577                self.add('                includes = %r + includes,' % (yaccIncludes))
578                self.add('                defines = defines + %r,' % (yaccDefines))
579                self.add('                source = "%s.c")' % (yaccFile[:-2]))
580                self.add('    libbsd_use += ["yacc_%s"]' % (yaccSym))
581            self.add('')
582
583        #
584        # We have 'm' different sets of flags and there can be 'n' cpus
585        # specific files for those flags.
586        #
587        objs = 0
588        self.add('    # Objects built with different CFLAGS')
589        sources = sorted(data['sources'])
590        if 'default' in sources:
591            sources.remove('default')
592        for flags in sources:
593            objs += 1
594            build = data['sources'][flags]
595            _sourceList('    objs%02d_source' % objs, build['all'])
596            archs = sorted(build)
597            for i in ['all', 'cflags', 'includes']:
598                if i in archs:
599                    archs.remove(i)
600            for arch in archs:
601                self.add('    if bld.get_env()["RTEMS_ARCH"] == "%s":' % arch)
602                _sourceList('        objs%02d_source' % objs, build[arch], append = True)
603            if 'cflags' in build:
604                defines = [d[2:] for d in build['cflags']]
605            else:
606                defines = []
607            if 'includes' in build:
608                includes = build['includes']
609            else:
610                includes = []
611            self.add('    bld.objects(target = "objs%02d",' % (objs))
612            self.add('                features = "c",')
613            self.add('                cflags = cflags,')
614            self.add('                includes = %r + includes,' % (sorted(includes)))
615            self.add('                defines = defines + %r,' % (sorted(defines)))
616            self.add('                source = objs%02d_source)' % objs)
617            self.add('    libbsd_use += ["objs%02d"]' % (objs))
618            self.add('')
619
620        #
621        # We hold the 'default' cflags set of files to the end to create the
622        # static library with.
623        #
624        build = data['sources']['default']
625        _sourceList('    source', build['all'])
626        archs = sorted(build)
627        archs.remove('all')
628        for arch in archs:
629            self.add('    if bld.get_env()["RTEMS_ARCH"] == "%s":' % arch)
630            _sourceList('        source', build[arch], append = True)
631        self.add('    bld.stlib(target = "bsd",')
632        self.add('              features = "c cxx",')
633        self.add('              cflags = cflags,')
634        self.add('              cxxflags = cxxflags,')
635        self.add('              includes = includes,')
636        self.add('              defines = defines,')
637        self.add('              source = source,')
638        self.add('              use = libbsd_use)')
639        self.add('')
640
641        #
642        # Header file collector.
643        #
644        self.add('    # Installs.    ')
645        self.add('    bld.install_files("${PREFIX}/" + rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), ["libbsd.a"])')
646        headerPaths = builder.headerPaths()
647        self.add('    header_paths = [%s,' % (str(headerPaths[0])))
648        for hp in headerPaths[1:-1]:
649            self.add('                     %s,' % (str(hp)))
650        self.add('                     %s]' % (str(headerPaths[-1])))
651        self.add('    for headers in header_paths:')
652        self.add('        ipath = os.path.join(rtems.arch_bsp_include_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), headers[2])')
653        self.add('        start_dir = bld.path.find_dir(headers[0])')
654        self.add('        bld.install_files("${PREFIX}/" + ipath,')
655        self.add('                          start_dir.ant_glob(headers[1]),')
656        self.add('                          cwd = start_dir,')
657        self.add('                          relative_trick = True)')
658        self.add('')
659
660        self.add('    # Tests')
661        tests = data['tests']
662        for testName in sorted(tests):
663            test = data['tests'][testName]['all']
664            block = 0
665            files = []
666            for cfg in test:
667                if cfg != 'default':
668                    cs = ''
669                    ors = ''
670                    for c in cfg.split(' '):
671                        cs += '%s bld.env["HAVE_%s"]' % (ors, c)
672                        ors = ' and'
673                    self.add('    if%s:' % (cs))
674                    block = 1
675                files = ['testsuite/%s/%s.c' % (testName, f) \
676                         for f in test[cfg]['files']]
677            indent = ' ' * block * 4
678            _sourceList('%s    test_%s' % (indent, testName), files)
679            self.add('%s    bld.program(target = "%s.exe",' % (indent, testName))
680            self.add('%s                features = "cprogram",' % (indent))
681            self.add('%s                cflags = cflags,' % (indent))
682            self.add('%s                includes = includes,' % (indent))
683            self.add('%s                source = test_%s,' % (indent, testName))
684            self.add('%s                use = ["bsd"],' % (indent))
685            self.add('%s                lib = ["m", "z"],' % (indent))
686            self.add('%s                install_path = None)' % (indent))
687            self.add('')
688
689        self.write()
Note: See TracBrowser for help on using the repository browser.