source: rtems-libbsd/waf_generator.py @ b15a719

55-freebsd-126-freebsd-12
Last change on this file since b15a719 was fb84af0, checked in by Sebastian Huber <sebastian.huber@…>, on 10/24/17 at 05:42:36

Fix install arch-specific header files

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