Re: Request help on the usage of scons

Daniel Moody <[email protected]>
Newsgroups gmane.comp.programming.tools.scons.user
Message-ID <CANws3JTkOsLXaEYJTrj8xGNmd0DLTQC4LP30ndh7twY094zxiw@mail.gmail.com>
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 <
[email protected]> 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
> [email protected]
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>

_______________________________________________
Scons-users mailing list
[email protected]
https://pairlist4.pair.net/mailman/listinfo/scons-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.