1 import os.path, glob, site_tools.Yaptu
2 from SCons.Script import *
5 senfutildir = os.path.dirname(__file__)
7 # Fix for SCons 0.97 compatibility
12 BoolVariable = BoolOption
14 def parseLogOption(value):
15 stream, area, level = ( x.strip() for x in value.strip().split('|') )
16 stream = ''.join('(%s)' % x for x in stream.split('::') )
17 if area : area = ''.join( '(%s)' % x for x in area.split('::') )
19 return '((%s,%s,%s))' % (stream,area,level)
21 def expandLogOption(target, source, env, for_signature):
22 if env.get('LOGLEVELS'):
23 return [ 'SENF_LOG_CONF="' + ''.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )+'"']
27 class BuildTypeOptions:
28 def __init__(self, var):
31 def __call__(self, target, source, env, for_signature):
32 type = env['final'] and "final" or env['debug'] and "debug" or "normal"
33 return env[self._var + "_" + type]
37 tooldir = os.path.join(senfutildir, 'site_tools')
38 for tool in os.listdir(tooldir):
39 name, ext = os.path.splitext(tool)
40 if ext == '.py' and name != "__init__" : env.Tool(name, [ tooldir ])
42 def parseArguments(env, *defs):
43 vars = Variables(args=ARGUMENTS)
44 for d in defs : vars.Add(d)
47 Any construction environment variable may be set from the scons
48 command line (see SConstruct file and SCons documentation for a list
51 VARNAME=value Assign new value
52 VARNAME+=value Append value at end
54 Special command line parameters:
56 env.Help(vars.GenerateHelpText(env))
57 try : unknv = vars.UnknownVariables()
58 except AttributeError: unknv = vars.UnknownOptions()
59 for k,v in unknv.iteritems():
61 env.Append(**{k[:-1]: v})
66 ###########################################################################
67 # This looks much more complicated than it is: We do three things here:
68 # a) switch between final or debug options
69 # b) parse the LOGLEVELS parameter into the correct SENF_LOG_CONF syntax
70 # c) check for a local SENF, set options accordingly
71 # d) check, wether the boost extensions are needed
73 def SetupForSENF(env, senf_path = []):
75 senf_path.extend(('senf', os.path.dirname(senfutildir), '/usr/local', '/usr'))
82 CXXFLAGS = [ '-Wno-long-long', '$CXXFLAGS_' ],
83 CXXFLAGS_ = BuildTypeOptions('CXXFLAGS'),
85 CPPDEFINES = [ '$expandLogOption', '$CPPDEFINES_' ],
86 expandLogOption = expandLogOption,
87 CPPDEFINES_ = BuildTypeOptions('CPPDEFINES'),
89 LINKFLAGS = [ '-rdynamic', '$LINKFLAGS_' ],
90 LINKFLAGS_ = BuildTypeOptions('LINKFLAGS'),
92 LOGLEVELS = [ '$LOGLEVELS_' ],
93 LOGLEVELS_ = BuildTypeOptions('LOGLEVELS'),
101 CPPDEFINES_final = [],
102 CPPDEFINES_normal = [],
103 CPPDEFINES_debug = [],
105 LINKFLAGS_final = [],
106 LINKFLAGS_normal = [],
107 LINKFLAGS_debug = [],
109 LOGLEVELS_final = [],
110 LOGLEVELS_normal = [],
111 LOGLEVELS_debug = [],
113 PROJECTNAME = "Unnamed project",
115 PROJECTEMAIL = "nobody@nowhere.org",
116 COPYRIGHT = "nobody",
117 REVISION = "unknown",
120 # Interpret command line options
123 BoolVariable('final', 'Build final (optimized) build', False),
124 BoolVariable('debug', 'Link in debug symbols', False),
127 # If we have a symbolic link (or directory) 'senf', we use it as our
129 for path in senf_path:
130 if not path.startswith('/') : sconspath = '#/%s' % path
131 else : sconspath = path
132 if os.path.exists(os.path.join(path,"senf/config.hh")):
133 if not env.GetOption('no_progress'):
134 print "\nUsing SENF in '%s'\n" \
135 % ('/..' in sconspath and os.path.abspath(path) or sconspath)
136 env.Append( LIBPATH = [ sconspath ],
137 CPPPATH = [ sconspath ],
138 BUNDLEDIR = sconspath,
140 SENFSYSLAYOUT = False)
142 env.MergeFlags(file(os.path.join(path,"senf.conf")).read())
144 if not env.GetOption('no_progress'):
145 print "(SENF configuration file 'senf.conf' not found, assuming non-final SENF)"
146 env.Append(CPPDEFINES = [ 'SENF_DEBUG' ])
148 elif os.path.exists(os.path.join(path,"include/senf/config.hh")):
149 if not env.GetOption('no_progress'):
150 print "\nUsing system SENF in '%s/'\n" % sconspath
151 env.Append(BUNDLEDIR = os.path.join(sconspath,"lib/senf"),
153 SENFSYSLAYOUT = True)
156 if not env.GetOption('no_progress'):
157 print "\nSENF library not found .. trying build anyway !!\n"
161 # Only add senf after all configure checks have run
163 CPPPATH = '${NEED_BOOST_EXT and "$SENFDIR/boost_ext" or None}',
164 LIBS = [ 'senf', '$BOOSTREGEXLIB', '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB',
168 env.Alias('all', '#')
171 def DefaultOptions(env):
173 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ],
174 CXXFLAGS_final = [ '-O3' ],
175 CXXFLAGS_normal = [ '-O2', '-g' ],
176 CXXFLAGS_debug = [ '-O0', '-g' ],
178 LINKFLAGS_normal = [ '-Wl,-S' ],
179 LINKFLAGS_debug = [ '-g' ],
183 def Glob(env, exclude=[], subdirs=[]):
184 testSources = env.Glob("*.test.cc", strings=True)
186 for x in env.Glob("*.cc", strings=True)
187 if x not in testSources and x not in exclude ]
188 for subdir in subdirs:
189 testSources += env.Glob(os.path.join(subdir,"*.test.cc"), strings=True)
191 for x in env.Glob(os.path.join(subdir,"*.cc"), strings=True)
192 if x not in testSources and x not in exclude ]
195 return (sources, testSources)
199 conf = env.Configure(clean=False, help=False, custom_tests = senfconf.Tests())
201 BOOST_VERSION = conf.CheckBoostVersion(),
202 BOOST_VARIANT = conf.CheckBoostVariants( '', 'mt' ),
203 NEED_BOOST_EXT = not conf.CheckCXXHeader("boost/bimap.hpp"),
210 def Doxygen(env, doxyheader=None, doxyfooter=None, doxycss=None, mydoxyfile=False, senfdoc_path=[],
212 # Additional interesting keyword arguments or environment variables:
213 # PROJECTNAME, DOCLINKS, PROJECTEMAIL, COPYRIGHT, REVISION
217 libdir=os.path.join(senfutildir, 'lib')
221 senfdoc_path.extend(('senfdoc', '$SENFDIR', '$SENFDIR/manual',
222 '$SENFDIR/share/doc/senf', '$SENFDIR/share/doc/libsenf-doc/html'))
223 for path in senfdoc_path:
224 path = env.Dir(path).get_path()
225 if os.path.exists(os.path.join(path, "doc/doclib.tag")):
229 if senfdocdir is None:
230 if not env.GetOption('no_progress'):
231 print "(SENF documentation not found)"
233 for dir, dirs, files in os.walk(senfdocdir):
234 tagfiles.extend([ os.path.join(dir,f) for f in files if f.endswith('.tag') ])
235 if dir.endswith('/doc') :
236 try: dirs.remove('html')
237 except ValueError: pass
239 if d.startswith('.') : dirs.remove(d)
241 if env.GetOption('clean'):
242 env.Clean('doc', env.Dir('doc'))
244 env.Clean('doc', "Doxyfile")
247 # Create Doxyfile NOW
248 site_tools.Yaptu.yaptuAction("Doxyfile",
249 os.path.join(libdir, "Doxyfile.yap"),
252 envvalues = [ env.Value('$PROJECTNAME'),
253 env.Value('$DOCLINKS'),
254 env.Value('$PROJECTEMAIL'),
255 env.Value('$COPYRIGHT'),
256 env.Value('$REVISION') ]
258 # The other files are created using dependencies
260 doxyheader = env.CopyToDir(env.Dir("doc"), doxyheader)
262 doxyheader = env.Yaptu("doc/doxyheader.html", os.path.join(libdir, "doxyheader.yap"), **kw)
263 env.Depends(doxyheader, envvalues)
265 doxyfooter = env.CopyToDir(env.Dir("doc"), doxyfooter)
267 doxyfooter = env.Yaptu("doc/doxyfooter.html", os.path.join(libdir, "doxyfooter.yap"), **kw)
268 env.Depends(doxyfooter, envvalues)
270 doxycss = env.CopyToDir(env.Dir("doc"), doxycss)
272 doxycss = env.CopyToDir(env.Dir("doc"), os.path.join(libdir, "doxy.css"))
274 doc = env.Doxygen("Doxyfile",
275 DOXYOPTS = [ '--html', '--tagfiles', '"$TAGFILES"' ],
276 DOXYENV = { 'TOPDIR' : env.Dir('#').abspath,
278 'REVISION' : '$REVISION',
279 'tagfiles' : '$TAGFILES',
280 'output_dir' : 'doc',
283 'DOXYGEN' : '$DOXYGEN' },
286 DOXYGENCOM = "$DOCLIBDIR/doxygen.sh $DOXYOPTS $SOURCE")
288 env.Depends(doc, [ doxyheader, doxyfooter, doxycss ])