[Scons-users] Replace env['BUILDERS']['Program'] and env.Configure

Ringo De Smet ringo.desmet at gmail.com
Thu Nov 8 03:33:20 EST 2012


Luc,

On 24 August 2012 10:52, Luc Bourhis <luc_j_bourhis at mac.com> wrote:


> > If you create the shared and static libraries into different

> directories, then it should be fairly easy.

>

> I am afraid I can't imagine how to do that still.

>


My developers asked me how they could indicate that for e.g. a Program and
SharedLibrary builder, some libraries could be linked statically and some
dynamically. gcc/g++ supports this for example:

g++ -Bstatic -lfirst_static_lib -lsecond_static_lib -Bdynamic
-lfirst_shared_lib -l second_shared_lib ...

I came up with the following:

------------------
def split_libs_in_static_and_shared(environment):
# Remove the Program and SharedLibrary registration
import LibProg
del environment['BUILDERS']['Program']
del environment['BUILDERS']['SharedLibrary']

# Now re-initialize the builders to make sure these are no longer
shared with other
# environments. Once we have separate instances, we can further patch
them.
environment.Tool('link')

# And now patch the target_scanner to detect static libraries via
env['STATICLIBS'] & env['SHAREDLIBS']
LibraryProgramScanner = LibProg.LibraryProgramScanner()
environment['BUILDERS']['Program'].target_scanner =
LibraryProgramScanner
environment['BUILDERS']['SharedLibrary'].target_scanner =
LibraryProgramScanner

# Make sure that all the libs expand properly into a static and dynamic
section on the command line
environment['_STATICLIBFLAGS'] = '${_stripixes(LIBLINKPREFIX,
STATICLIBS, LIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}'
environment['_DYNAMICLIBFLAGS'] = '${_stripixes(LIBLINKPREFIX,
SHAREDLIBS, LIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}'
environment['_LIBFLAGS'] = '-Wl,-Bstatic ${_STATICLIBFLAGS}
-Wl,-Bdynamic ${_DYNAMICLIBFLAGS}'

# Return the environment so we can chain several configure calls.
return environment
------------------

In the above snippet you see references to LibProg and functions in it.
LibProg is a patched version of SCons/Scanner/Prog.py where references to
env['LIBS'] are replaced with "env['SHAREDLIBS'] + env['STATICLIBS']". I
have put this patched LibProg.py in my site_scons folder.

Hope the code comments in the snippet are self-explanatory.

Ringo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20121108/e69e503a/attachment.html>


More information about the Scons-users mailing list