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 LINKFLAGS = [ '${"$LINKFLAGS_"+(final and "final" or "debug")}' ],
17 SENF_BUILDOPTS = [ '-j%s' % (env.GetOption('num_jobs') or "1") ],
18 CXXFLAGS_debug = [ '-O0', '-g', '-fno-inline' ],
19 LINKFLAGS_debug = [ '-g', '-rdynamic' ],
22 # Parse LOGLEVELS parameter
23 def parseLogOption(value):
24 stream, area, level = ( x.strip() for x in value.strip().split('|') )
25 stream = ''.join('(%s)' % x for x in stream.split('::') )
26 if area : area = ''.join( '(%s)' % x for x in elts[1].split('::') )
28 return '(( %s,%s,%s ))' % (stream,area,level)
30 def expandLogOption(target, source, env, for_signature):
31 return ' '.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )
33 # Add command-line options: 'LOGLEVELS' and 'final'
35 opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: <stream>|[<area>]|<level> ...',
36 '${"$LOGLEVELS_"+(final and "final" or "debug")}' )
37 opts.Add( BoolOption('final', 'Build final (optimized) build', False) )
40 if env.subst('$LOGLEVELS'):
41 env.Append( expandLogOption=expandLogOption )
42 env.Append( CPPDEFINES = { 'SENF_LOG_CONF': '$expandLogOption' } )
44 env.Help(opts.GenerateHelpText(env))
46 # If we have a symbolic link (or directory) 'senf', we use it as our
48 if os.path.exists('senf'):
49 print "\nUsing SENF in './senf'\n"
50 env.Append( LIBPATH = [ 'senf' ],
51 CPPPATH = [ 'senf/include' ],
52 SENF_BUILDOPTS = [ '${final and "final=1" or None}' ],
53 CPPDEFINES = [ '${not(final) and "SENF_DEBUG" or None}' ] )
57 env.Command('senf/libsenf.a', [], [ 'scons -C %s $SENF_BUILDOPTS libsenf.a' % os.path.realpath('senf')])))
59 print '\nUsing global SENF\n'