I have an existing C library that's built with scons (the library has it's own
SConscript). This code now contains two variations controlled by #ifdef
s. How
do I tell scons to build two variants of this library that can live side by
side (so applications can link against the appropriate variation)?
Conceptually, it's something like this:
driver_sources = [ ... ]
env.Library('drivers', driver_sources)
env.Library('drivers_withflag', driver_sources,
CPPDEFINES += ['FLAG'])
SCons (understandably) doesn't like using the same source list for different outputs with different environments because the intermediate object names conflict.
I'm not sure whether to approach this problem by somehow deriving a new
Builder for dr开发者_JAVA百科ivers_withflag
objects, or whether I should include my library's
SConscript twice with some parameter to specify the #defines
(and I could put
each variant in its own build directory). Any advice?
Here's a link to some relevant documentation: http://www.scons.org/doc/1.1.0/HTML/scons-user/x1392.html
I think it would go something like this
driver_sources = [ ... ]
env.Library('libdrivers', driver_sources)
env_flag = env.Clone()
env_flag.Append(CPPDEFINES = ['FLAG'])
flag_objects = [os.path.splitext(src)[0] + '_flag' +
env['OBJSUFFIX'] for src in driver_sources]
d_wf = [env_flag.Object(tgt, src) for tgt,src in
zip(flag_objects, driver_sources)]
env_flag.Library(d_wf)
This would go directly inside your current SConscript file, however you could also take a look at this question: here
You could use the steps outlined there in whatever file calls your library's SConscript file to setup two environments, then just call the SConscript twice with each one.
Hope that helps.
精彩评论