1 import os.path, glob, site_tools.Yaptu
2 from SCons.Script import *
4 senfutildir = os.path.dirname(__file__)
6 # Fix for SCons 0.97 compatibility
11 BoolVariable = BoolOption
13 def parseLogOption(value):
14 stream, area, level = ( x.strip() for x in value.strip().split('|') )
15 stream = ''.join('(%s)' % x for x in stream.split('::') )
16 if area : area = ''.join( '(%s)' % x for x in area.split('::') )
18 return '((%s,%s,%s))' % (stream,area,level)
20 def expandLogOption(target, source, env, for_signature):
21 if env.get('LOGLEVELS'):
22 return [ 'SENF_LOG_CONF="' + ''.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )+'"']
26 class BuildTypeOptions:
27 def __init__(self, var):
30 def __call__(self, target, source, env, for_signature):
31 type = env['final'] and "final" or env['debug'] and "debug" or "normal"
32 return env[self._var + "_" + type]
34 def parseArguments(env, *defs):
35 vars = Variables(args=ARGUMENTS)
36 for d in defs : vars.Add(d)
39 Any construction environment variable may be set from the scons
40 command line (see SConstruct file and SCons documentation for a list
43 VARNAME=value Assign new value
44 VARNAME+=value Append value at end
46 Special command line parameters:
48 env.Help(vars.GenerateHelpText(env))
49 try : unknv = vars.UnknownVariables()
50 except AttributeError: unknv = vars.UnknownOptions()
51 for k,v in unknv.iteritems():
53 env.Append(**{k[:-1]: v})
58 ###########################################################################
59 # This looks much more complicated than it is: We do three things here:
60 # a) switch between final or debug options
61 # b) parse the LOGLEVELS parameter into the correct SENF_LOG_CONF syntax
62 # c) check for a local SENF, set options accordingly and update that SENF if needed
64 def SetupForSENF(env, senf_path = []):
66 senf_path.extend(('senf', os.path.dirname(senfutildir), '/usr/local', '/usr'))
67 tooldir = os.path.join(senfutildir, 'site_tools')
69 env.Tool('Boost', [ tooldir ])
70 env.Tool('PhonyTarget', [ tooldir ])
71 env.Tool('Yaptu', [ tooldir ])
72 env.Tool('CopyToDir', [ tooldir ])
73 env.Tool('Doxygen', [ tooldir ])
76 LIBS = [ 'senf', 'rt', '$BOOSTREGEXLIB',
77 '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB',
79 BOOSTREGEXLIB = 'boost_regex',
80 BOOSTIOSTREAMSLIB = 'boost_iostreams',
81 BOOSTSIGNALSLIB = 'boost_signals',
82 BOOSTFSLIB = 'boost_filesystem',
84 CXXFLAGS = [ '-Wno-long-long', '$CXXFLAGS_' ],
85 CXXFLAGS_ = BuildTypeOptions('CXXFLAGS'),
87 CPPDEFINES = [ '$expandLogOption', '$CPPDEFINES_' ],
88 expandLogOption = expandLogOption,
89 CPPDEFINES_ = BuildTypeOptions('CPPDEFINES'),
91 LINKFLAGS = [ '-rdynamic', '$LINKFLAGS_' ],
92 LINKFLAGS_ = BuildTypeOptions('LINKFLAGS'),
94 LOGLEVELS = [ '$LOGLEVELS_' ],
95 LOGLEVELS_ = BuildTypeOptions('LOGLEVELS'),
100 CXXFLAGS_normal = [],
103 CPPDEFINES_final = [],
104 CPPDEFINES_normal = [],
105 CPPDEFINES_debug = [],
107 LINKFLAGS_final = [],
108 LINKFLAGS_normal = [],
109 LINKFLAGS_debug = [],
111 LOGLEVELS_final = [],
112 LOGLEVELS_normal = [],
113 LOGLEVELS_debug = [],
115 PROJECTNAME = "Unnamed project",
117 PROJECTEMAIL = "nobody@nowhere.org",
118 COPYRIGHT = "nobody",
119 REVISION = "unknown",
122 # Interpret command line options
125 BoolVariable('final', 'Build final (optimized) build', False),
126 BoolVariable('debug', 'Link in debug symbols', False),
129 # If we have a symbolic link (or directory) 'senf', we use it as our
131 for path in senf_path:
132 if not path.startswith('/') : sconspath = '#/%s' % path
133 else : sconspath = path
134 if os.path.exists(os.path.join(path,"senf/config.hh")):
135 if not env.GetOption('no_progress'):
136 print "\nUsing SENF in '%s'\n" \
137 % ('/..' in sconspath and os.path.abspath(path) or sconspath)
138 env.Append( LIBPATH = [ sconspath ],
139 CPPPATH = [ sconspath ],
140 BUNDLEDIR = sconspath,
142 SENFSYSLAYOUT = False)
144 env.MergeFlags(file(os.path.join(path,"senf.conf")).read())
146 if not env.GetOption('no_progress'):
147 print "(SENF configuration file 'senf.conf' not found, assuming non-final SENF)"
148 env.Append(CPPDEFINES = [ 'SENF_DEBUG' ])
150 elif os.path.exists(os.path.join(path,"include/senf/config.hh")):
151 if not env.GetOption('no_progress'):
152 print "\nUsing system SENF in '%s/'\n" % sconspath
153 env.Append(BUNDLEDIR = os.path.join(sconspath,"lib/senf"),
155 SENFSYSLAYOUT = True)
158 if not env.GetOption('no_progress'):
159 print "\nSENF library not found .. trying build anyway !!\n"
161 env.Alias('all', '#')
164 def DefaultOptions(env):
166 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ],
167 CXXFLAGS_final = [ '-O2' ],
168 CXXFLAGS_normal = [ '-O0', '-g' ],
169 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
171 LINKFLAGS_normal = [ '-Wl,-S' ],
172 LINKFLAGS_debug = [ '-g' ],
175 def Glob(env, exclude=[], subdirs=[]):
176 testSources = env.Glob("*.test.cc", strings=True)
178 for x in env.Glob("*.cc", strings=True)
179 if x not in testSources and x not in exclude ]
180 for subdir in subdirs:
181 testSources += env.Glob(os.path.join(subdir,"*.test.cc"), strings=True)
183 for x in env.Glob(os.path.join(subdir,"*.cc"), strings=True)
184 if x not in testSources and x not in exclude ]
187 return (sources, testSources)
191 def Doxygen(env, doxyheader=None, doxyfooter=None, doxycss=None, mydoxyfile=False, senfdoc_path=[],
193 # Additional interesting keyword arguments or environment variables:
194 # PROJECTNAME, DOCLINKS, PROJECTEMAIL, COPYRIGHT, REVISION
198 libdir=os.path.join(senfutildir, 'lib')
202 senfdoc_path.extend(('senfdoc', '$SENFDIR', '$SENFDIR/manual',
203 '$SENFDIR/share/doc/senf', '$SENFDIR/share/doc/libsenf-doc/html'))
204 for path in senfdoc_path:
205 path = env.Dir(path).get_path()
206 if os.path.exists(os.path.join(path, "doc/doclib.tag")):
210 if senfdocdir is None:
211 if not env.GetOption('no_progress'):
212 print "(SENF documentation not found)"
214 for dir, dirs, files in os.walk(senfdocdir):
215 tagfiles.extend([ os.path.join(dir,f) for f in files if f.endswith('.tag') ])
216 if dir.endswith('/doc') :
217 try: dirs.remove('html')
218 except ValueError: pass
220 if d.startswith('.') : dirs.remove(d)
222 if env.GetOption('clean'):
223 env.Clean('doc', env.Dir('doc'))
225 env.Clean('doc', "Doxyfile")
228 # Create Doxyfile NOW
229 site_tools.Yaptu.yaptuAction("Doxyfile",
230 os.path.join(libdir, "Doxyfile.yap"),
233 envvalues = [ env.Value('$PROJECTNAME'),
234 env.Value('$DOCLINKS'),
235 env.Value('$PROJECTEMAIL'),
236 env.Value('$COPYRIGHT'),
237 env.Value('$REVISION') ]
239 # The other files are created using dependencies
241 doxyheader = env.CopyToDir(env.Dir("doc"), doxyheader)
243 doxyheader = env.Yaptu("doc/doxyheader.html", os.path.join(libdir, "doxyheader.yap"), **kw)
244 env.Depends(doxyheader, envvalues)
246 doxyfooter = env.CopyToDir(env.Dir("doc"), doxyfooter)
248 doxyfooter = env.Yaptu("doc/doxyfooter.html", os.path.join(libdir, "doxyfooter.yap"), **kw)
249 env.Depends(doxyfooter, envvalues)
251 doxycss = env.CopyToDir(env.Dir("doc"), doxycss)
253 doxycss = env.CopyToDir(env.Dir("doc"), os.path.join(libdir, "doxy.css"))
255 doc = env.Doxygen("Doxyfile",
256 DOXYOPTS = [ '--html', '--tagfiles', '"$TAGFILES"' ],
257 DOXYENV = { 'TOPDIR' : env.Dir('#').abspath,
259 'REVISION' : '$REVISION',
260 'tagfiles' : '$TAGFILES',
261 'output_dir' : 'doc',
266 DOXYGENCOM = "$DOCLIBDIR/doxygen.sh $DOXYOPTS $SOURCE")
268 env.Depends(doc, [ doxyheader, doxyfooter, doxycss ])