SCons notes

From OriWiki

Jump to: navigation, search


SCons is a build utility. Its build specification files are python scripts.

scons guide

Python notes can come in handy.

Contents

Simplest example

In MySConstruct.py

Program ('check.cpp')

build command

scons -f MySConstruct.py

Output of scons:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o check.o -c check.cpp
g++ -o check check.o
scons: done building targets.

Simple skeleton

 list = Split('main.c file1.c file2.c')
       Program(source = list, target = 'program')

Building static library

StaticLibrary('foo', ['f1.c', 'f2.c', 'f3.c'])

or

StaticLibrary('foo', ['f1.c', 'f2.o', 'f3.c'])

Building shared library (DLL)

SharedLibrary('foo', ['f1.c', 'f2.c', 'f3.c'])

Linking a library to a program

      Library('foo', ['f1.c', 'f2.c', 'f3.c'])
      Program('prog.c', LIBS=['foo', 'bar'], LIBPATH='.')

or

      Program('prog.c', LIBS = 'm',
                        LIBPATH = ['/usr/lib', '/usr/local/lib'])

Using return scons node

      hello_list = Object('hello.c', CCFLAGS='-DHELLO')
      goodbye_list = Object('goodbye.c', CCFLAGS='-DGOODBYE')
      Program(hello_list + goodbye_list)

Building Environments

env = Environment(CXX = 'g++', CXXFLAGS = '-Wall')

print "env['CC']", env['CC']
print "env['CXX']",env['CXX']

env.Program('check.cpp')

Printing all environment variables

env = Environment()
dict = env.Dictionary()
print dict
env = Environment()
dict = env.Dictionary()
keys = dict.keys()
keys.sort()
for key in keys:
     print key, dict[key] 

Having the same path as in the OS

import os
env = Environment(ENV = {'PATH' : os.environ['PATH']})

Or the whole environment

      import os
      env = Environment(ENV = os.environ)

Passing values in arguments

# 17 is a default value in case yosi parameter is not provided to the program

a = ARGUMENTS.get('yosi',17) 
print a
scons yosi=4

or

scons 

See also [1]

Aliasing

make an alias for a build target:

Program('myf1','f1.cpp')

Alias('myalias','myf1')
scons myf1

Is the same as

scons myalias

clean

scons -c 

Misc

env = Environment()
env1 = env.Clone()
----
print "hello %s, how are you %s ?" % ('Moshe','Doing')

Personal tools