summaryrefslogtreecommitdiff
path: root/py/waf/tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'py/waf/tools.py')
-rw-r--r--py/waf/tools.py256
1 files changed, 256 insertions, 0 deletions
diff --git a/py/waf/tools.py b/py/waf/tools.py
new file mode 100644
index 0000000000..9e6a415319
--- /dev/null
+++ b/py/waf/tools.py
@@ -0,0 +1,256 @@
+from waflib.Logs import pprint
+from os.path import exists, getmtime
+
+
+def fatal(str):
+ pprint('RED', str)
+ exit(1)
+
+def generate_rtems_config(ctx, file_in, file_out, devel=False):
+ from os import fchmod
+ from pprint import PrettyPrinter
+ srcnode = ctx.srcnode.abspath()
+ pp = PrettyPrinter(depth=4)
+ bsps = {}
+
+
+ for bsp in ctx.env.BSP:
+ env = ctx.all_envs[bsp]
+ bsps[bsp] = {
+ # XXX: This really needs to use features to get the paths.
+ "cflags": env.CFLAGS + env.CONFIG_CFLAGS + \
+ [
+ "-I%s/cpukit/include" % srcnode, "-I%s/cpukit/score/cpu/%s/include/" % (srcnode, env.RTEMS_ARCH),
+ "-I%s/bsps/%s/%s/include/" % (srcnode, env.RTEMS_ARCH, env.BSP_SOURCE_DIR),
+ "-I%s/bsps/include/" % srcnode,
+ "-I%s/bsps/%s/include/" % (srcnode, env.RTEMS_ARCH)
+ ],
+ "libs": env.LIBS + ["-lrtemscpu -lrtemsbsp"] + env.CONFIG_LIBS,
+ "ldflags": env.LDFLAGS + env.CONFIG_LDFLAGS,
+ "description": env.CONFIG_DESCRIPTION
+ }
+
+ if devel:
+ path_bld = "%s/%s" % (ctx.bldnode.abspath(), bsp)
+
+ include = []
+ include.append("-I%s/include" % srcnode)
+ include.append("-I%s/include" % path_bld)
+ include.append("-I%s/include/rtems" % path_bld)
+ bsps[bsp]["cflags"] = include + bsps[bsp]["cflags"]
+# bsps[bsp]["libs"] = ["%s/c/start.o" % path_bld] + bsps[bsp]["libs"]
+
+ ldflags = []
+ ldflags.append("-specs %s/gcc_spec" % path_bld)
+ ldflags.append("-L%s/cpukit/" % path_bld)
+ ldflags.append("-L%s/c/" % path_bld)
+# ldflags.append("-Wl,-T %s/c/linkcmds" % path_bld)
+# bsps[bsp]["ldflags"] = ldflags + bsps[bsp]["libs"]
+ bsps[bsp]["ldflags"] += ldflags + ["-Wl,-start-group"] + bsps[bsp]["libs"] + ["-lc"] + ["-lgcc"] + ["-Wl,-end-group"]
+
+ else:
+ raise Exception("Doesn't work in install mode yet.")
+
+ #XXX: file_in and file_out can be automatically calculated they don't need to be parms.
+ with open(file_in, "r") as fp:
+ config = fp.read()
+
+ with open(file_out, "w") as fp:
+ fp.write('#!%s\n' % ctx.env.BIN_PYTHON[0]) # XXX: How does this work on Windows?
+ fp.write('RTEMS_VERSION = "%s"\n' % ctx.env.RTEMS_VERSION)
+ fp.write('PREFIX="%s"\n' % ctx.env.PREFIX)
+ fp.write('BSP_LIST = %s\n' % pp.pformat(bsps))
+ fp.write(config)
+ fchmod(fp.fileno(), 0o755)
+
+
+# XXX: rewrite this.
+def generate_gcc_spec_file(ctx, devel=False):
+
+ path_bld = "%s/%s" % (ctx.bldnode.abspath(), ctx.variant)
+ path_bld_linkcmds = "%s/bsps/" % path_bld #XXX temp for new build.
+ path_bld_shared = "%s/bsps/%s/shared/" % (path_bld, ctx.env.RTEMS_ARCH) #XXX temp for new build.
+ path_bld_bsp = "%s/bsps/%s/%s/" % (path_bld, ctx.env.RTEMS_ARCH, ctx.env.RTEMS_BSP) #XXX temp for new build.
+ data = []
+
+# /mnt/devel/rtems/commit/build/sparc/erc32/bsps/sparc/shared//linkcmds
+# /mnt/devel/rtems/commit/build/sparc/erc32/bsps/linkcmds
+
+ def expand_flags(ctx, obj_list):
+# path_bld = "%s/%s" % (ctx.bldnode.abspath(), ctx.variant)
+ l = []
+ for obj in obj_list:
+ obj = obj.replace("${RTEMS_LINKCMDS}", "%s" % path_bld_linkcmds)
+ obj = obj.replace("${RTEMS}", "%s" % path_bld_shared)
+ obj = obj.replace("${RTEMS_BSP}", "%s" % path_bld_bsp)
+
+ if obj.endswith('.o'):
+ fmt = '%s%%s'
+ else:
+ fmt = '%s'
+ l.append(fmt % obj)
+ return " ".join(l)
+
+ data.append("*startfile:")
+ data.append(expand_flags(ctx, ctx.env.LINK_START))
+ data.append("")
+ data.append("*endfile:")
+ data.append(expand_flags(ctx, ctx.env.LINK_END))
+ data.append("")
+ data.append("*link:")
+ data.append(expand_flags(ctx, ctx.env.LINK_LINK))
+
+ with open("%s/gcc_spec" % path_bld, "w") as fp:
+ for line in data:
+ fp.write(line)
+ fp.write("\n")
+
+ ctx.env.append_value('cfg_files', "%s/gcc_spec" % path_bld)
+
+ return "%s/%s/gcc_spec" % (ctx.bldnode, ctx.variant)
+
+
+
+# Get all the BSPs for a specific arch
+def rtems_bsp_arch_all(arch):
+ from py.config.bsp import map_bsp
+ list_bsp = map_bsp() #XXX: temp
+
+ if arch not in list_bsp:
+ fatal("Incorrect arch for --bsp, must be in the form of arch or arch/name: \"%s\"" % arch)
+ bsp_list = []
+ for bsp in list_bsp[arch]:
+ bsp_list += ['%s/%s' % (arch, bsp)]
+ return bsp_list
+
+
+# Get all the BSPs
+def rtems_bsp_all():
+ from py.config.bsp import map_bsp
+ list_bsp = map_bsp() #XXX: temp
+
+ bsp_list = []
+ for arch in list_bsp:
+ for bsp in list_bsp[arch]:
+ bsp_list += ['%s/%s' % (arch, bsp)]
+ return bsp_list
+
+
+def rtems_bsp_wildcard(pattern):
+ if '.' in pattern:
+ pattern = pattern.replace('.', '\.')
+ if '*' in pattern:
+ pattern = pattern.replace('*', '.*')
+ return '^' + pattern + '$'
+
+
+def rtems_bsp_list(bsps):
+ import re
+ from py.config.bsp import map_bsp
+ list_bsp = map_bsp() #XXX: temp
+
+ bsp_list = [x.strip() for x in bsps.split(',')]
+
+ verified_bsp_list = []
+
+ for bsp in bsp_list:
+ if '/' not in bsp:
+ fatal("Incorrect value for --bsp must be in the form of arch/name: \"%s\"" % bsp)
+ (arch, bsp) = bsp.split('/')
+ pa = re.compile(rtems_bsp_wildcard(arch), re.IGNORECASE)
+ pb = re.compile(rtems_bsp_wildcard(bsp), re.IGNORECASE)
+
+ for arch in list_bsp:
+ if pa.match(arch) is not None:
+ for bsp in list_bsp[arch]:
+ if pb.match(bsp) is not None:
+ arch_bsp = '%s/%s' % (arch, bsp)
+ verified_bsp_list += [arch_bsp]
+
+ return sorted(verified_bsp_list)
+
+
+def rtems_cmd_config(ctx):
+ from py.config import BuildConfig, RTEMSConfig
+ from py.config.bsp import get_option_class, get_config_class
+
+ rc = RTEMSConfig(get_option_class(), get_config_class())
+
+ if ctx.options.list is True:
+ from py.config.bsp import map_bsp
+ list_bsp = map_bsp() #XXX: temp
+
+ from py.config import BuildConfig
+# cfg = BuildConfig(rc)
+
+ for arch in sorted(list_bsp):
+ print("")
+ print(arch)
+
+ for bsp in sorted(list_bsp[arch]):
+# descr = cfg.bsp_get_detail(arch, bsp)
+ descr = "" #XXX: There is a bug here fix needs to be in config/base/BuildConfig::_parse_bsp
+ print(" %-22s %s" % ("%s/%s" % (arch, bsp), descr))
+ return
+
+
+
+
+ if ctx.options.force is False and exists("config.cfg"):
+ ctx.fatal("Please delete config.cfg before creating a new one.")
+
+ if not ctx.options.bsps:
+ ctx.fatal("You must specify a single or comma separated list of BSPs using --bsp")
+
+ bsp_list = rtems_bsp_list(ctx.options.bsps)
+ if not bsp_list:
+ ctx.fatal("You must specify a single or comma separated list of BSPs using --bsp")
+
+
+ cfg = BuildConfig(rc, bsp_list)
+ cfg.option_set("general", "PATH_TOOLS", ctx.options.path_tools or "")
+ cfg.option_set("general", "PREFIX", ctx.options.prefix or "")
+ cfg.save()
+
+ pprint("YELLOW", "Wrote config.cfg")
+ archs = {}
+ for bsp in bsp_list:
+ pprint("YELLOW", " - %s" % bsp)
+ arch = bsp.split('/')[0]
+ if arch not in archs:
+ archs[arch] = 0
+ archs[arch] += 1
+
+ pprint("YELLOW", "Configured BSPS:")
+ pprint("YELLOW", " Total : %d" % len(bsp_list))
+ arch_list = sorted(archs.keys())
+ for arch in arch_list:
+ pprint("YELLOW", " %-8s: %d" % (arch, archs[arch]))
+
+
+def rtems_cmd_bsp(ctx):
+ ctx.fatal("Not implemented.")
+ print("List of available BSPs")
+ print("List of DISABLED BSPs")
+
+
+# Get file mtime.
+def get_file_mtime(file):
+ return getmtime(file)
+
+
+from subprocess import Popen, PIPE
+
+def run(cmd):
+ p = Popen(cmd, stdout=PIPE, stderr=PIPE)
+ stdout, stderr = p.communicate()
+ return stdout[:-1], stderr[:-1], p.returncode
+
+
+def get_options(bsp):
+ pass
+
+def get_config(bsp):
+ pass
+
+