[5ba6949] | 1 | # |
---|
| 2 | # Copyright (c) 2015 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 | |
---|
| 35 | import os |
---|
| 36 | import tempfile |
---|
| 37 | |
---|
| 38 | import builder |
---|
| 39 | |
---|
| 40 | trace = False |
---|
| 41 | |
---|
| 42 | data = { } |
---|
| 43 | |
---|
| 44 | def _add_files(name, files): |
---|
| 45 | if type(files) is not list: |
---|
| 46 | files = [files] |
---|
| 47 | if name not in data: |
---|
| 48 | data[name] = [] |
---|
| 49 | data[name] += files |
---|
| 50 | |
---|
[8440506] | 51 | def _clfags_includes(cflags, includes): |
---|
| 52 | if type(cflags) is not list: |
---|
| 53 | if cflags is not None: |
---|
| 54 | _cflags = cflags.split(' ') |
---|
| 55 | else: |
---|
| 56 | _cflags = [None] |
---|
| 57 | else: |
---|
| 58 | _cflags = cflags |
---|
| 59 | if type(includes) is not list: |
---|
| 60 | _includes = [includes] |
---|
| 61 | else: |
---|
| 62 | _includes = includes |
---|
| 63 | return _cflags, _includes |
---|
| 64 | |
---|
[5ba6949] | 65 | class SourceFileFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
| 66 | |
---|
[8440506] | 67 | def __init__(self, cflags = "default", includes = None): |
---|
| 68 | self.cflags, self.includes = _clfags_includes(cflags, includes) |
---|
[5ba6949] | 69 | |
---|
| 70 | def compose(self, path): |
---|
[8440506] | 71 | if None in self.includes: |
---|
| 72 | return ['sources', self.cflags], [path], self.cflags, self.includes |
---|
| 73 | return ['sources', self.cflags + self.includes], [path], self.cflags, self.includes |
---|
[5ba6949] | 74 | |
---|
| 75 | class TestFragementComposer(builder.BuildSystemFragmentComposer): |
---|
| 76 | |
---|
| 77 | def __init__(self, testName, fileFragments, runTest = True, netTest = False): |
---|
| 78 | self.testName = testName |
---|
| 79 | self.fileFragments = fileFragments |
---|
| 80 | self.runTest = runTest |
---|
| 81 | self.netTest = netTest |
---|
| 82 | |
---|
| 83 | def compose(self, path): |
---|
| 84 | return ['tests', self.testName], { 'files': self.fileFragments, |
---|
| 85 | 'run': self.runTest, |
---|
| 86 | 'net': self.netTest } |
---|
| 87 | |
---|
| 88 | class KVMSymbolsFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
| 89 | |
---|
| 90 | def compose(self, path): |
---|
[8440506] | 91 | return ['KVMSymbols', 'files'], [path], self.includes |
---|
[5ba6949] | 92 | |
---|
| 93 | class RPCGENFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
| 94 | |
---|
| 95 | def compose(self, path): |
---|
| 96 | return ['RPCGen', 'files'], [path] |
---|
| 97 | |
---|
| 98 | class RouteKeywordsFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
| 99 | |
---|
| 100 | def compose(self, path): |
---|
| 101 | return ['RouteKeywords', 'files'], [path] |
---|
| 102 | |
---|
| 103 | class LexFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
| 104 | |
---|
[8440506] | 105 | def __init__(self, sym, dep, cflags = None, includes = None): |
---|
[5ba6949] | 106 | self.sym = sym |
---|
| 107 | self.dep = dep |
---|
[8440506] | 108 | self.cflags, self.includes = _clfags_includes(cflags, includes) |
---|
[5ba6949] | 109 | |
---|
| 110 | def compose(self, path): |
---|
[8440506] | 111 | d = { 'file': path, |
---|
| 112 | 'sym': self.sym, |
---|
| 113 | 'dep': self.dep } |
---|
| 114 | if None not in self.cflags: |
---|
| 115 | d['cflags'] = self.cflags |
---|
| 116 | if None not in self.includes: |
---|
| 117 | d['includes'] = self.includes |
---|
| 118 | return ['lex', path], d |
---|
[5ba6949] | 119 | |
---|
| 120 | class YaccFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
| 121 | |
---|
[8440506] | 122 | def __init__(self, sym, header, cflags = None, includes = None): |
---|
[5ba6949] | 123 | self.sym = sym |
---|
| 124 | self.header = header |
---|
[8440506] | 125 | self.cflags, self.includes = _clfags_includes(cflags, includes) |
---|
[5ba6949] | 126 | |
---|
| 127 | def compose(self, path): |
---|
[8440506] | 128 | d = { 'file': path, |
---|
| 129 | 'sym': self.sym, |
---|
| 130 | 'header': self.header } |
---|
| 131 | if None not in self.cflags: |
---|
| 132 | d['cflags'] = self.cflags |
---|
| 133 | if None not in self.includes: |
---|
| 134 | d['includes'] = self.includes |
---|
| 135 | return ['yacc', path], d |
---|
[5ba6949] | 136 | |
---|
| 137 | # Module Manager - Collection of Modules |
---|
| 138 | class ModuleManager(builder.ModuleManager): |
---|
| 139 | |
---|
| 140 | def restart(self): |
---|
| 141 | self.script = '' |
---|
| 142 | |
---|
| 143 | def add(self, line = ''): |
---|
| 144 | self.script += line + os.linesep |
---|
| 145 | |
---|
| 146 | def write(self): |
---|
| 147 | try: |
---|
| 148 | out = tempfile.NamedTemporaryFile(delete = False) |
---|
| 149 | out.write(self.script) |
---|
| 150 | out.close() |
---|
| 151 | wscript = builder.RTEMS_DIR + '/wscript' |
---|
| 152 | builder.processIfDifferent(out.name, wscript, "wscript") |
---|
| 153 | finally: |
---|
| 154 | try: |
---|
| 155 | os.remove(out.name) |
---|
| 156 | except: |
---|
| 157 | pass |
---|
| 158 | |
---|
| 159 | def setGenerators(self): |
---|
| 160 | self.generator['convert'] = builder.Converter |
---|
| 161 | self.generator['no-convert'] = builder.NoConverter |
---|
| 162 | |
---|
| 163 | self.generator['file'] = builder.File |
---|
| 164 | |
---|
| 165 | self.generator['path'] = builder.PathComposer |
---|
| 166 | self.generator['freebsd-path'] = builder.FreeBSDPathComposer |
---|
| 167 | self.generator['rtems-path'] = builder.RTEMSPathComposer |
---|
| 168 | self.generator['cpu-path'] = builder.CPUDependentPathComposer |
---|
| 169 | self.generator['target-src-cpu--path'] = builder.TargetSourceCPUDependentPathComposer |
---|
| 170 | |
---|
| 171 | self.generator['source'] = SourceFileFragmentComposer |
---|
| 172 | self.generator['test'] = TestFragementComposer |
---|
| 173 | self.generator['kvm-symbols'] = KVMSymbolsFragmentComposer |
---|
| 174 | self.generator['rpc-gen'] = RPCGENFragmentComposer |
---|
| 175 | self.generator['route-keywords'] = RouteKeywordsFragmentComposer |
---|
| 176 | self.generator['lex'] = LexFragmentComposer |
---|
| 177 | self.generator['yacc'] = YaccFragmentComposer |
---|
| 178 | |
---|
| 179 | def generate(self): |
---|
| 180 | |
---|
| 181 | def _source_list(lhs, files, append = False): |
---|
| 182 | if append: |
---|
| 183 | adder = '+' |
---|
| 184 | adder_space = ' ' |
---|
| 185 | else: |
---|
| 186 | adder = '' |
---|
| 187 | adder_space = '' |
---|
| 188 | ll = len(lhs) |
---|
| 189 | if len(files) == 1: |
---|
| 190 | self.add('%s %s= [%r]' % (lhs, adder, files[0])) |
---|
| 191 | elif len(files) == 2: |
---|
| 192 | self.add('%s %s= [%r,' % (lhs, adder, files[0])) |
---|
| 193 | self.add('%s %s %r]' % (' ' * ll, adder_space, files[-1])) |
---|
| 194 | elif len(files) > 0: |
---|
| 195 | self.add('%s %s= [%r,' % (lhs, adder, files[0])) |
---|
| 196 | for f in files[1:-1]: |
---|
| 197 | self.add('%s %s %r,' % (' ' * ll, adder_space, f)) |
---|
| 198 | self.add('%s %s %r]' % (' ' * ll, adder_space, files[-1])) |
---|
| 199 | |
---|
| 200 | def _data_insert(data, cpu, frag): |
---|
| 201 | # |
---|
| 202 | # The default handler returns an empty string. Skip it. |
---|
| 203 | # |
---|
| 204 | if type(frag) is not str: |
---|
[8440506] | 205 | # Start at the top of the tree |
---|
[5ba6949] | 206 | d = data |
---|
[8440506] | 207 | path = frag[0] |
---|
| 208 | if path[0] not in d: |
---|
| 209 | d[path[0]] = {} |
---|
| 210 | # Select the sub-part of the tree as the compile options |
---|
| 211 | # specialise how files are built. |
---|
| 212 | d = d[path[0]] |
---|
| 213 | if type(path[1]) is list: |
---|
| 214 | p = ' '.join(path[1]) |
---|
| 215 | else: |
---|
| 216 | p = path[1] |
---|
| 217 | if p not in d: |
---|
| 218 | d[p] = {} |
---|
| 219 | d = d[p] |
---|
| 220 | if cpu not in d: |
---|
| 221 | d[cpu] = [] |
---|
[5ba6949] | 222 | if type(frag[1]) is list: |
---|
| 223 | d[cpu] += frag[1] |
---|
| 224 | else: |
---|
| 225 | d[cpu] = frag[1] |
---|
[8440506] | 226 | if len(frag) > 3: |
---|
| 227 | if 'cflags' not in d[cpu]: |
---|
| 228 | d['cflags'] = [] |
---|
| 229 | d['cflags'] += frag[2] |
---|
| 230 | if len(frag) >= 3 and None not in frag[-1]: |
---|
| 231 | if 'includes' not in d[cpu]: |
---|
| 232 | d['includes'] = [] |
---|
| 233 | d['includes'] += frag[-1] |
---|
[5ba6949] | 234 | |
---|
| 235 | data = { } |
---|
| 236 | |
---|
| 237 | for mn in self.getModules(): |
---|
| 238 | m = self[mn] |
---|
| 239 | if m.conditionalOn == "none": |
---|
| 240 | for f in m.files: |
---|
| 241 | _data_insert(data, 'all', f.getFragment()) |
---|
| 242 | for cpu, files in sorted(m.cpuDependentSourceFiles.items()): |
---|
| 243 | for f in files: |
---|
| 244 | _data_insert(data, cpu, f.getFragment()) |
---|
| 245 | |
---|
| 246 | if trace: |
---|
| 247 | import pprint |
---|
| 248 | pprint.pprint(data) |
---|
| 249 | |
---|
| 250 | self.restart() |
---|
| 251 | |
---|
| 252 | self.add('#') |
---|
[e9aa9537] | 253 | self.add('# RTEMS Project (https://www.rtems.org)') |
---|
| 254 | self.add('#') |
---|
| 255 | self.add('# Generated waf script. Do not edit, run ./freebsd-to-rtems.py -m') |
---|
| 256 | self.add('#') |
---|
| 257 | self.add('# To use see README.waf shipped with this file.') |
---|
[5ba6949] | 258 | self.add('#') |
---|
| 259 | self.add('') |
---|
[4963785] | 260 | self.add('import os.path') |
---|
| 261 | self.add('') |
---|
[5ba6949] | 262 | self.add('try:') |
---|
| 263 | self.add(' import rtems_waf.rtems as rtems') |
---|
| 264 | self.add('except:') |
---|
| 265 | self.add(' print "error: no rtems_waf git submodule; see README.waf"') |
---|
| 266 | self.add(' import sys') |
---|
| 267 | self.add(' sys.exit(1)') |
---|
| 268 | self.add('') |
---|
| 269 | self.add('def init(ctx):') |
---|
| 270 | self.add(' rtems.init(ctx)') |
---|
| 271 | self.add('') |
---|
| 272 | self.add('def options(opt):') |
---|
| 273 | self.add(' rtems.options(opt)') |
---|
[e9aa9537] | 274 | self.add(' opt.add_option("--enable-auto-regen",') |
---|
| 275 | self.add(' action = "store_true",') |
---|
| 276 | self.add(' default = False,') |
---|
| 277 | self.add(' dest = "auto_regen",') |
---|
| 278 | self.add(' help = "Enable auto-regeneration of LEX, RPC and YACC files.")') |
---|
| 279 | self.add(' opt.add_option("--enable-warnings",') |
---|
| 280 | self.add(' action = "store_true",') |
---|
| 281 | self.add(' default = False,') |
---|
| 282 | self.add(' dest = "warnings",') |
---|
| 283 | self.add(' help = "Enable all warnings. The default is quiet builds.")') |
---|
[4963785] | 284 | self.add(' opt.add_option("--net-test-config",') |
---|
| 285 | self.add(' default = "config.inc",') |
---|
| 286 | self.add(' dest = "net_config",') |
---|
| 287 | self.add(' help = "Network test configuration.")') |
---|
[5ba6949] | 288 | self.add('') |
---|
[84288f4] | 289 | self.add('def bsp_configure(conf, arch_bsp):') |
---|
| 290 | self.add(' conf.check(header_name = "dlfcn.h", features = "c")') |
---|
[1383c80] | 291 | self.add(' conf.check(header_name = "rtems/pci.h", features = "c", mandatory = False)') |
---|
[84288f4] | 292 | self.add('') |
---|
[5ba6949] | 293 | self.add('def configure(conf):') |
---|
[e9aa9537] | 294 | self.add(' if conf.options.auto_regen:') |
---|
| 295 | self.add(' conf.find_program("lex", mandatory = True)') |
---|
| 296 | self.add(' conf.find_program("rpcgen", mandatory = True)') |
---|
| 297 | self.add(' conf.find_program("yacc", mandatory = True)') |
---|
| 298 | self.add(' conf.env.AUTO_REGEN = conf.options.auto_regen') |
---|
| 299 | self.add(' conf.env.WARNINGS = conf.options.warnings') |
---|
[4963785] | 300 | self.add(' conf.env.NET_CONFIG = conf.options.net_config') |
---|
[84288f4] | 301 | self.add(' rtems.configure(conf, bsp_configure)') |
---|
[5ba6949] | 302 | self.add(' if rtems.check_networking(conf):') |
---|
| 303 | self.add(' conf.fatal("RTEMS kernel contains the old network support; configure RTEMS with --disable-networking")') |
---|
| 304 | self.add('') |
---|
| 305 | self.add('def build(bld):') |
---|
| 306 | self.add(' rtems.build(bld)') |
---|
| 307 | self.add('') |
---|
| 308 | self.add(' # C/C++ flags') |
---|
| 309 | self.add(' common_flags = []') |
---|
| 310 | for f in builder.common_flags(): |
---|
| 311 | self.add(' common_flags += ["%s"]' % (f)) |
---|
[e9aa9537] | 312 | self.add(' if bld.env.WARNINGS:') |
---|
| 313 | for f in builder.common_warnings(): |
---|
| 314 | self.add(' common_flags += ["%s"]' % (f)) |
---|
| 315 | self.add(' else:') |
---|
[5ba6949] | 316 | for f in builder.common_no_warnings(): |
---|
[e9aa9537] | 317 | self.add(' common_flags += ["%s"]' % (f)) |
---|
[5ba6949] | 318 | self.add(' cflags = %r + common_flags' % (builder.cflags())) |
---|
| 319 | self.add(' cxxflags = %r + common_flags' % (builder.cxxflags())) |
---|
| 320 | self.add('') |
---|
| 321 | self.add(' # Include paths') |
---|
[8440506] | 322 | self.add(' includes = ["."]') |
---|
[5ba6949] | 323 | for i in builder.includes(): |
---|
| 324 | self.add(' includes += ["%s"]' % (i[2:])) |
---|
| 325 | self.add(' for i in %r:' % (builder.cpu_includes())) |
---|
| 326 | self.add(' includes += ["%s" % (i[2:].replace("@CPU@", bld.get_env()["RTEMS_ARCH"]))]') |
---|
| 327 | self.add('') |
---|
| 328 | self.add(' # Support dummy PIC IRQ includes') |
---|
| 329 | self.add(' if bld.get_env()["RTEMS_ARCH"] not in ("arm", "i386", "lm32", "mips", "powerpc", "sparc", "m68k"):') |
---|
| 330 | self.add(' includes += ["rtems-dummy-pic-irq/include"]') |
---|
| 331 | self.add('') |
---|
| 332 | |
---|
| 333 | self.add(' # Collect the libbsd uses') |
---|
| 334 | self.add(' libbsd_use = []') |
---|
| 335 | self.add('') |
---|
| 336 | |
---|
[4963785] | 337 | # |
---|
| 338 | # Support the existing Makefile based network configuration file. |
---|
| 339 | # |
---|
| 340 | self.add(' # Network test configuration') |
---|
| 341 | self.add(' if not os.path.exists(bld.env.NET_CONFIG):') |
---|
| 342 | self.add(' bld.fatal("network configuraiton \'%s\' not found" % (bld.env.NET_CONFIG))') |
---|
| 343 | self.add(' net_cfg_self_ip = None') |
---|
| 344 | self.add(' net_cfg_netmask = None') |
---|
| 345 | self.add(' net_cfg_peer_ip = None') |
---|
| 346 | self.add(' net_cfg_gateway_ip = None') |
---|
| 347 | self.add(' net_tap_interface = None') |
---|
| 348 | self.add(' try:') |
---|
| 349 | self.add(' net_cfg_lines = open(bld.env.NET_CONFIG).readlines()') |
---|
| 350 | self.add(' except:') |
---|
| 351 | self.add(' bld.fatal("network configuraiton \'%s\' read failed" % (bld.env.NET_CONFIG))') |
---|
| 352 | self.add(' lc = 0') |
---|
| 353 | self.add(' for l in net_cfg_lines:') |
---|
| 354 | self.add(' lc += 1') |
---|
| 355 | self.add(' if l.strip().startswith("NET_CFG_"):') |
---|
| 356 | self.add(' ls = l.split("=")') |
---|
| 357 | self.add(' if len(ls) != 2:') |
---|
| 358 | self.add(' bld.fatal("network configuraiton \'%s\' parse error: %d: %s" % ' + \ |
---|
| 359 | '(bld.env.NET_CONFIG, lc, l))') |
---|
| 360 | self.add(' lhs = ls[0].strip()') |
---|
| 361 | self.add(' rhs = ls[1].strip()') |
---|
| 362 | self.add(' if lhs == "NET_CFG_SELF_IP":') |
---|
| 363 | self.add(' net_cfg_self_ip = rhs') |
---|
| 364 | self.add(' if lhs == "NET_CFG_NETMASK":') |
---|
| 365 | self.add(' net_cfg_netmask = rhs') |
---|
| 366 | self.add(' if lhs == "NET_CFG_PEER_IP":') |
---|
| 367 | self.add(' net_cfg_peer_ip = rhs') |
---|
| 368 | self.add(' if lhs == "NET_CFG_GATEWAY_IP_IP":') |
---|
| 369 | self.add(' net_cfg_gateway_ip = rhs') |
---|
| 370 | self.add(' if lhs == "NET_TAP_INTERFACE_IP_IP":') |
---|
| 371 | self.add(' net_tap_interface = rhs') |
---|
| 372 | self.add(' bld(target = "testsuite/include/rtems/bsd/test/network-config.h",') |
---|
| 373 | self.add(' source = "testsuite/include/rtems/bsd/test/network-config.h.in",') |
---|
| 374 | self.add(' rule = "sed -e \'s/@NET_CFG_SELF_IP@/%s/\' ' + \ |
---|
| 375 | '-e \'s/@NET_CFG_NETMASK@/%s/\' ' + \ |
---|
| 376 | '-e \'s/@NET_CFG_PEER_IP@/%s/\' ' + \ |
---|
| 377 | '-e \'s/@NET_CFG_GATEWAY_IP@/%s/\' < ${SRC} > ${TGT}" % ' + \ |
---|
[0768880] | 378 | '(net_cfg_self_ip, net_cfg_netmask, net_cfg_peer_ip, net_cfg_netmask),') |
---|
| 379 | self.add(' update_outputs = True)') |
---|
[4963785] | 380 | self.add('') |
---|
| 381 | |
---|
[5ba6949] | 382 | # |
---|
| 383 | # Add the specific rule based builders for generating files. |
---|
| 384 | # |
---|
| 385 | if 'KVMSymbols' in data: |
---|
| 386 | kvmsymbols = data['KVMSymbols'] |
---|
[8440506] | 387 | if 'includes' in kvmsymbols['files']: |
---|
| 388 | includes = kvmsymbols['files']['includes'] |
---|
| 389 | else: |
---|
| 390 | includes = [] |
---|
[5ba6949] | 391 | self.add(' # KVM Symbols') |
---|
[4963785] | 392 | self.add(' bld(target = "%s",' % (kvmsymbols['files']['all'][0])) |
---|
| 393 | self.add(' source = "rtemsbsd/rtems/generate_kvm_symbols",') |
---|
[0768880] | 394 | self.add(' rule = "./${SRC} > ${TGT}",') |
---|
| 395 | self.add(' update_outputs = True)') |
---|
[5ba6949] | 396 | self.add(' bld.objects(target = "kvmsymbols",') |
---|
| 397 | self.add(' features = "c",') |
---|
| 398 | self.add(' cflags = cflags,') |
---|
[8440506] | 399 | self.add(' includes = %r + includes,' % (includes)) |
---|
[5ba6949] | 400 | self.add(' source = "%s")' % (kvmsymbols['files']['all'][0])) |
---|
| 401 | self.add(' libbsd_use += ["kvmsymbols"]') |
---|
| 402 | self.add('') |
---|
| 403 | |
---|
[0768880] | 404 | self.add(' bld.add_group()') |
---|
| 405 | |
---|
[5ba6949] | 406 | if 'RPCGen' in data: |
---|
| 407 | rpcgen = data['RPCGen'] |
---|
| 408 | rpcname = rpcgen['files']['all'][0][:-2] |
---|
| 409 | self.add(' # RPC Generation') |
---|
[e9aa9537] | 410 | self.add(' if bld.env.AUTO_REGEN:') |
---|
| 411 | self.add(' bld(target = "%s.h",' % (rpcname)) |
---|
| 412 | self.add(' source = "%s.x",' % (rpcname)) |
---|
| 413 | self.add(' rule = "${RPCGEN} -h -o ${TGT} ${SRC}")') |
---|
[5ba6949] | 414 | self.add('') |
---|
| 415 | |
---|
| 416 | if 'RouteKeywords' in data: |
---|
| 417 | routekw = data['RouteKeywords'] |
---|
| 418 | rkwname = routekw['files']['all'][0] |
---|
| 419 | self.add(' # Route keywords') |
---|
[e9aa9537] | 420 | self.add(' if bld.env.AUTO_REGEN:') |
---|
| 421 | self.add(' rkw_rule = "cat ${SRC} | ' + \ |
---|
[5ba6949] | 422 | 'awk \'BEGIN { r = 0 } { if (NF == 1) ' + \ |
---|
| 423 | 'printf \\"#define\\\\tK_%%s\\\\t%%d\\\\n\\\\t{\\\\\\"%%s\\\\\\", K_%%s},\\\\n\\", ' + \ |
---|
| 424 | 'toupper($1), ++r, $1, toupper($1)}\' > ${TGT}"') |
---|
[e9aa9537] | 425 | self.add(' bld(target = "%s.h",' % (rkwname)) |
---|
| 426 | self.add(' source = "%s",' % (rkwname)) |
---|
| 427 | self.add(' rule = rkw_rule)') |
---|
[5ba6949] | 428 | self.add('') |
---|
| 429 | |
---|
| 430 | if 'lex' in data: |
---|
| 431 | lexes = data['lex'] |
---|
| 432 | self.add(' # Lex') |
---|
| 433 | for l in lexes: |
---|
| 434 | lex = lexes[l]['all'] |
---|
[8440506] | 435 | if 'cflags' in lex: |
---|
| 436 | lex_defines = [d[2:] for d in lex['cflags']] |
---|
| 437 | else: |
---|
| 438 | lex_defines = [] |
---|
| 439 | if 'includes' in lex: |
---|
| 440 | lex_includes = lex['includes'] |
---|
| 441 | else: |
---|
| 442 | lex_includes = [] |
---|
[e9aa9537] | 443 | self.add(' if bld.env.AUTO_REGEN:') |
---|
| 444 | self.add(' bld(target = "%s.c",' % (lex['file'][:-2])) |
---|
| 445 | self.add(' source = "%s",' % (lex['file'])) |
---|
| 446 | self.add(' rule = "${LEX} -P %s -t ${SRC} | ' % (lex['sym']) + \ |
---|
[5ba6949] | 447 | 'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' > ${TGT}")') |
---|
| 448 | self.add(' bld.objects(target = "lex_%s",' % (lex['sym'])) |
---|
| 449 | self.add(' features = "c",') |
---|
| 450 | self.add(' cflags = cflags,') |
---|
[8440506] | 451 | self.add(' includes = %r + includes,' % (lex_includes)) |
---|
| 452 | self.add(' defines = %r,' % (lex_defines)) |
---|
[5ba6949] | 453 | self.add(' source = "%s.c")' % (lex['file'][:-2])) |
---|
| 454 | self.add(' libbsd_use += ["lex_%s"]' % (lex['sym'])) |
---|
| 455 | self.add('') |
---|
| 456 | |
---|
| 457 | if 'yacc' in data: |
---|
| 458 | yaccs = data['yacc'] |
---|
| 459 | self.add(' # Yacc') |
---|
| 460 | for y in yaccs: |
---|
| 461 | yacc = yaccs[y]['all'] |
---|
| 462 | yacc_file = yacc['file'] |
---|
[8440506] | 463 | if yacc['sym'] is not None: |
---|
| 464 | yacc_sym = yacc['sym'] |
---|
| 465 | else: |
---|
| 466 | yacc_sym = os.path.basename(yacc_file)[:-2] |
---|
[5ba6949] | 467 | yacc_header = '%s/%s' % (os.path.dirname(yacc_file), yacc['header']) |
---|
[8440506] | 468 | if 'cflags' in yacc: |
---|
| 469 | yacc_defines = [d[2:] for d in yacc['cflags']] |
---|
| 470 | else: |
---|
| 471 | yacc_defines = [] |
---|
| 472 | if 'includes' in yacc: |
---|
| 473 | yacc_includes = yacc['includes'] |
---|
| 474 | else: |
---|
| 475 | yacc_includes = [] |
---|
[e9aa9537] | 476 | self.add(' if bld.env.AUTO_REGEN:') |
---|
| 477 | self.add(' bld(target = "%s.c",' % (yacc_file[:-2])) |
---|
| 478 | self.add(' source = "%s",' % (yacc_file)) |
---|
| 479 | self.add(' rule = "${YACC} -b %s -d -p %s ${SRC} && ' % (yacc_sym, yacc_sym) + \ |
---|
[5ba6949] | 480 | 'sed -e \'/YY_BUF_SIZE/s/16384/1024/\' < %s.tab.c > ${TGT} && ' % (yacc_sym) + \ |
---|
| 481 | 'rm -f %s.tab.c && mv %s.tab.h %s")' % (yacc_sym, yacc_sym, yacc_header)) |
---|
| 482 | self.add(' bld.objects(target = "yacc_%s",' % (yacc_sym)) |
---|
| 483 | self.add(' features = "c",') |
---|
| 484 | self.add(' cflags = cflags,') |
---|
[8440506] | 485 | self.add(' includes = %r + includes,' % (yacc_includes)) |
---|
| 486 | self.add(' defines = %r,' % (yacc_defines)) |
---|
[5ba6949] | 487 | self.add(' source = "%s.c")' % (yacc_file[:-2])) |
---|
| 488 | self.add(' libbsd_use += ["yacc_%s"]' % (yacc_sym)) |
---|
| 489 | self.add('') |
---|
| 490 | |
---|
| 491 | # |
---|
| 492 | # We have 'm' different sets of flags and there can be 'n' cpus |
---|
| 493 | # specific files for those flags. |
---|
| 494 | # |
---|
| 495 | objs = 0 |
---|
| 496 | self.add(' # Objects built with different CFLAGS') |
---|
[8440506] | 497 | for flags in sorted(data['sources']): |
---|
| 498 | if flags is not 'default': |
---|
[5ba6949] | 499 | objs += 1 |
---|
[8440506] | 500 | _source_list(' objs%02d_source' % objs, sorted(data['sources'][flags]['all'])) |
---|
| 501 | archs = sorted(data['sources'][flags]) |
---|
[5ba6949] | 502 | for arch in archs: |
---|
[8440506] | 503 | if arch not in ['all', 'cflags', 'includes']: |
---|
[5ba6949] | 504 | self.add(' if bld.get_env()["RTEMS_ARCH"] == "%s":' % arch) |
---|
| 505 | _source_list(' objs%02d_source' % objs, |
---|
[8440506] | 506 | sorted(data['sources'][flags][arch]), |
---|
[5ba6949] | 507 | append = True) |
---|
[8440506] | 508 | if 'cflags' in data['sources'][flags]: |
---|
| 509 | defines = [d[2:] for d in data['sources'][flags]['cflags']] |
---|
| 510 | else: |
---|
| 511 | defines = [] |
---|
| 512 | if 'includes' in data['sources'][flags]: |
---|
| 513 | includes = data['sources'][flags]['includes'] |
---|
| 514 | else: |
---|
| 515 | includes = [] |
---|
[5ba6949] | 516 | self.add(' bld.objects(target = "objs%02d",' % (objs)) |
---|
| 517 | self.add(' features = "c",') |
---|
| 518 | self.add(' cflags = cflags,') |
---|
[8440506] | 519 | self.add(' includes = %r + includes,' % (includes)) |
---|
[5ba6949] | 520 | self.add(' defines = %r,' % (defines)) |
---|
| 521 | self.add(' source = objs%02d_source)' % objs) |
---|
| 522 | self.add(' libbsd_use += ["objs%02d"]' % (objs)) |
---|
| 523 | self.add('') |
---|
| 524 | |
---|
| 525 | # |
---|
| 526 | # We hold the 'default' cflags set of files to the end to create the |
---|
| 527 | # static library with. |
---|
| 528 | # |
---|
| 529 | _source_list(' source', sorted(data['sources']['default']['all'])) |
---|
| 530 | archs = sorted(data['sources']['default']) |
---|
| 531 | for arch in archs: |
---|
| 532 | if arch is not 'all': |
---|
| 533 | self.add(' if bld.get_env()["RTEMS_ARCH"] == "%s":' % arch) |
---|
| 534 | _source_list(' source', |
---|
| 535 | sorted(data['sources']['default'][arch]), |
---|
| 536 | append = True) |
---|
| 537 | self.add(' bld.stlib(target = "bsd",') |
---|
| 538 | self.add(' features = "c cxx",') |
---|
| 539 | self.add(' cflags = cflags,') |
---|
| 540 | self.add(' cxxflags = cxxflags,') |
---|
| 541 | self.add(' includes = includes,') |
---|
| 542 | self.add(' source = source,') |
---|
| 543 | self.add(' use = libbsd_use)') |
---|
| 544 | self.add('') |
---|
| 545 | |
---|
[0768880] | 546 | # |
---|
| 547 | # Head file collector. |
---|
| 548 | # |
---|
| 549 | self.add(' # Installs. ') |
---|
| 550 | self.add(' bld.install_files("${PREFIX}/" + rtems.arch_bsp_lib_path(bld.env.RTEMS_ARCH_BSP), ["libbsd.a"])') |
---|
| 551 | header_paths = builder.header_paths() |
---|
| 552 | self.add(' header_paths = [%s,' % (str(header_paths[0]))) |
---|
| 553 | for hp in header_paths[1:-1]: |
---|
| 554 | self.add(' %s,' % (str(hp))) |
---|
| 555 | self.add(' %s]' % (str(header_paths[-1]))) |
---|
| 556 | self.add(' for headers in header_paths:') |
---|
| 557 | self.add(' ipath = os.path.join(rtems.arch_bsp_include_path(bld.env.RTEMS_ARCH_BSP), headers[2])') |
---|
| 558 | self.add(' start_dir = bld.path.find_dir(headers[0])') |
---|
| 559 | self.add(' bld.install_files("${PREFIX}/" + ipath,') |
---|
| 560 | self.add(' start_dir.ant_glob("**/" + headers[1]),') |
---|
| 561 | self.add(' cwd = start_dir,') |
---|
| 562 | self.add(' relative_trick = True)') |
---|
| 563 | self.add('') |
---|
| 564 | |
---|
[5ba6949] | 565 | self.add(' # Tests') |
---|
| 566 | tests = data['tests'] |
---|
| 567 | for test_name in tests: |
---|
| 568 | files = ['testsuite/%s/%s.c' % (test_name, f) for f in data['tests'][test_name]['all']['files']] |
---|
| 569 | _source_list(' test_%s' % (test_name), sorted(files)) |
---|
| 570 | self.add(' bld.program(target = "%s",' % (test_name)) |
---|
| 571 | self.add(' features = "cprogram",') |
---|
| 572 | self.add(' cflags = cflags,') |
---|
| 573 | self.add(' includes = includes,') |
---|
| 574 | self.add(' source = test_%s,' % (test_name)) |
---|
| 575 | self.add(' use = ["bsd"],') |
---|
[0768880] | 576 | self.add(' lib = ["m", "z"],') |
---|
| 577 | self.add(' install_path = None)') |
---|
[5ba6949] | 578 | self.add('') |
---|
| 579 | |
---|
| 580 | self.write() |
---|