Custom Builders

scons can be extended to build different types of targets by adding new Builder objects to a construction environment.

Generator

A function that returns a list of actions that will be executed to build the target(s) from the source(s).

The returned action(s) may be an Action object, or anything that can be converted into an Action object.

A generator function takes four arguments:

  • source - a list of source nodes,
  • target - a list of target nodes,
  • env - the construction environment,
  • for_signature - a Boolean value that specifies whether the generator is being called for generating a build signature (as opposed to actually executing the command).
# binary file builder
def arm_generator(source, target, env, for_signature):
    return '$OBJCOPY -O binary %s %s'%(source[0], target[0])
env.Replace(OBJCOPY="arm-none-eabi-objcopy")

# binary file builder
def arm_generator(source, target, env, for_signature):
    return '$OBJCOPY -O binary %s %s'%(source[0], target[0])


prg = env.Program(
    target = 'application',
    source = [] + system_sources + driver_sources + program_sources + middleware_sources
)

env.Append(BUILDERS = {
    'Objcopy': Builder(
        generator=arm_generator,
        suffix='.bin',
        src_suffix='.elf'
    )
})

env.Objcopy(prg)

will create the file application.binfrom the file application.elf

results matching ""

    No results matching ""