source: rtems-libbsd/waf_generator.py @ 301ee6e

55-freebsd-126-freebsd-12
Last change on this file since 301ee6e was 1f7037d, checked in by Sichen Zhao <1473996754@…>, on 08/01/17 at 12:32:08

Port openssl to RTEMS.

  • Property mode set to 100755
File size: 29.4 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        for f in builder.commonFlags():
375            self.add('    common_flags += ["%s"]' % (f))
376        self.add('    if bld.env.WARNINGS:')
377        for f in builder.commonWarnings():
378            self.add('        common_flags += ["%s"]' % (f))
379        self.add('    else:')
380        for f in builder.commonNoWarnings():
381            self.add('        common_flags += ["%s"]' % (f))
382        self.add('    cflags = %r + common_flags' % (builder.cflags()))
383        self.add('    cxxflags = %r + common_flags' % (builder.cxxflags()))
384        self.add('')
385        self.add('    # Defines')
386        self.add('    defines = []')
387        self.add('    if len(bld.env.FREEBSD_OPTIONS) > 0:')
388        self.add('        for o in bld.env.FREEBSD_OPTIONS.split(","):')
389        self.add('            defines += ["%s=1" % (o.strip().upper())]')
390        self.add('')
391        self.add('    # Include paths')
392        self.add('    includes = []')
393        self.add('    for i in %r:' % (builder.cpuIncludes()))
394        self.add('        includes += ["%s" % (i[2:].replace("@CPU@", bld.get_env()["RTEMS_ARCH"]))]')
395        self.add('    if bld.get_env()["RTEMS_ARCH"] == "i386":')
396        self.add('        for i in %r:' % (builder.cpuIncludes()))
397        self.add('            includes += ["%s" % (i[2:].replace("@CPU@", "x86"))]')
398        for i in builder.includes() + ['-I' + builder.buildInclude()]:
399            self.add('    includes += ["%s"]' % (i[2:]))
400        self.add('')
401        self.add('    # Collect the libbsd uses')
402        self.add('    libbsd_use = []')
403        self.add('')
404
405        #
406        # Support the existing Makefile based network configuration file.
407        #
408        self.add('    # Network test configuration')
409        self.add('    if not os.path.exists(bld.env.NET_CONFIG):')
410        self.add('        bld.fatal("network configuraiton \'%s\' not found" % (bld.env.NET_CONFIG))')
411        self.add('    net_cfg_self_ip = None')
412        self.add('    net_cfg_netmask = None')
413        self.add('    net_cfg_peer_ip = None')
414        self.add('    net_cfg_gateway_ip = None')
415        self.add('    net_tap_interface = None')
416        self.add('    try:')
417        self.add('        net_cfg_lines = open(bld.env.NET_CONFIG).readlines()')
418        self.add('    except:')
419        self.add('        bld.fatal("network configuraiton \'%s\' read failed" % (bld.env.NET_CONFIG))')
420        self.add('    lc = 0')
421        self.add('    for l in net_cfg_lines:')
422        self.add('        lc += 1')
423        self.add('        if l.strip().startswith("NET_CFG_"):')
424        self.add('            ls = l.split("=")')
425        self.add('            if len(ls) != 2:')
426        self.add('                bld.fatal("network configuraiton \'%s\' parse error: %d: %s" % ' + \
427                 '(bld.env.NET_CONFIG, lc, l))')
428        self.add('            lhs = ls[0].strip()')
429        self.add('            rhs = ls[1].strip()')
430        self.add('            if lhs == "NET_CFG_SELF_IP":')
431        self.add('                net_cfg_self_ip = rhs')
432        self.add('            if lhs == "NET_CFG_NETMASK":')
433        self.add('                net_cfg_netmask = rhs')
434        self.add('            if lhs == "NET_CFG_PEER_IP":')
435        self.add('                net_cfg_peer_ip = rhs')
436        self.add('            if lhs == "NET_CFG_GATEWAY_IP":')
437        self.add('                net_cfg_gateway_ip = rhs')
438        self.add('            if lhs == "NET_TAP_INTERFACE":')
439        self.add('                net_tap_interface = rhs')
440        self.add('    bld(target = "testsuite/include/rtems/bsd/test/network-config.h",')
441        self.add('        source = "testsuite/include/rtems/bsd/test/network-config.h.in",')
442        self.add('        rule = "sed -e \'s/@NET_CFG_SELF_IP@/%s/\' ' + \
443                 '-e \'s/@NET_CFG_NETMASK@/%s/\' ' + \
444                 '-e \'s/@NET_CFG_PEER_IP@/%s/\' ' + \
445                 '-e \'s/@NET_CFG_GATEWAY_IP@/%s/\' < ${SRC} > ${TGT}" % ' + \
446                 '(net_cfg_self_ip, net_cfg_netmask, net_cfg_peer_ip, net_cfg_gateway_ip),')
447        self.add('        update_outputs = True)')
448        self.add('')
449
450        #
451        # Add a copy rule for all headers where the install path and the source
452        # path are not the same.
453        #
454        self.add('    # copy headers if necessary')
455        self.add('    header_build_copy_paths = [')
456        for hp in builder.headerPaths():
457            if hp[2] != '' and not hp[0].endswith(hp[2]):
458                self.add('                               %s,' % (str(hp)))
459        self.add('                              ]')
460        self.add('    for headers in header_build_copy_paths:')
461        self.add('        target = os.path.join("%s", headers[2])' % (builder.buildInclude()))
462        self.add('        start_dir = bld.path.find_dir(headers[0])')
463        self.add('        for header in start_dir.ant_glob(headers[1]):')
464        self.add('            relsourcepath = header.path_from(start_dir)')
465        self.add('            targetheader = os.path.join(target, relsourcepath)')
466        self.add('            bld(features = \'subst\',')
467        self.add('                target = targetheader,')
468        self.add('                source = header,')
469        self.add('                is_copy = True)')
470        self.add('')
471
472        #
473        # Add the specific rule based builders for generating files.
474        #
475        if 'KVMSymbols' in data:
476            kvmsymbols = data['KVMSymbols']
477            if 'includes' in kvmsymbols['files']:
478                includes = kvmsymbols['files']['includes']
479            else:
480                includes = []
481            self.add('    # KVM Symbols')
482            self.add('    bld(target = "%s",' % (kvmsymbols['files']['all']['default'][0]))
483            self.add('        source = "rtemsbsd/rtems/generate_kvm_symbols",')
484            self.add('        rule = host_shell + "./${SRC} > ${TGT}",')
485            self.add('        update_outputs = True)')
486            self.add('    bld.objects(target = "kvmsymbols",')
487            self.add('                features = "c",')
488            self.add('                cflags = cflags,')
489            self.add('                includes = %r + includes,' % (includes))
490            self.add('                source = "%s")' % (kvmsymbols['files']['all']['default'][0]))
491            self.add('    libbsd_use += ["kvmsymbols"]')
492            self.add('')
493
494        self.add('    bld.add_group()')
495
496        if 'RPCGen' in data:
497            rpcgen = data['RPCGen']
498            rpcname = rpcgen['files']['all']['default'][0][:-2]
499            self.add('    # RPC Generation')
500            self.add('    if bld.env.AUTO_REGEN:')
501            self.add('        bld(target = "%s.h",' % (rpcname))
502            self.add('            source = "%s.x",' % (rpcname))
503            self.add('            rule = host_shell + "${RPCGEN} -h -o ${TGT} ${SRC}")')
504            self.add('')
505
506        if 'RouteKeywords' in data:
507            routekw = data['RouteKeywords']
508            rkwname = routekw['files']['all']['default'][0]
509            self.add('    # Route keywords')
510            self.add('    if bld.env.AUTO_REGEN:')
511            self.add('        rkw_rule = host_shell + "cat ${SRC} | ' + \
512                     'awk \'BEGIN { r = 0 } { if (NF == 1) ' + \
513                     'printf \\"#define\\\\tK_%%s\\\\t%%d\\\\n\\\\t{\\\\\\"%%s\\\\\\", K_%%s},\\\\n\\", ' + \
514                     'toupper($1), ++r, $1, toupper($1)}\' > ${TGT}"')
515            self.add('        bld(target = "%s.h",' % (rkwname))
516            self.add('            source = "%s",' % (rkwname))
517            self.add('            rule = rkw_rule)')
518            self.add('')
519
520        if 'lex' in data:
521            lexes = data['lex']
522            self.add('    # Lex')
523            for l in sorted(lexes.keys()):
524                lex = lexes[l]['all']['default']
525                if 'cflags' in lex:
526                    lexDefines = [d[2:] for d in lex['cflags']]
527                else:
528                    lexDefines = []
529                if 'includes' in lex:
530                    lexIncludes = lex['includes']
531                else:
532                    lexIncludes = []
533                self.add('    if bld.env.AUTO_REGEN:')
534                self.add('        bld(target = "%s.c",' % (lex['file'][:-2]))
535                self.add('            source = "%s",' % (lex['file']))
536                self.add('            rule = host_shell + "${LEX} -P %s -t ${SRC} | ' % (lex['sym']) + \
537                         'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' > ${TGT}")')
538                self.add('    bld.objects(target = "lex_%s",' % (lex['sym']))
539                self.add('                features = "c",')
540                self.add('                cflags = cflags,')
541                self.add('                includes = %r + includes,' % (lexIncludes))
542                self.add('                defines = defines + %r,' % (lexDefines))
543                self.add('                source = "%s.c")' % (lex['file'][:-2]))
544                self.add('    libbsd_use += ["lex_%s"]' % (lex['sym']))
545                self.add('')
546
547        if 'yacc' in data:
548            yaccs = data['yacc']
549            self.add('    # Yacc')
550            for y in sorted(yaccs.keys()):
551                yacc = yaccs[y]['all']['default']
552                yaccFile = yacc['file']
553                if yacc['sym'] is not None:
554                    yaccSym = yacc['sym']
555                else:
556                    yaccSym = os.path.basename(yaccFile)[:-2]
557                yaccHeader = '%s/%s' % (os.path.dirname(yaccFile), yacc['header'])
558                if 'cflags' in yacc:
559                    yaccDefines = [d[2:] for d in yacc['cflags']]
560                else:
561                    yaccDefines = []
562                if 'includes' in yacc:
563                    yaccIncludes = yacc['includes']
564                else:
565                    yaccIncludes = []
566                self.add('    if bld.env.AUTO_REGEN:')
567                self.add('        bld(target = "%s.c",' % (yaccFile[:-2]))
568                self.add('            source = "%s",' % (yaccFile))
569                self.add('            rule = host_shell + "${YACC} -b %s -d -p %s ${SRC} && ' % \
570                         (yaccSym, yaccSym) + \
571                         'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' < %s.tab.c > ${TGT} && ' % (yaccSym) + \
572                         'rm -f %s.tab.c && mv %s.tab.h %s")' % (yaccSym, yaccSym, yaccHeader))
573                self.add('    bld.objects(target = "yacc_%s",' % (yaccSym))
574                self.add('                features = "c",')
575                self.add('                cflags = cflags,')
576                self.add('                includes = %r + includes,' % (yaccIncludes))
577                self.add('                defines = defines + %r,' % (yaccDefines))
578                self.add('                source = "%s.c")' % (yaccFile[:-2]))
579                self.add('    libbsd_use += ["yacc_%s"]' % (yaccSym))
580            self.add('')
581
582        #
583        # We have 'm' different sets of flags and there can be 'n' cpus
584        # specific files for those flags.
585        #
586        objs = 0
587        self.add('    # Objects built with different CFLAGS')
588        sources = sorted(data['sources'])
589        if 'default' in sources:
590            sources.remove('default')
591        for flags in sources:
592            objs += 1
593            build = data['sources'][flags]
594            _sourceList('    objs%02d_source' % objs, build['all'])
595            archs = sorted(build)
596            for i in ['all', 'cflags', 'includes']:
597                if i in archs:
598                    archs.remove(i)
599            for arch in archs:
600                self.add('    if bld.get_env()["RTEMS_ARCH"] == "%s":' % arch)
601                _sourceList('        objs%02d_source' % objs, build[arch], append = True)
602            if 'cflags' in build:
603                defines = [d[2:] for d in build['cflags']]
604            else:
605                defines = []
606            if 'includes' in build:
607                includes = build['includes']
608            else:
609                includes = []
610            self.add('    bld.objects(target = "objs%02d",' % (objs))
611            self.add('                features = "c",')
612            self.add('                cflags = cflags,')
613            self.add('                includes = %r + includes,' % (sorted(includes)))
614            self.add('                defines = defines + %r,' % (sorted(defines)))
615            self.add('                source = objs%02d_source)' % objs)
616            self.add('    libbsd_use += ["objs%02d"]' % (objs))
617            self.add('')
618
619        #
620        # We hold the 'default' cflags set of files to the end to create the
621        # static library with.
622        #
623        build = data['sources']['default']
624        _sourceList('    source', build['all'])
625        archs = sorted(build)
626        archs.remove('all')
627        for arch in archs:
628            self.add('    if bld.get_env()["RTEMS_ARCH"] == "%s":' % arch)
629            _sourceList('        source', build[arch], append = True)
630        self.add('    bld.stlib(target = "bsd",')
631        self.add('              features = "c cxx",')
632        self.add('              cflags = cflags,')
633        self.add('              cxxflags = cxxflags,')
634        self.add('              includes = includes,')
635        self.add('              defines = defines,')
636        self.add('              source = source,')
637        self.add('              use = libbsd_use)')
638        self.add('')
639
640        #
641        # Header file collector.
642        #
643        self.add('    # Installs.    ')
644        self.add('    bld.install_files("${PREFIX}/" + rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), ["libbsd.a"])')
645        headerPaths = builder.headerPaths()
646        self.add('    header_paths = [%s,' % (str(headerPaths[0])))
647        for hp in headerPaths[1:-1]:
648            self.add('                     %s,' % (str(hp)))
649        self.add('                     %s]' % (str(headerPaths[-1])))
650        self.add('    for headers in header_paths:')
651        self.add('        ipath = os.path.join(rtems.arch_bsp_include_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), headers[2])')
652        self.add('        start_dir = bld.path.find_dir(headers[0])')
653        self.add('        bld.install_files("${PREFIX}/" + ipath,')
654        self.add('                          start_dir.ant_glob(headers[1]),')
655        self.add('                          cwd = start_dir,')
656        self.add('                          relative_trick = True)')
657        self.add('')
658
659        self.add('    # Tests')
660        tests = data['tests']
661        for testName in sorted(tests):
662            test = data['tests'][testName]['all']
663            block = 0
664            files = []
665            for cfg in test:
666                if cfg != 'default':
667                    cs = ''
668                    ors = ''
669                    for c in cfg.split(' '):
670                        cs += '%s bld.env["HAVE_%s"]' % (ors, c)
671                        ors = ' and'
672                    self.add('    if%s:' % (cs))
673                    block = 1
674                files = ['testsuite/%s/%s.c' % (testName, f) \
675                         for f in test[cfg]['files']]
676            indent = ' ' * block * 4
677            _sourceList('%s    test_%s' % (indent, testName), files)
678            self.add('%s    bld.program(target = "%s.exe",' % (indent, testName))
679            self.add('%s                features = "cprogram",' % (indent))
680            self.add('%s                cflags = cflags,' % (indent))
681            self.add('%s                includes = includes,' % (indent))
682            self.add('%s                source = test_%s,' % (indent, testName))
683            self.add('%s                use = ["bsd"],' % (indent))
684            self.add('%s                lib = ["m", "z"],' % (indent))
685            self.add('%s                install_path = None)' % (indent))
686            self.add('')
687
688        self.write()
Note: See TracBrowser for help on using the repository browser.