[Scons-users] Building SDL 2 with SCons on Linux

Dirk Bächle tshortik at gmx.de
Thu Mar 13 14:02:02 EDT 2014


Hi Davide,

On 13.03.2014 16:00, Davide Coppola wrote:

> I wrote a tutorial about how to build SDL2 as a static library on

> Linux using SCons:

> http://blog.davidecoppola.com/2014/03/13/building-sdl-2-with-scons-on-linux/

>

>


thanks a lot for publishing your scripts. I really like the style of
your writing, the article reads nicely.


> Please check it out and let me know if you have any comment or

> suggestion for improving the scripts.

>


I have indeed a few comments, especially regarding your usage of the
variant_dir feature.

1.) If your projects get bigger and you would perhaps like to create
several (all?) variants with *one* call of SCons, here's what you could
change: Create another SConscript, right beside your top-level
SConstruct. It only contains the includes to the lower directories, so:

Import('env')
SConscript('src/libs/SDL2/SConscript', exports = 'env', variant_dir =
'build/' + env['mode'], src_dir = 'src', duplicate = 0)
SConscript('src/game/SConscript', exports = 'env', variant_dir =
'build/' + env['mode'], src_dir = 'src', duplicate = 0)

Then, set up single environments for the variants you'd like to create
in your SConstruct:

env = Environment(variables = vars)
debugEnv = env.Clone()
debugEnv.Append(CCFLAGS = ['-Wall', '-g', '-O0', '-DDEBUG'])
debugEnv['mode'] = 'debug'

...
profileEnv = env.Clone()
profileEnv.Append(CCFLAGS = ['-Wall', '-pg', '-O0', '-DNDEBUG'])
profileEnv['mode'] = 'profile'

Now, you can do things like

mode_env = {'debug' : debugEnv,
'release' : releaseEnv,
'profile' : profileEnv}
for m in mode_env:
SConscript('SConscript', exports={'env' : mode_env[m]})

and get all variants at once.

2.) As another minor point, in the SConscripts you create localEnvs via
Clone(). This is okay, but when you then call localEnv.Program() (or any
other builder that is defined within the localEnv environment) and
additionally give parameters like LIBPATH to this call, this means that
internally another Environment (a so called OverrideEnvironment) gets
created.
Doesn't really hurt, but it's actually unnecessary. You don't use the
localEnv for anything else, so just set it up completely like for the
other variables:

localEnv.Append(CPPPATH=['#/src/libs/SDL2/include'])
localEnv.Append(CCFLAGS = ['-D_REENTRANT'])
localEnv.Append(LINKFLAGS=['-Wl,--no-undefined'])
localEnv.Append(LIBS=['SDL2', 'pthread', 'm', 'dl', 'ts', 'pthread',
'rt'])
localEnv.Append(LIBPATH=['../libs/SDL2'])

Finally, feel free to add your project as snippet to our Wiki, under the
"Recipes" section ( http://www.scons.org/wiki/SconsRecipes ) . We can
always use more good examples like this one.

Best regards,

Dirk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://four.pairlist.net/pipermail/scons-users/attachments/20140313/4dc170d9/attachment.html


More information about the Scons-users mailing list