1 import os, os.path, site_tools.Yaptu, types, re, fnmatch
2 from SCons.Script import *
4 senfutildir = os.path.dirname(__file__)
6 # Fix for SCons 0.97 compatibility
11 BoolVariable = BoolOption
13 ###########################################################################
17 tooldir = os.path.join(senfutildir, 'site_tools')
18 for tool in os.listdir(tooldir):
19 name, ext = os.path.splitext(tool)
20 if ext == '.py' and name != "__init__" : env.Tool(name, [ tooldir ])
22 def parseArguments(env, *defs):
23 vars = Variables(args=ARGUMENTS)
24 for d in defs : vars.Add(d)
27 Any construction environment variable may be set from the scons
28 command line (see SConstruct file and SCons documentation for a list
31 VARNAME=value Assign new value
32 VARNAME+=value Append value at end
34 Special command line parameters:
36 env.Help(vars.GenerateHelpText(env))
37 try : unknv = vars.UnknownVariables()
38 except AttributeError: unknv = vars.UnknownOptions()
39 env.SetDefault(ARGUMENT_VARIABLES = {})
40 for k,v in unknv.iteritems():
42 env.Append(**{k[:-1]: v})
43 env.Append(ARGUMENT_VARIABLES = {k[:-1]:v})
46 env.Append(ARGUMENT_VARIABLES = {k:v})
48 def importProcessEnv(env):
49 env.Append( ENV = dict(( (k,v)
50 for pattern in env.get('IMPORT_ENV',[])
51 for k,v in os.environ.iteritems()
52 if fnmatch.fnmatchcase(k,pattern) )) )
55 ###########################################################################$
56 # SENF log option parsing
58 def parseLogOption(value):
59 stream, area, level = ( x.strip() for x in value.strip().split('|') )
60 stream = ''.join('(%s)' % x for x in stream.split('::') )
61 if area : area = ''.join( '(%s)' % x for x in area.split('::') )
63 return '((%s,%s,%s))' % (stream,area,level)
65 def expandLogOption(target, source, env, for_signature):
66 if env.subst('$LOGLEVELS'):
67 return [ 'SENF_LOG_CONF="' + ''.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )+'"']
71 ###########################################################################
72 # client SENF detection/configuration
74 def detect_senf(env,senf_path, try_flavors):
75 """Detect senf with flavor in 'try_flavors' somewhere in 'senf_path'.
77 This function returns True, if senf is found, False otherwise.
78 The environment 'env' is updated in the following way:
80 SENFSYSLAYOUT set to True, if the install is a system installation,
83 FLAVOR set to the detected senf flavor
85 SENFDIR set to the base directory of the senf installation.
88 senf_path.extend((os.path.dirname(senfutildir), '/usr/local', '/usr'))
90 for path in senf_path:
91 if not path.startswith('/') : sconspath = '#/%s' % path
92 else : sconspath = path
93 for flavor in try_flavors:
94 suffix = flavor and "_"+flavor or ""
95 local_path = os.path.join(path,"senf%s.conf" % suffix)
96 sys_path = os.path.join(path, "lib", "senf", "senf%s.conf" % suffix)
97 if os.path.exists(local_path):
98 env.SetDefault( SENFSYSLAYOUT = False )
99 elif os.path.exists(sys_path):
100 env.SetDefault( SENFSYSLAYOUT = True )
103 env.SetDefault( FLAVOR = flavor, SENFDIR = sconspath )
107 def SetupForSENF(env, senf_path = [], flavor=None):
108 try_flavors = [ '', 'g' ]
109 if flavor is not None:
110 try_flavors[0:0] = [ flavor ]
112 res = detect_senf(env, senf_path, try_flavors)
114 if not env.GetOption('no_progress'):
115 print env.subst("scons: Using${SENFSYSLAYOUT and ' system' or ''} "
116 "'libsenf${LIBADDSUFFIX}' in '$SENFDIR'")
118 print "scons: SENF library not found, trying to build anyway ..."
122 # For a non-system installed senf, we add library and include search path here
123 if not env.get('SENFSYSLAYOUT', True):
125 CPPPATH = [ '$SENFINCDIR' ],
126 LIBPATH = [ '$SENFDIR' ],
129 if env['BOOST_VARIANT'] is None:
130 conf = env.Configure(clean=False, help=False)
131 conf.CheckBoostVersion(fail=True)
132 conf.CheckBoostVariants()
136 expandLogOption = expandLogOption,
139 LIBADDSUFFIX = '${FLAVOR and "_$FLAVOR" or ""}',
140 OBJADDSUFFIX = '${LIBADDSUFFIX}',
141 BUNDLEDIR = '$SENFDIR${SENFSYSLAYOUT and "/lib/senf" or ""}',
142 SENFINCDIR = '$SENFDIR${SENFSYSLAYOUT and "/include" or ""}',
144 PROJECTNAME = "Unnamed project",
146 PROJECTEMAIL = "nobody@nowhere.org",
147 COPYRIGHT = "nobody",
148 REVISION = "unknown",
151 CPPDEFINES = [ '$expandLogOption' ],
152 CXXFLAGS = [ '-Wno-long-long', '-fno-strict-aliasing' ],
153 LINKFLAGS = [ '-rdynamic' ],
154 LIBS = [ 'senf$LIBADDSUFFIX', 'rt', '$BOOSTREGEXLIB', '$BOOSTIOSTREAMSLIB',
155 '$BOOSTSIGNALSLIB', '$BOOSTFSLIB' ],
159 path = env.File('$BUNDLEDIR/senf${LIBADDSUFFIX}.conf').abspath
160 env.MergeFlags(file(path).read())
162 # Really should never happen since detect_senf looks for this file ...
165 ###########################################################################
168 def DefaultOptions(env):
170 expandLogOption = expandLogOption,
171 CXXFLAGS_ = env.BuildTypeOptions('CXXFLAGS'),
172 CPPDEFINES_ = env.BuildTypeOptions('CPPDEFINES'),
173 LINKFLAGS_ = env.BuildTypeOptions('LINKFLAGS'),
174 LOGLEVELS_ = env.BuildTypeOptions('LOGLEVELS'),
177 CXXFLAGS = [ '$CXXFLAGS_' ],
178 CPPDEFINES = [ '$CPPDEFINES_' ],
179 LINKFLAGS = [ '$LINKFLAGS_' ],
180 LOGLEVELS = [ '$LOGLEVELS_' ],
184 CXXFLAGS_normal = [],
187 CPPDEFINES_final = [],
188 CPPDEFINES_normal = [],
189 CPPDEFINES_debug = [],
191 LINKFLAGS_final = [],
192 LINKFLAGS_normal = [],
193 LINKFLAGS_debug = [],
195 LOGLEVELS_final = [],
196 LOGLEVELS_normal = [],
197 LOGLEVELS_debug = [],
200 # Interpret command line options
203 BoolVariable('final', 'Build final (optimized) build', False),
204 BoolVariable('debug', 'Link in debug symbols', False),
207 # Set nice default options
209 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ],
210 CXXFLAGS_final = [ '-O3' ],
211 CXXFLAGS_normal = [ '-O2', '-g' ],
212 CXXFLAGS_debug = [ '-O0', '-g' ],
214 LINKFLAGS_normal = [ '-Wl,-S' ],
215 LINKFLAGS_debug = [ '-g' ],
218 env.Alias('all', '#')
221 def Glob(env, exclude=[], subdirs=[]):
222 testSources = env.Glob("*.test.cc", strings=True)
224 for x in env.Glob("*.cc", strings=True)
225 if x not in testSources and x not in exclude ]
226 for subdir in subdirs:
227 testSources += env.Glob(os.path.join(subdir,"*.test.cc"), strings=True)
229 for x in env.Glob(os.path.join(subdir,"*.cc"), strings=True)
230 if x not in testSources and x not in exclude ]
233 return (sources, testSources)
237 def Doxygen(env, doxyheader=None, doxyfooter=None, doxycss=None, mydoxyfile=False, senfdoc_path=[],
239 # Additional interesting keyword arguments or environment variables:
240 # PROJECTNAME, DOCLINKS, PROJECTEMAIL, COPYRIGHT, REVISION
244 libdir=os.path.join(senfutildir, 'lib')
248 senfdoc_path.extend(('senfdoc', '$SENFDIR', '$SENFDIR/manual',
249 '$SENFDIR/share/doc/senf', '$SENFDIR/share/doc/libsenf-doc/html'))
250 for path in senfdoc_path:
251 path = env.Dir(path).get_path()
252 if os.path.exists(os.path.join(path, "doc/doclib.tag")):
256 if senfdocdir is None:
257 if not env.GetOption('no_progress'):
258 print "(SENF documentation not found)"
260 for dir, dirs, files in os.walk(senfdocdir):
261 tagfiles.extend([ os.path.join(dir,f) for f in files if f.endswith('.tag') ])
262 if dir.endswith('/doc') :
263 try: dirs.remove('html')
264 except ValueError: pass
266 if d.startswith('.') : dirs.remove(d)
268 if env.GetOption('clean'):
269 env.Clean('doc', env.Dir('doc'))
271 env.Clean('doc', "Doxyfile")
274 # Create Doxyfile NOW
275 site_tools.Yaptu.yaptuAction("Doxyfile",
276 os.path.join(libdir, "Doxyfile.yap"),
279 envvalues = [ env.Value('$PROJECTNAME'),
280 env.Value('$DOCLINKS'),
281 env.Value('$PROJECTEMAIL'),
282 env.Value('$COPYRIGHT'),
283 env.Value('$REVISION') ]
285 # The other files are created using dependencies
287 doxyheader = env.CopyToDir(env.Dir("doc"), doxyheader)
289 doxyheader = env.Yaptu("doc/doxyheader.html", os.path.join(libdir, "doxyheader.yap"), **kw)
290 env.Depends(doxyheader, envvalues)
292 doxyfooter = env.CopyToDir(env.Dir("doc"), doxyfooter)
294 doxyfooter = env.Yaptu("doc/doxyfooter.html", os.path.join(libdir, "doxyfooter.yap"), **kw)
295 env.Depends(doxyfooter, envvalues)
297 doxycss = env.CopyToDir(env.Dir("doc"), doxycss)
299 doxycss = env.CopyToDir(env.Dir("doc"), os.path.join(libdir, "doxy.css"))
301 doc = env.Doxygen("Doxyfile",
302 DOXYOPTS = [ '--html', '--tagfiles', '"$TAGFILES"' ],
303 DOXYENV = { 'TOPDIR' : env.Dir('#').abspath,
305 'REVISION' : '$REVISION',
306 'tagfiles' : '$TAGFILES',
307 'output_dir' : 'doc',
310 'DOXYGEN' : '$DOXYGEN' },
313 DOXYGENCOM = "$DOCLIBDIR/doxygen.sh $DOXYOPTS $SOURCE")
315 env.Depends(doc, [ doxyheader, doxyfooter, doxycss ])