[Scons-users] SCon example for common build scenario

Dan Pidcock dan.pidcock at googlemail.com
Mon Jun 16 07:37:58 EDT 2014


Ronex,

On 14 June 2014 16:07, ronex chako <ronex_89 at yahoo.in> wrote:

I know python, Although it is useful, But SCons has some convenient methods
> that are specifically used for build, which I am not actually much aware of.
>

I have a simple test project that I use to try things out with SCons and I
have uploaded a version of it to https://github.com/danio/scons-test. It is
currently an app and a dependent module, rather than your example of 2
modules but hopefully it will give you an idea of how it is possible to do
separate modules with SCons. It does show you how to have debug/release
variants with the libraries build and installed into separate directory
trees so you don't have to rebuild when switching modes (which I think is a
common requirement for build systems). Note however that I'm quite new to
SCons (used on only one project for about 9 months) so I'm sure there are
better ways to do some of the things I have there and maybe other members
of the mailing list will point them out.

 These are points which  are not clear to me:
> The example shared by you are helpful, But I can't understand followings:
>
> 1) Where should I place/create SConstruct and SConscript for my example ?
>     Is it like I need to create SConscript inside src directory of
> module_1 & module_2, SConstrcut for one directory above it ?
>
As with much of SCons, this is very flexible and so it is up to you, but
the downside is that it doesn't give you much support for a particular way
of doing it. I feel that it is good to have all the files for a module
together so I have put the SConscripts into the module's directories.
Andrew's example shows you how to have a SConscript outside of the modules.
In either case, I think you only want one SConstruct so that should be
outside the modules.


>  2) How SConstrcut of module_2 gets called from module_1's make only in
> case if module_2's library is not found ?
> In my example I want to build a library module_1.(a/so) and
> module_2.(a/so).
>  How path of both directories should be used/provided in SConstruct or
> SConscript to build module_2's library if not build before ?
>
> As in makefile it's implemented as like:
>
> module_1.a : path_of_module_2/lib/module2.a
>  ....
> path_of_module_2/lib/module_2.a: (Rule to build module_2.a with some
> explicit path)
>

SCons will manage this for you if you tell it that module2 depends on
module1. With an application you would add modules using the LIB SCons
environment variable.


>  3) If debug build is used, then in case of windows (cl.exe)it uses
> "DEBUG" where as in linux it uses "-g" ?
>     Does it needs to be implemented by some condition, like
>     if os.name == 'posix' :
>        debug_env = env.Clone(CCFLAGS = '-g')
>     else :
>        debug_env = env.Clone(CCFLAGS = 'DEBUG') --- # will it be resoved
> as /D _DEBUG
>      As main intent to use scons is for portability, Do I need to specify
> like this ?
>

You have to manage all this manually yourself. So something like the above,
but you will need all the specific compiler options for Windows.


>  4) How can I add dependcy on header like if a.h is modified then a.cpp
> shoul be compiled ?
>

Again, like 2, SCons will manage this for you. scons --debug=tree is a
really useful option as it will show you all the dependencies it has
managed to figure out. Be aware though this debug mode becomes very large
and slow as soon as you get to a real-sized project.

I am looking for entire solution from the users/experts because I think the
> user guide doesn't have any proper example like this, And going through
> minute details can only be useful or worthy if I need to prefer Scons over
> CMake.Rone
>

I understand your perspective. I found the user guide doesn't have any real
complete examples - just snippets of features so it takes a long time to
build up to something close to a real world project. You also need to read
the whole user guide to understand the concepts before playing around with
anything significant so there is a large time cost to just evaluating
SCons. Hopefully the project I put on github shows you some features that
you may need.

One thing that I didn't appreciate at the beginning of using SCons is that
you really need to understand how to create builders to do anything but the
most trivial of projects. For example, I ended up with shared functions for
the common code to made modules/apps and I think this really should have
been a builder. In the sample app I have put this common code in each
module but obviously this won't scale well so it should really be done as a
builder.

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20140616/47fc380a/attachment-0001.html>


More information about the Scons-users mailing list