<div><div dir="auto">Hi Chris,</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 15 Mar 2020 at 21:09, Chris Johns <<a href="mailto:chrisj@rtems.org">chrisj@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Hesham,<br>
<br>
This is a great addition to rtems_waf, some comments below.<br>
<br>
On 16/3/20 2:56 am, Hesham Almatary wrote:<br>
> ---<br>
>  rtems.py | 85 +++++++++++++++++++++++++++++++++++++++++---------------<br>
>  1 file changed, 62 insertions(+), 23 deletions(-)<br>
> <br>
> diff --git a/rtems.py b/rtems.py<br>
> index ffb386f..f1ef4de 100644<br>
> --- a/rtems.py<br>
> +++ b/rtems.py<br>
> @@ -1,4 +1,5 @@<br>
>  <br>
> +# Copyright 2020 Hesham Almatary<br>
>  # Copyright 2012-2016 Chris Johns (<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>)<br>
>  #<br>
>  # Redistribution and use in source and binary forms, with or without<br>
> @@ -63,6 +64,10 @@ def options(opt):<br>
>                     default = 'all',<br>
>                     dest = 'rtems_bsps',<br>
>                     help = 'List of BSPs to build.')<br>
> +    opt.add_option('--rtems-compiler',<br>
> +                   default = 'gcc',<br>
> +                   dest = 'rtems_compiler',<br>
> +                   help = 'RTEMS compiler to use available options are clang and gcc (defaults to gcc).')<br>
>      opt.add_option('--show-commands',<br>
>                     action = 'store_true',<br>
>                     default = False,<br>
> @@ -104,15 +109,17 @@ def init(ctx, filters = None, version = None, long_commands = False, bsp_init =<br>
>          #<br>
>          # Check the tools, architectures and bsps.<br>
>          #<br>
> -        rtems_version, rtems_path, rtems_tools, archs, arch_bsps = \<br>
> +        rtems_compiler, rtems_version, rtems_path, rtems_tools, archs, arch_bsps = \<br>
>              check_options(ctx,<br>
>                            env.options['prefix'],<br>
> +                          env.options['rtems_compiler'],<br>
>                            env.options['rtems_tools'],<br>
>                            env.options['rtems_path'],<br>
>                            env.options['rtems_version'],<br>
>                            env.options['rtems_archs'],<br>
>                            env.options['rtems_bsps'])<br>
>  <br>
> +        print("RTEMS Compiler is " + rtems_compiler)<br>
<br>
Please use `conf.msg()`. See <a href="https://git.rtems.org/rtems_waf/tree/rtems.py#n248" rel="noreferrer" target="_blank">https://git.rtems.org/rtems_waf/tree/rtems.py#n248</a><br>
<br>
>          #<br>
>          # Update the contexts for all the bsps.<br>
>          #<br>
> @@ -176,9 +183,10 @@ def configure(conf, bsp_configure = None):<br>
>      else:<br>
>          long_commands = 'no'<br>
>  <br>
> -    rtems_version, rtems_path, rtems_tools, archs, arch_bsps = \<br>
> +    rtems_compiler, rtems_version, rtems_path, rtems_tools, archs, arch_bsps = \<br>
>          check_options(conf,<br>
>                        conf.options.prefix,<br>
> +                      conf.options.rtems_compiler,<br>
>                        conf.options.rtems_tools,<br>
>                        conf.options.rtems_path,<br>
>                        conf.options.rtems_version,<br>
> @@ -222,13 +230,19 @@ def configure(conf, bsp_configure = None):<br>
>          conf.env.RTEMS_ARCH_RTEMS = arch<br>
>          conf.env.RTEMS_BSP = bsp<br>
>  <br>
> -        tools = _find_tools(conf, arch, rtems_tools, tools)<br>
> +        tools = _find_tools(conf, arch, rtems_compiler, rtems_tools, tools)<br>
>          for t in tools[arch]:<br>
>              conf.env[t] = tools[arch][t]<br>
>  <br>
> -        conf.load('gcc')<br>
> -        conf.load('g++')<br>
> -        conf.load('gas')<br>
> +        if rtems_compiler == 'gcc':<br>
> +            conf.load('gcc')<br>
> +            conf.load('g++')<br>
> +            conf.load('gas')<br>
> +        elif rtems_compiler == 'clang':<br>
> +            conf.load('clang')<br>
> +            conf.load('clang++')<br>
> +        else:<br>
> +            conf.fatal('Unknown RTEMS compiler: ' + rtems_compiler)<br>
>  <br>
>          #<br>
>          # Get the version of the tools being used.<br>
> @@ -388,7 +402,7 @@ def tweaks(conf, arch_bsp):<br>
>      if '-ffunction-sections' in conf.env.CFLAGS:<br>
>        conf.env.LINKFLAGS += ['-Wl,--gc-sections']<br>
>  <br>
> -def check_options(ctx, prefix, rtems_tools, rtems_path, rtems_version, rtems_archs, rtems_bsps):<br>
> +def check_options(ctx, prefix, rtems_compiler, rtems_tools, rtems_path, rtems_version, rtems_archs, rtems_bsps):<br>
>      #<br>
>      # Set defaults<br>
>      #<br>
> @@ -406,6 +420,12 @@ def check_options(ctx, prefix, rtems_tools, rtems_path, rtems_version, rtems_arc<br>
>      if rtems_tools is None:<br>
>          rtems_tools = rtems_path<br>
>  <br>
> +    #<br>
> +    # Check the compiler option is valid.<br>
> +    #<br>
> +    if rtems_compiler not in ['gcc', 'clang']:<br>
<br>
Key in compiler dict? See below.<br>
<br>
> +        ctx.fatal('Valid RTEMS compilers are gcc or clang')<br>
> +<br>
>      #<br>
>      # Check the paths are valid.<br>
>      #<br>
> @@ -476,7 +496,7 @@ def check_options(ctx, prefix, rtems_tools, rtems_path, rtems_version, rtems_arc<br>
>      #<br>
>      arch_bsps = filter(ctx, 'bsps', arch_bsps)<br>
>  <br>
> -    return rtems_version, rtems_path, tools, archs, arch_bsps<br>
> +    return rtems_compiler, rtems_version, rtems_path, tools, archs, arch_bsps<br>
>  <br>
>  def check_env(ctx, var):<br>
>      if var in ctx.env and len(ctx.env[var]) != 0:<br>
> @@ -682,22 +702,40 @@ def long_command_line():<br>
>              if hasattr(cls, 'hcode'):<br>
>                  derived_class.hcode = cls.hcode<br>
>  <br>
> -def _find_tools(conf, arch, paths, tools):<br>
> +def _find_tools(conf, arch, rtems_compiler, paths, tools):<br>
>      if arch not in tools:<br>
>          arch_tools = {}<br>
> -        arch_tools['CC']          = conf.find_program([arch + '-gcc'], path_list = paths)<br>
> -        arch_tools['CXX']         = conf.find_program([arch + '-g++'], path_list = paths)<br>
> -        arch_tools['LINK_CC']     = arch_tools['CC']<br>
> -        arch_tools['LINK_CXX']    = arch_tools['CXX']<br>
> -        arch_tools['AS']          = conf.find_program([arch + '-gcc'], path_list = paths)<br>
> -        arch_tools['LD']          = conf.find_program([arch + '-ld'],  path_list = paths)<br>
> -        arch_tools['AR']          = conf.find_program([arch + '-ar'], path_list = paths)<br>
> -        arch_tools['NM']          = conf.find_program([arch + '-nm'], path_list = paths)<br>
> -        arch_tools['OBJDUMP']     = conf.find_program([arch + '-objdump'], path_list = paths)<br>
> -        arch_tools['OBJCOPY']     = conf.find_program([arch + '-objcopy'], path_list = paths)<br>
> -        arch_tools['READELF']     = conf.find_program([arch + '-readelf'], path_list = paths)<br>
> -        arch_tools['STRIP']       = conf.find_program([arch + '-strip'], path_list = paths)<br>
> -        arch_tools['RANLIB']      = conf.find_program([arch + '-ranlib'], path_list = paths)<br>
> +        if rtems_compiler == 'gcc':<br>
> +            arch_tools['CC']          = conf.find_program([arch + '-gcc'], path_list = paths)<br>
> +            arch_tools['CXX']         = conf.find_program([arch + '-g++'], path_list = paths)<br>
> +            arch_tools['LINK_CC']     = arch_tools['CC']<br>
> +            arch_tools['LINK_CXX']    = arch_tools['CXX']<br>
> +            arch_tools['AS']          = conf.find_program([arch + '-gcc'], path_list = paths)<br>
> +            arch_tools['LD']          = conf.find_program([arch + '-ld'],  path_list = paths)<br>
> +            arch_tools['AR']          = conf.find_program([arch + '-ar'], path_list = paths)<br>
> +            arch_tools['NM']          = conf.find_program([arch + '-nm'], path_list = paths)<br>
> +            arch_tools['OBJDUMP']     = conf.find_program([arch + '-objdump'], path_list = paths)<br>
> +            arch_tools['OBJCOPY']     = conf.find_program([arch + '-objcopy'], path_list = paths)<br>
> +            arch_tools['READELF']     = conf.find_program([arch + '-readelf'], path_list = paths)<br>
> +            arch_tools['STRIP']       = conf.find_program([arch + '-strip'], path_list = paths)<br>
> +            arch_tools['RANLIB']      = conf.find_program([arch + '-ranlib'], path_list = paths)<br>
> +        elif rtems_compiler == 'clang':<br>
> +            arch_tools['CC']          = conf.find_program('clang')<br>
> +            arch_tools['CXX']         = conf.find_program('clang++')<br>
> +            arch_tools['LINK_CC']     = arch_tools['CC']<br>
> +            arch_tools['LINK_CXX']    = arch_tools['CXX']<br>
> +            arch_tools['AS']          = conf.find_program('clang')<br>
> +            arch_tools['LD']          = conf.find_program('lld')<br>
> +            arch_tools['AR']          = conf.find_program('llvm-ar')<br>
> +            arch_tools['NM']          = conf.find_program('llvm-nm')<br>
> +            arch_tools['OBJDUMP']     = conf.find_program('llvm-objdump')<br>
> +            arch_tools['OBJCOPY']     = conf.find_program('llvm-objcopy')<br>
> +            arch_tools['READELF']     = conf.find_program('llvm-readelf')<br>
> +            arch_tools['STRIP']       = conf.find_program('llvm-strip')<br>
> +            arch_tools['RANLIB']      = conf.find_program('llvm-ranlib')<br>
<br>
Could this be defined in a compile dict?<br>
</blockquote><div dir="auto">Do you mean just the names of the tools being values?</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Why does llvm not require a path_list?<br>
</blockquote><div dir="auto">I didn’t want to restrict the search path to rtems-prefix only but rather search from $PATH. That follows the rtems/waf (new build system) convention by default. As you know, Clang/LLVM don’t need multiple builds for each target/OS, but they have all backends for all supported architectures and OSes with a single frontend. So putting a custom Clang/LLVM build in RTEMS tools like we do with gcc didn’t make much sense to me. </div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Chris<br>
<br>
> +        else:<br>
> +            conf.fatal('Unknown RTEMS Compiler')<br>
> +<br>
>          arch_tools['RTEMS_LD']    = conf.find_program(['rtems-ld'], path_list = paths,<br>
>                                                        mandatory = False)<br>
>          arch_tools['RTEMS_TLD']   = conf.find_program(['rtems-tld'], path_list = paths,<br>
> @@ -837,7 +875,8 @@ def _filter_flags(label, flags, arch, rtems_path):<br>
>            { 'key': 'includes', 'path': True,  'flags': { '-I': 1, '-isystem': 2, '-sysroot': 2 } },<br>
>            { 'key': 'libpath',  'path': True,  'flags': { '-L': 1 } },<br>
>            { 'key': 'machines', 'path': True,  'flags': { '-O': 1, '-m': 1, '-f': 1, '-G':1, '-E':1 } },<br>
> -          { 'key': 'specs',    'path': True,  'flags': { '-q': 1, '-B': 2, '--specs': 2 } } ]<br>
> +          { 'key': 'specs',    'path': True,  'flags': { '-q': 1, '-B': 2, '--specs': 2 } },<br>
> +          { 'key': 'target',    'path': True,  'flags': { '--target': 1 } } ]<br>
>  <br>
>      flags = _strip_cflags(flags)<br>
>  <br>
> <br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>