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