[Scons-users] SCon example for common build scenario

Andrew Featherstone andrew.featherstone at gmail.com
Sun Jun 15 18:16:01 EDT 2014


Ronex,

1) I've attached my example layout, but in case attachments aren't 
permitted, here's the directory structure.

$ ls -R
.:
module_1  SConscript  SConstruct
./module_1:
include  src
./module_1/include:
foo.h
./module_1/src:
foo.c

An excellent way to find out these lovely functions exposed to your 
SCons* files is to read the user guide ;-). Seriously, your questions 
can easily be answered by reading the guide.

2) You're worrying a lot about how to make SCons aware of your build 
dependencies, but SCons takes care of the hard work for you. Relax, read 
the user guide's section on build dependencies 
http://www.scons.org/doc/2.3.1/HTML/scons-user.html#chap-depends ? 
There's even a lovely worked example of implicit dependencies 
http://www.scons.org/doc/2.3.1/HTML/scons-user.html#idm996432. Answering 
my previous questions about what sections mentioned by William you have 
read, etc, would also help you a lot, and it would be courteous too.
3) Your question about generating debugging information in your 
libraries suggests you're not that familiar with the compiler flags used 
by cl.exe or gcc. This is not the right place for these sorts of 
discussions, but for cl.exe you'll want a /Z[7|d|i|I] build flag. If you 
read the user guide you'll even be able to see what's in SCons' default 
construction environment 
http://www.scons.org/doc/2.3.1/HTML/scons-user.html#idm23430168, and 
decide if the default option is right for you.
4) Once you've read the sections I've highlighted above this should be 
obvious.

Your last comment doesn't make much sense to me. You're not being asked 
to go through anything in "minute detail" or delve into SCons' inner 
workings, simply to tell us what parts of the documentation you have 
read. I'm sure that if some bits really are too opaque then we can 
collectively contribute back to the project.

Andrew

On 14/06/14 16:07, ronex chako wrote:
> Hello Andrew,
>
> Thanks once agian for your reply.
>
> 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.
>
> 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 ?
> 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)
>
> 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 ?
> 4) How can I add dependcy on header like if a.h is modified then a.cpp 
> shoul be compiled ?
>
> 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.
>
>
> On Saturday, 14 June 2014 7:54 PM, Andrew Featherstone 
> <andrew.featherstone at gmail.com> wrote:
>
>
> On 14/06/14 13:49, ronex chako wrote:
>> Hello Andrew & William,
>>
>> Thanks for sharing the example and all the suggestion/pointers on my 
>> queries.
>> I am comparing build approach between two build-tools (SCons and 
>> CMake). For this I am trying few examples and for CMake I have 
>> already implemented the same scenario.
>>
>> Due to some limited amount of time on hand, I could not devote 
>> required amount of time in understanding and reading SCons user guide 
>> and directly started with the example, As SCons implements looks more 
>> like a python script.
>>
>> Your suggestion will definietly help me in implementing the scenario 
>> I mentioned. I'd would be very greatful if either of you or 
>> scons-users help me with the entire example in elegant way.. As 
>> initially it's be difficult for me and possibility brings a chances 
>> of mistakes/errors.
>>
>> If possible, Please Kindly help with elegant and entire solution for 
>> my problem,  I am sure this is very general scenario and must have 
>> been implemented by someone before.
>>
>>
>> On Saturday, 14 June 2014 4:52 AM, Andrew Featherstone 
>> <andrew.featherstone at gmail.com> 
>> <mailto:andrew.featherstone at gmail.com> wrote:
>>
>>
>> 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  <mailto:Scons-users at scons.org>
>>> http://four.pairlist.net/mailman/listinfo/scons-users
>> Oops, here's a change to my earlier reply
>> - include_dirs.append(Dir(os.path.join('include', entry)))
>> + include_dirs.append(Dir(os.path.join(entry, 'include')))
>>
>> New 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 
>> -Imodule_1/include module_1/src/foo.c
>> gcc -o build/debug_gcc_v_4.8.2/module_1/src/foo.o -c -g 
>> -Imodule_1/include 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
>>
>> and for completeness
>> $ ls module_1/*/
>> module_1/include/:
>> foo.h
>>
>> module_1/src/:
>> foo.c
>>
>> $ cat module_1/src/foo.c
>> #include <foo.h>
>>
>> int foo_bar(void)
>> {
>>     int a = 1;
>>     return a;
>> }
>>
>> Andrew
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org <mailto:Scons-users at scons.org>
>> http://four.pairlist.net/mailman/listinfo/scons-users
>>
>>
>>
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org  <mailto:Scons-users at scons.org>
>> http://four.pairlist.net/mailman/listinfo/scons-users
> Hi Ronex,
>
> I'm not quite sure I understand what you're looking for. You've 
> mentioned that you want to compare CMake and SCons and already have 
> examples for the former, but you also don't have time to read the 
> SCons literature (which really is very comprehensive and full of 
> concise working examples). SCons* files _are_ python scripts; that's 
> absolutely key (and great) 
> http://www.scons.org/doc/2.3.1/HTML/scons-user.html#idp58648.
>
> It's hard for people to help when the problem isn't tightly defined. 
> Are you trying to say that you don't know python? If so, I wouldn't 
> worry about that. Have you read the sections kindly highlight by 
> William? Which parts of the documentation were confusing? Have you run 
> my example files? Did you get a result you didn't expect? If so, 
> what's missing/incomplete/incorrect? Perhaps you can describe the 
> output of your CMake based build system and how it differs from what 
> this SCons based example provides.
>
> Regards,
> Andrew
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org <mailto:Scons-users at scons.org>
> http://four.pairlist.net/mailman/listinfo/scons-users
>
>
>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> http://four.pairlist.net/mailman/listinfo/scons-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20140615/9da17e35/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.tar.gz
Type: application/gzip
Size: 794 bytes
Desc: not available
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20140615/9da17e35/attachment-0001.bin>


More information about the Scons-users mailing list