2 from SCons.Script import *
4 def parseLogOption(value):
5 stream, area, level = ( x.strip() for x in value.strip().split('|') )
6 stream = ''.join('(%s)' % x for x in stream.split('::') )
7 if area : area = ''.join( '(%s)' % x for x in area.split('::') )
9 return '((%s,%s,%s))' % (stream,area,level)
11 def expandLogOption(target, source, env, for_signature):
12 if env.get('LOGLEVELS'):
13 return [ 'SENF_LOG_CONF="' + ''.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )+'"']
17 class BuildTypeOptions:
18 def __init__(self, var):
21 def __call__(self, target, source, env, for_signature):
22 type = env['final'] and "final" or env['debug'] and "debug" or "normal"
23 return env[self._var + "_" + type]
25 ###########################################################################
26 # This looks much more complicated than it is: We do three things here:
27 # a) switch between final or debug options
28 # b) parse the LOGLEVELS parameter into the correct SENF_LOG_CONF syntax
29 # c) check for a local SENF, set options accordingly and update that SENF if needed
31 def SetupForSENF(env, senf_paths = []):
32 senf_paths.extend(('senf', '../senf', os.path.dirname(os.path.dirname(__file__)),
33 '/usr/local', '/usr'))
35 LIBS = [ 'senf', 'rt', '$BOOSTREGEXLIB',
36 '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB',
38 BOOSTREGEXLIB = 'boost_regex',
39 BOOSTIOSTREAMSLIB = 'boost_iostreams',
40 BOOSTSIGNALSLIB = 'boost_signals',
41 BOOSTFSLIB = 'boost_filesystem',
43 CXXFLAGS = [ '-Wno-long-long', '$CXXFLAGS_' ],
44 CXXFLAGS_ = BuildTypeOptions('CXXFLAGS'),
46 CPPDEFINES = [ '$expandLogOption', '$CPPDEFINES_' ],
47 expandLogOption = expandLogOption,
48 CPPDEFINES_ = BuildTypeOptions('CPPDEFINES'),
50 LINKFLAGS = [ '-rdynamic', '$LINKFLAGS_' ],
51 LINKFLAGS_ = BuildTypeOptions('LINKFLAGS'),
53 LOGLEVELS = [ '$LOGLEVELS_' ],
54 LOGLEVELS_ = BuildTypeOptions('LOGLEVELS'),
62 CPPDEFINES_final = [],
63 CPPDEFINES_normal = [],
64 CPPDEFINES_debug = [],
67 LINKFLAGS_normal = [],
71 LOGLEVELS_normal = [],
75 # Interpret command line options
76 opts = Variables(ARGUMENTS)
77 opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: <stream>|[<area>]|<level> ...',
78 '${"$LOGLEVELS_"+(final and "final" or "debug")}' )
79 opts.Add( BoolOption('final', 'Build final (optimized) build', False) )
80 opts.Add( BoolOption('debug', 'Link in debug symbols', False) )
82 env.Replace(**dict(opts.UnknownVariables()))
83 env.Help(opts.GenerateHelpText(env))
85 # If we have a symbolic link (or directory) 'senf', we use it as our
87 for path in senf_paths:
88 if not path.startswith('/') : sconspath = '#/%s' % path
89 else : sconspath = path
90 if os.path.exists(os.path.join(path,"senf/config.hh")):
91 print "\nUsing SENF in '%s'\n" \
92 % ('/..' in sconspath and os.path.abspath(path) or sconspath)
93 env.Append( LIBPATH = [ sconspath ],
94 CPPPATH = [ sconspath ],
95 BUNDLEDIR = sconspath )
97 env.MergeFlags(file(os.path.join(path,"senf.conf")).read())
99 print "(SENF configuration file 'senf.conf' not found, assuming non-final SENF)"
100 env.Append(CPPDEFINES = [ 'SENF_DEBUG' ])
102 elif os.path.exists(os.path.join(path,"include/senf/config.hh")):
103 print "\nUsing system SENF in '%s/'\n" % sconspath
104 env.Append(BUNDLEDIR = os.path.join(sconspath,"lib/senf"))
107 print "\nSENF library not found .. trying build anyway !!\n"
110 def DefaultOptions(env):
112 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ],
113 CXXFLAGS_final = [ '-O2' ],
114 CXXFLAGS_normal = [ '-O0', '-g' ],
115 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
117 LINKFLAGS_normal = [ '-Wl,-S' ],