[Scons-users] Modify CXXFile Builder

luke+scons-ml at lukedrummond.net luke+scons-ml at lukedrummond.net
Tue Nov 18 07:29:45 EST 2014


    How about something like this? (untested)


    def do_sed_lex_junk(target=None, source=None, env=None):
        # call out to
        env = env or Environment()
        env.Command(target, source,
            """lex++ -Cfr -p -$TARGET $SOURCE; cat $TARGET | sed
's/#include <FlexLexer.h>//g' > $TARGET_new.cc; mv $TARGET_new.cc
$TARGET"""
        )


    dynamically_generated_target = os.path.join(thisdir, 'file.cc')
    dynamically_generated_target_sources = os.path.join(thisdir, 'scanner.l')
    env.Depends(dynamically_generated_target,
dynamically_generated_target_sources)
    env.Command(dynamically_generated_target, do_sed_lex_junk)


- The env.Command builder calls out to sed/lex and is passed a list of sources.
- The env.Depends() call makes sure that file.cc is rebuilt using
`do_sed_lex_junk()` whenver the sources change.

Like I said, I haven't tested this, but I do something very similar to
compile a bunch of Lua sources into a static C array that's embedded
into a library:

    https://github.com/ldrumm/libbeemo/blob/master/src/lua/SConscript

Hope that helps


More information about the Scons-users mailing list