[Scons-users] Custom Builder Tool for IAR Compiler

Marco Schuler marco.schuler at gmail.com
Wed Oct 4 11:54:31 EDT 2017


Hello

I have a IAR compiler for STM8 microcontrollers and since it is rather
different to call compared to gcc, I implemented a custom Builder/Tool for
it. I was following https://github.com/SConsProject/scons/wiki/ToolsForFools
.

Here is the directories and files that I have:

site_scons/
    site_tools/
        stm8.py
    site_init.py
src/
    main.c
SConstruct

site_init.py so far is an empty file.

Contents of stm8.py is:

import os

import SCons.Action
import SCons.Builder
import SCons.Util

class ToolStm8Warning(SCons.Warnings.Warning):
    pass

class Stm8CompilerNotFound(ToolStm8Warning):
    pass

SCons.Warnings.enableWarningClass(ToolStm8Warning)


#
# Builders
#

_stm8_builder =
SCons.Builder.Builder(action=SCons.Action.Action('$STM8_COM',
'$STM8_COMSTR'),

 suffix='$STM8_SUFFIX',

 src_suffix='$STM8_SRC_SUFFIX')

def generate(env):
    """Add Builders and construction variables to the Environment."""

    env['STM8'] = 'iccstm8.exe'

    env['CFLAGS']=[
       '-e',
       '-Ol',
       '--no_cse',
       '--no_unroll',
       '--no_inline',
       '--no_code_motion',
       '--no_tbaa',
       '--no_cross_call',
       '--debug',
       '--code_model', 'small',
       '--data_model', 'medium',
       '--dlib_config', 'C:\Program Files (x86)\IAR Systems\Embedded
Workbench 7.3\stm8\LIB\dlstm8smn.h',
       '--vregs', '16'
    ]

    env.SetDefault(
        # suffixes/prefixes
        STM8_SUFFIX = ".o",
        STM8_SRC_SUFFIX = ".c",

        # command
        STM8_COM = '$STM8 $CFLAGS $SOURCES',
        STM8_COMSTR = '')

    # Add stm8 builder to builders
    env['BUILDERS']['Stm8'] = _stm8_builder


def exists(env):
    """Check if the preconditions for our tool are met."""

    return env.Detect('iccstm8.exe')


SConstruct contains the following:

import os

env  = Environment(tools=['stm8'],
                   ENV=os.environ) # take os-environment to have compiler
in path

env.Stm8('src\main','src\main')

When I run scons, then a main.o is created in the top level directory.

But actually, I would like to use (instead of env.Stm8):

env.Program(target='main', source='main')

to build the program.

Obviously, the ProgramBuilder is not available anymore in my environment.
How can I implement my Tool so that I can use env.Program? Did I understand
something wrong about the usage of a Tool/Builder?

Sorry if the questions might be too basic. I am new to scons...

--
Regards,
 Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20171004/745f0e51/attachment.html>


More information about the Scons-users mailing list