[Scons-users] Request help on the usage of scons

Daniel Moody dmoody256 at gmail.com
Wed Sep 7 10:57:06 EDT 2022


setting the specific flag on the invocation of the specific builder would
be the recommended way to do this:

object_nodelist = env.Object('src/sample.c', CFLAGS=env.get('CFLAGS', []) +
['-Wno-conversion'])

But assuming this is for some reason not possible, there are other
roundabout ways to do this. I am also assuming you only have access to the
environment? One thing you could do is create a generator that expands to
one or the other depending on the source file. Here is an example:

def cflags_warn_conversion(env, source, target, for_signature):
    if source[0].abspath == env.File('#src/sample.c').abspath:
        return '-Wno-conversion'
    else:
        return '-Wconversion'

env['CFLAGS_WARN_CONVERSION_GEN'] = cflags_warn_conversion
env.Append(CFLAGS=['$CFLAGS_WARN_CONVERSION_GEN'])

What this is doing is putting a function in the CFLAGS to run when
evaluating an expansion, when the CFLAGS is being evaluated to execute a
command line, scons will perform expansion on any $ variables, and so the
source file would be identified and the correct command line flag would be
added to the command line.


On Wed, Sep 7, 2022 at 3:25 AM David Zhu via Scons-users <
scons-users at scons.org> wrote:

> Dear scons community,
>
> Sorry for bothering.
>
> I have a question about the usage of scons.
>
> Firstly, I want to explain my requirement by makefile.
>
> In makefile, I can configure the CFLAGS for a specific C source file
> without changing other parts of the build script.
>
> For example, I add below line in makefile to apply '-Wno-conversion' for
> 'src/sample.c'.
>
> ----------
>
> src/sample.o: CFLAGS += -Wno-conversion
>
> ----------
>
> The reason is that '-Wconversion' is configured for all source files but I
> want to remove the conversion check for 'src/sample.c' only.
>
> So my question is how to configure that in scons?
>
> In my project, I can only edit the script in a small range. I cannot use
> 'env.Object' to generate 'sample.o' in this range.
>
> 'env.Object' must be called in the next step by another script shared by
> all modules.
>
> Many thanks for your help!
>
> Best Regards,
>
> David
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20220907/6da7d4e5/attachment.htm>


More information about the Scons-users mailing list