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 def parseArguments(env, *defs):
26 vars = Variables(args=ARGUMENTS)
27 vars.AddVariables(*defs)
30 Any construction environment variable may be set from the scons
31 command line (see SConstruct file and SCons documentation for a list
34 VARNAME=value Assign new value
35 VARNAME+=value Append value at end
37 Special command line parameters:
39 env.Help(vars.GenerateHelpText(env))
40 for k,v in vars.UnknownVariables().iteritems():
42 env.Append(**{k[:-1]: v})
47 ###########################################################################
48 # This looks much more complicated than it is: We do three things here:
49 # a) switch between final or debug options
50 # b) parse the LOGLEVELS parameter into the correct SENF_LOG_CONF syntax
51 # c) check for a local SENF, set options accordingly and update that SENF if needed
53 def SetupForSENF(env, senf_paths = []):
54 senf_paths.extend(('senf', '../senf', os.path.dirname(os.path.dirname(__file__)),
55 '/usr/local', '/usr'))
57 LIBS = [ 'senf', 'rt', '$BOOSTREGEXLIB',
58 '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB',
60 BOOSTREGEXLIB = 'boost_regex',
61 BOOSTIOSTREAMSLIB = 'boost_iostreams',
62 BOOSTSIGNALSLIB = 'boost_signals',
63 BOOSTFSLIB = 'boost_filesystem',
65 CXXFLAGS = [ '-Wno-long-long', '$CXXFLAGS_' ],
66 CXXFLAGS_ = BuildTypeOptions('CXXFLAGS'),
68 CPPDEFINES = [ '$expandLogOption', '$CPPDEFINES_' ],
69 expandLogOption = expandLogOption,
70 CPPDEFINES_ = BuildTypeOptions('CPPDEFINES'),
72 LINKFLAGS = [ '-rdynamic', '$LINKFLAGS_' ],
73 LINKFLAGS_ = BuildTypeOptions('LINKFLAGS'),
75 LOGLEVELS = [ '$LOGLEVELS_' ],
76 LOGLEVELS_ = BuildTypeOptions('LOGLEVELS'),
84 CPPDEFINES_final = [],
85 CPPDEFINES_normal = [],
86 CPPDEFINES_debug = [],
89 LINKFLAGS_normal = [],
93 LOGLEVELS_normal = [],
97 # Interpret command line options
100 BoolVariable('final', 'Build final (optimized) build', False),
101 BoolVariable('debug', 'Link in debug symbols', False),
104 # If we have a symbolic link (or directory) 'senf', we use it as our
106 for path in senf_paths:
107 if not path.startswith('/') : sconspath = '#/%s' % path
108 else : sconspath = path
109 if os.path.exists(os.path.join(path,"senf/config.hh")):
110 print "\nUsing SENF in '%s'\n" \
111 % ('/..' in sconspath and os.path.abspath(path) or sconspath)
112 env.Append( LIBPATH = [ sconspath ],
113 CPPPATH = [ sconspath ],
114 BUNDLEDIR = sconspath )
116 env.MergeFlags(file(os.path.join(path,"senf.conf")).read())
118 print "(SENF configuration file 'senf.conf' not found, assuming non-final SENF)"
119 env.Append(CPPDEFINES = [ 'SENF_DEBUG' ])
121 elif os.path.exists(os.path.join(path,"include/senf/config.hh")):
122 print "\nUsing system SENF in '%s/'\n" % sconspath
123 env.Append(BUNDLEDIR = os.path.join(sconspath,"lib/senf"))
126 print "\nSENF library not found .. trying build anyway !!\n"
129 def DefaultOptions(env):
131 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ],
132 CXXFLAGS_final = [ '-O2' ],
133 CXXFLAGS_normal = [ '-O0', '-g' ],
134 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
136 LINKFLAGS_normal = [ '-Wl,-S' ],
137 LINKFLAGS_debug = [ '-g' ],