[Scons-users] SCon example for common build scenario
Andrew Featherstone
andrew.featherstone at gmail.com
Fri Jun 13 19:03:29 EDT 2014
On 13/06/14 16:49, ronex chako wrote:
> I just started learning scon build tools But could not find any
> example which could describe the basic build scenario as mentioned below:
> || module_1: | module_2
> |_ src|_ src
> |_ a.cpp|_ c.cpp
> |_ b.cpp|_ d.cpp
> |_ include|_ include
> |_ a.h|_ c.h
> |_ b.h|_ d.h
> |_ test
> |_ test_1
> |_ test_2|
> Here |module_1| depends on the library created from |module_2|I want
> to implement SCon makefiles for different *release and debug build*
> which can work for platforms like *Windows and Linux* and implement
> the task as mentioned below:
>
> 1.
> SCon should build sources in release(build/release) and
> debug(build/debug) mode, For debug mode it must use appropriate
> flags depending on the OS.
> 2.
> Running scons inside |module_1| it should first search for
> |libmodule_2.(a/so)| (can be either shared or static library which
> needs to be decide from scon environment variable/flag), if not
> present then build it (How this kind of dependencies cane be
> implied in scons and resolved in an elegant way ?)
> 3.
> If |libmodules_2| is found or in case if not found then after
> building it, it should later build |module_2|.
> 4.
> How can I add regression target in |module_1| to run all the test
> cases ?
> 5.
> Where can I place and implement Sconstruct and SConscript files
> for above scenario.. i.e. Can it be done using some top level
> SConstruct file and SConscript in |module_1| and |module_2| ?
> 6.
> How can I specify the release and debug directories names based on
> the tools used by scons ? i.e if it uses gcc version 4.2 then
> |build_gcc_v_4.2| or |release_gcc_v_4.|.
>
>
> Kindly help me with some examples, or solution for the above
> scenario... Thanks in advance.
> I heartily appreciate any pointers or help.
>
>
> Regards,
> Ronex
>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> http://four.pairlist.net/mailman/listinfo/scons-users
Hi Ronex,
Have you had a chance to look through the user guide
http://www.scons.org/doc/production/HTML/scons-user.html ? A few of
these topics are touched on there. As a starting point, try placing the
following basic SConstruct and SConscript files in the top of your
hierarchy.
# SConstruct
import os
import subprocess
include_dirs = []
for entry in os.listdir('.'):
if os.path.isdir(entry) and (entry != 'build'):
include_dirs.append(Dir(os.path.join('include', entry)))
env = Environment(CC = 'gcc', CPPPATH = include_dirs)
debug_env = env.Clone(CCFLAGS = '-g')
release_env = env.Clone(CCFLAGS = '-O2')
version = subprocess.check_output([ env.subst('$CC'), '-dumpversion'])[:-1]
SConscript('SConscript', variant_dir='build/debug_gcc_v_' + version,
exports={'env' : debug_env}, duplicate=0)
SConscript('SConscript', variant_dir='build/release_gcc_v_' + version,
exports={'env' : release_env}, duplicate=0)
# SConscript
import os
Import('env')
modules = []
for entry in os.listdir('.'):
if os.path.isdir(entry) and (entry != 'build'):
lib = env.StaticLibrary(entry, Glob(entry + '/src/*.c'))
modules.append(lib)
Return('modules')
Here's some example output:
$ scons -Q
scons: building associated VariantDir targets: build/debug_gcc_v_4.8.2
build/release_gcc_v_4.8.2
gcc -o build/release_gcc_v_4.8.2/module_1/src/foo.o -c -O2
-Iinclude/module_1 module_1/src/foo.c
ar rc build/release_gcc_v_4.8.2/libmodule_1.a
build/release_gcc_v_4.8.2/module_1/src/foo.o
ranlib build/release_gcc_v_4.8.2/libmodule_1.a
gcc -o build/debug_gcc_v_4.8.2/module_1/src/foo.o -c -g
-Iinclude/module_1 module_1/src/foo.c
ar rc build/debug_gcc_v_4.8.2/libmodule_1.a
build/debug_gcc_v_4.8.2/module_1/src/foo.o
ranlib build/debug_gcc_v_4.8.2/libmodule_1.a
This isn't a complete solution, but should get you started. It's up to
you really to choose what flags are appropriate for your build variants,
have a look at
http://www.scons.org/doc/production/HTML/scons-user.html#chap-environments
for an explanation of using base construction environments and then
using clones. SCons is intelligent and works out the sort of
dependencies your describing automatically; try using the --tree flag to
find out more
http://www.scons.org/doc/production/HTML/scons-user.html#idm682768. If
your test program is dependent on the library code then it will be
rebuilt automatically.
Running your tests automatically is a bit more involved, and something
others can better describe than me. I'm not sure why you want the
compiler version in your directory names, but as you can see it's using
the fact the SConscript files are just plain python. N.b. though I've
been explicit in setting CC = 'gcc' in the SConstruct file, and used the
expansion of the construction variable to ensure that we're reporting
the name of the actual compiler used in our construction environments.
I've not tried this on Windows, almost certainly there's some
os.path.joins that should be in there instead of some hard-coded forward
slashes.
I hope this helps,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20140614/d78770c5/attachment-0001.html>
More information about the Scons-users
mailing list