Add libboost-signals library to build setup
[senf.git] / senfscons / senfutil.py
1 import os.path
2 from SCons.Script import *
3
4 ###########################################################################
5 # This looks much more complicated than it is: We do three things here:
6 # a) switch between final or debug options
7 # b) parse the LOGLEVELS parameter into the correct SENF_LOG_CONF syntax
8 # c) check for a local SENF, set options accordingly and update that SENF if needed
9
10 def SetupForSENF(env):
11     env.Append( LIBS           = [ 'senf', 'readline', 'rt', '$BOOSTREGEXLIB',
12                                    '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB' ],
13                 BOOSTREGEXLIB  = 'boost_regex',
14                 BOOSTIOSTREAMSLIB = 'boost_iostreams',
15                 BOOSTSIGNALSLIB = 'boost_signals',
16                 CXXFLAGS       = [ '-Wno-long-long',
17                                    '${"$CXXFLAGS_"+(final and "final" or "debug")}',
18                                    '${profile and ("-g","-pg") or None}' ],
19                 LINKFLAGS      = [ '${"$LINKFLAGS_"+(final and "final" or "debug")}',
20                                    '${profile and "-pg" or None}' ],
21                 SENF_BUILDOPTS = [ '-j%s' % (env.GetOption('num_jobs') or "1") ],
22                 CXXFLAGS_debug  = [ '-O0', '-g', '-fno-inline' ],
23                 LINKFLAGS_debug = [ '-g', '-rdynamic' ],
24                 )
25
26     # Parse LOGLEVELS parameter
27     def parseLogOption(value):
28         stream, area, level = ( x.strip() for x in value.strip().split('|') )
29         stream = ''.join('(%s)' % x for x in stream.split('::') )
30         if area : area = ''.join( '(%s)' % x for x in area.split('::') )
31         else    : area = '(_)'
32         return '(( %s,%s,%s ))' % (stream,area,level)
33
34     def expandLogOption(target, source, env, for_signature):
35         return ' '.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )
36
37     # Add command-line options: 'LOGLEVELS' and 'final'
38     opts = Options()
39     opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: <stream>|[<area>]|<level> ...',
40               '${"$LOGLEVELS_"+(final and "final" or "debug")}' )
41     opts.Add( BoolOption('final', 'Build final (optimized) build', False) )
42     opts.Add( BoolOption('debug', 'Link in debug symbols', False) )
43     opts.Add( BoolOption('profile', 'Add profile information', False) )
44     opts.Update(env)
45
46     if env.subst('$LOGLEVELS'):
47         env.Append( expandLogOption=expandLogOption )
48         env.Append( CPPDEFINES = { 'SENF_LOG_CONF': '$expandLogOption' } )
49
50     env.Help(opts.GenerateHelpText(env))
51
52     # If we have a symbolic link (or directory) 'senf', we use it as our
53     # senf repository
54     if os.path.exists('senf'):
55         print "\nUsing SENF in './senf'\n"
56         env.Append( LIBPATH = [ 'senf' ],
57                     CPPPATH = [ 'senf/include' ],
58                     SENF_BUILDOPTS = [ '${final and "final=1" or None}',
59                                        '${debug and "debug=1" or None}',
60                                        '${profile and "profile=1" or None}' ],
61                     CPPDEFINES = [ '${not(final) and "SENF_DEBUG" or None}' ] )
62
63         env.Default(
64             env.AlwaysBuild(
65                 env.Command('senf/libsenf.a', [],  [ 'scons -C %s $SENF_BUILDOPTS libsenf.a' % os.path.realpath('senf')])))
66     else:
67         print '\nUsing global SENF\n'