2 from SCons.Script import *
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
10 def SetupForSENF(env):
11 env.Append( LIBS = [ 'senf', 'readline', 'rt', '$BOOSTREGEXLIB', '$BOOSTIOSTREAMSLIB' ],
12 BOOSTREGEXLIB = 'boost_regex',
13 BOOSTIOSTREAMSLIB = 'boost_iostreams',
14 CXXFLAGS = [ '-Wno-long-long',
15 '${"$CXXFLAGS_"+(final and "final" or "debug")}',
16 '${profile and ("-g","-pg") or None}' ],
17 LINKFLAGS = [ '${"$LINKFLAGS_"+(final and "final" or "debug")}',
18 '${profile and "-pg" or None}' ],
19 SENF_BUILDOPTS = [ '-j%s' % (env.GetOption('num_jobs') or "1") ],
20 CXXFLAGS_debug = [ '-O0', '-g', '-fno-inline' ],
21 LINKFLAGS_debug = [ '-g', '-rdynamic' ],
24 # Parse LOGLEVELS parameter
25 def parseLogOption(value):
26 stream, area, level = ( x.strip() for x in value.strip().split('|') )
27 stream = ''.join('(%s)' % x for x in stream.split('::') )
28 if area : area = ''.join( '(%s)' % x for x in area.split('::') )
30 return '(( %s,%s,%s ))' % (stream,area,level)
32 def expandLogOption(target, source, env, for_signature):
33 return ' '.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )
35 # Add command-line options: 'LOGLEVELS' and 'final'
37 opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: <stream>|[<area>]|<level> ...',
38 '${"$LOGLEVELS_"+(final and "final" or "debug")}' )
39 opts.Add( BoolOption('final', 'Build final (optimized) build', False) )
40 opts.Add( BoolOption('debug', 'Link in debug symbols', False) )
41 opts.Add( BoolOption('profile', 'Add profile information', False) )
44 if env.subst('$LOGLEVELS'):
45 env.Append( expandLogOption=expandLogOption )
46 env.Append( CPPDEFINES = { 'SENF_LOG_CONF': '$expandLogOption' } )
48 env.Help(opts.GenerateHelpText(env))
50 # If we have a symbolic link (or directory) 'senf', we use it as our
52 if os.path.exists('senf'):
53 print "\nUsing SENF in './senf'\n"
54 env.Append( LIBPATH = [ 'senf' ],
55 CPPPATH = [ 'senf/include' ],
56 SENF_BUILDOPTS = [ '${final and "final=1" or None}',
57 '${debug and "debug=1" or None}',
58 '${profile and "profile=1" or None}' ],
59 CPPDEFINES = [ '${not(final) and "SENF_DEBUG" or None}' ] )
63 env.Command('senf/libsenf.a', [], [ 'scons -C %s $SENF_BUILDOPTS libsenf.a' % os.path.realpath('senf')])))
65 print '\nUsing global SENF\n'