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