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]
36 tooldir = os.path.join(senfutildir, 'site_tools')
37 for tool in os.listdir(tooldir):
38 name, ext = os.path.splitext(tool)
39 if ext == '.py' and name != "__init__" : env.Tool(name, [ tooldir ])
41 def parseArguments(env, *defs):
42 vars = Variables(args=ARGUMENTS)
43 for d in defs : vars.Add(d)
46 Any construction environment variable may be set from the scons
47 command line (see SConstruct file and SCons documentation for a list
50 VARNAME=value Assign new value
51 VARNAME+=value Append value at end
53 Special command line parameters:
55 env.Help(vars.GenerateHelpText(env))
56 try : unknv = vars.UnknownVariables()
57 except AttributeError: unknv = vars.UnknownOptions()
58 for k,v in unknv.iteritems():
60 env.Append(**{k[:-1]: v})
65 ###########################################################################
66 # This looks much more complicated than it is: We do three things here:
67 # a) switch between final or debug options
68 # b) parse the LOGLEVELS parameter into the correct SENF_LOG_CONF syntax
69 # c) check for a local SENF, set options accordingly and update that SENF if needed
71 def SetupForSENF(env, senf_path = []):
73 senf_path.extend(('senf', os.path.dirname(senfutildir), '/usr/local', '/usr'))
78 LIBS = [ 'senf', 'rt', '$BOOSTREGEXLIB',
79 '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB',
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"
159 env.Alias('all', '#')
162 def DefaultOptions(env):
164 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ],
165 CXXFLAGS_final = [ '-O2' ],
166 CXXFLAGS_normal = [ '-O0', '-g' ],
167 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
169 LINKFLAGS_normal = [ '-Wl,-S' ],
170 LINKFLAGS_debug = [ '-g' ],
172 # ugly hack for ubuntu karmic
173 # ToDo: auto-configure alike support
174 if os.path.exists('/usr/lib/libboost_regex-mt.so'):
175 env.Append( BOOST_VARIANT = '-mt' )
178 def Glob(env, exclude=[], subdirs=[]):
179 testSources = env.Glob("*.test.cc", strings=True)
181 for x in env.Glob("*.cc", strings=True)
182 if x not in testSources and x not in exclude ]
183 for subdir in subdirs:
184 testSources += env.Glob(os.path.join(subdir,"*.test.cc"), strings=True)
186 for x in env.Glob(os.path.join(subdir,"*.cc"), strings=True)
187 if x not in testSources and x not in exclude ]
190 return (sources, testSources)
194 def Doxygen(env, doxyheader=None, doxyfooter=None, doxycss=None, mydoxyfile=False, senfdoc_path=[],
196 # Additional interesting keyword arguments or environment variables:
197 # PROJECTNAME, DOCLINKS, PROJECTEMAIL, COPYRIGHT, REVISION
201 libdir=os.path.join(senfutildir, 'lib')
205 senfdoc_path.extend(('senfdoc', '$SENFDIR', '$SENFDIR/manual',
206 '$SENFDIR/share/doc/senf', '$SENFDIR/share/doc/libsenf-doc/html'))
207 for path in senfdoc_path:
208 path = env.Dir(path).get_path()
209 if os.path.exists(os.path.join(path, "doc/doclib.tag")):
213 if senfdocdir is None:
214 if not env.GetOption('no_progress'):
215 print "(SENF documentation not found)"
217 for dir, dirs, files in os.walk(senfdocdir):
218 tagfiles.extend([ os.path.join(dir,f) for f in files if f.endswith('.tag') ])
219 if dir.endswith('/doc') :
220 try: dirs.remove('html')
221 except ValueError: pass
223 if d.startswith('.') : dirs.remove(d)
225 if env.GetOption('clean'):
226 env.Clean('doc', env.Dir('doc'))
228 env.Clean('doc', "Doxyfile")
231 # Create Doxyfile NOW
232 site_tools.Yaptu.yaptuAction("Doxyfile",
233 os.path.join(libdir, "Doxyfile.yap"),
236 envvalues = [ env.Value('$PROJECTNAME'),
237 env.Value('$DOCLINKS'),
238 env.Value('$PROJECTEMAIL'),
239 env.Value('$COPYRIGHT'),
240 env.Value('$REVISION') ]
242 # The other files are created using dependencies
244 doxyheader = env.CopyToDir(env.Dir("doc"), doxyheader)
246 doxyheader = env.Yaptu("doc/doxyheader.html", os.path.join(libdir, "doxyheader.yap"), **kw)
247 env.Depends(doxyheader, envvalues)
249 doxyfooter = env.CopyToDir(env.Dir("doc"), doxyfooter)
251 doxyfooter = env.Yaptu("doc/doxyfooter.html", os.path.join(libdir, "doxyfooter.yap"), **kw)
252 env.Depends(doxyfooter, envvalues)
254 doxycss = env.CopyToDir(env.Dir("doc"), doxycss)
256 doxycss = env.CopyToDir(env.Dir("doc"), os.path.join(libdir, "doxy.css"))
258 doc = env.Doxygen("Doxyfile",
259 DOXYOPTS = [ '--html', '--tagfiles', '"$TAGFILES"' ],
260 DOXYENV = { 'TOPDIR' : env.Dir('#').abspath,
262 'REVISION' : '$REVISION',
263 'tagfiles' : '$TAGFILES',
264 'output_dir' : 'doc',
267 'DOXYGEN' : '$DOXYGEN' },
270 DOXYGENCOM = "$DOCLIBDIR/doxygen.sh $DOXYOPTS $SOURCE")
272 env.Depends(doc, [ doxyheader, doxyfooter, doxycss ])