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', 'iberty', 'boost_regex', 'boost_iostreams' ],
12 CXXFLAGS = [ '-Wno-long-long',
13 '${"$CXXFLAGS_"+(final and "final" or "debug")}' ],
14 LINKFLAGS = [ '${"$LINKFLAGS_"+(final and "final" or "debug")}' ],
15 SENF_BUILDOPTS = [ '-j%s' % (env.GetOption('num_jobs') or "1") ],
16 CXXFLAGS_debug = [ '-O0', '-g', '-fno-inline' ],
17 LINKFLAGS_debug = [ '-g', '-rdynamic' ],
20 # Parse LOGLEVELS parameter
21 def parseLogOption(value):
22 stream, area, level = ( x.strip() for x in value.strip().split('|') )
23 stream = ''.join('(%s)' % x for x in stream.split('::') )
24 if area : area = ''.join( '(%s)' % x for x in elts[1].split('::') )
26 return '(( %s,%s,%s ))' % (stream,area,level)
28 def expandLogOption(target, source, env, for_signature):
29 return ' '.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )
31 # Add command-line options: 'LOGLEVELS' and 'final'
33 opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: <stream>|[<area>]|<level> ...',
34 '${"$LOGLEVELS_"+(final and "final" or "debug")}' )
35 opts.Add( BoolOption('final', 'Build final (optimized) build', False) )
38 print env.subst('$LOGLEVELS')
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 senf $SENF_BUILDOPTS libsenf.a' ])))
59 print '\nUsing global SENF\n'