[Scons-users] scons add source file suffix for env.Object()
Mats Wichmann
mats at wichmann.us
Tue Oct 29 10:14:14 EDT 2024
On 10/29/24 07:17, 于 wrote:
> Hello,
>
> I use scons to build MCU project, and the project need asm
> files. The file suffix is *.850.
> Scons report a error message "scons: *** While building `['']':
> Cannot deduce file extension from source files".
> I think I can add environment to resolve the problem. But I
> don't know how to set src_suffix.
> Thanks everyone.
It's not entirely trivial, and involves using features that are not
documented as part of the "public API" - that is, you won't find these
in the man page.
You can write your own builder for those files - that's the place you
can specify src_suffix by that name - or you can sneak in and modify the
existing Object (and maybe SharedObject?) builders. The latter is
probably easier because Object (which is a synonym for StaticObject) is
already plumbed into the system.
In general terms, that could look like this, assuming your situation
just uses the regular assembler and doesn't require special syntax, etc.
(you didn't say). This has to happen after the construction environment
is created:
import SCons.Defaults
static_obj = env["BUILDERS"]["StaticObject"]
suffix = ".850"
static_obj.add_action(suffix, SCons.Defaults.ASAction)
static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
# repeat if needed for SharedObject
There may be additional steps needed.
It that works out you can turn it into a tool - see the User Guide for
some details on how to do that. The advantage of a tool is you put its
name in the tool list when instantiating an Environment, like
env = Environment(tools=["default", "myasm"])
and it just gets taken care of...
More information about the Scons-users
mailing list