2 import SCons.Options, SCons.Environment, SCons.Script.SConscript, SCons.Node.FS, SCons.Defaults
12 basedir = os.path.split(__file__)[0]
16 if opts is not None: return
17 opts = SCons.Options.Options('SConfig')
18 opts.Add('CXX', 'C++ compiler to use', 'g++')
19 opts.Add('EXTRA_DEFINES', 'Additional preprocessor defines', '')
20 opts.Add('EXTRA_LIBS', 'Additional libraries to link against', '')
21 opts.Add(SCons.Options.BoolOption('final','Enable optimization',0))
30 opts.Add('BOOST_INCLUDES', 'Boost include directory', '')
31 opts.Add('BOOST_VARIANT', 'The boost variant to use', '')
32 opts.Add('BOOST_TOOLSET', 'The boost toolset to use', '')
33 opts.Add('BOOST_RUNTIME', 'The boost runtime to use', '')
34 opts.Add('BOOST_DEBUG_RUNTIME', 'The boost debug runtime to use', '')
35 opts.Add('BOOST_LIBDIR', 'The directory of the boost libraries', '')
36 Finalizer(FinalizeBoost)
38 def FinalizeBoost(env):
39 env.Tool('BoostUnitTests', [basedir])
41 if env['BOOST_TOOLSET']:
43 if env['final'] : runtime += env.get('BOOST_RUNTIME','')
44 else : runtime += env.get('BOOST_DEBUG_RUNTIME','gd')
45 if env['STLPORT_LIB'] : runtime += "p"
46 if runtime: runtime = "-" + runtime
47 env['BOOST_VARIANT'] = "-" + env['BOOST_TOOLSET'] + runtime
49 env['BOOSTTESTLIB'] = 'libboost_unit_test_framework' + env['BOOST_VARIANT']
51 env.Append(LIBPATH = [ '$BOOST_LIBDIR' ],
52 CPPPATH = [ '$BOOST_INCLUDES' ])
57 opts.Add('STLPORT_INCLUDES', 'STLport include directory', '')
58 opts.Add('STLPORT_LIB', 'Name of the stlport library or empty to not use stlport', '')
59 opts.Add('STLPORT_DEBUGLIB', 'Name of the stlport debug library','')
60 opts.Add('STLPORT_LIBDIR', 'The directory of the stlport libraries','')
61 Finalizer(FinalizeSTLPort)
63 def FinalizeSTLPort(env):
64 if env['STLPORT_LIB']:
65 if not env['STLPORT_DEBUGLIB']:
66 env['STLPORT_DEBUGLIB'] = env['STLPORT_LIB'] + '_stldebug'
67 env.Append(LIBPATH = [ '$STLPORT_LIBDIR' ],
68 CPPPATH = [ '$STLPORT_INCLUDES' ])
70 env.Append(LIBS = [ '$STLPORT_LIB' ])
72 env.Append(LIBS = [ '$STLPORT_DEBUGLIB' ],
73 CPPDEFINES = [ '_STLP_DEBUG' ])
75 def MakeEnvironment():
76 global opts, finalizers
78 env = SCons.Environment.Environment(options=opts)
79 if SCons.Script.SConscript.Arguments.get('final'):
81 env.Help(opts.GenerateHelpText(env))
82 #conf = env.Configure()
84 if os.environ.has_key('SSH_AUTH_SOCK'):
85 env.Append( ENV = { 'SSH_AUTH_SOCK': os.environ['SSH_AUTH_SOCK'] } )
87 for finalizer in finalizers:
90 for tool in SCONS_TOOLS:
91 env.Tool(tool, [basedir])
93 env.Append(CXXFLAGS = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long' ],
94 LOCALLIBDIR = [ '#' ],
95 LIBPATH = [ '$LOCALLIBDIR' ])
98 env.Append(CXXFLAGS = [ '-O3' ],
99 CPPDEFINES = [ 'NDEBUG' ])
101 env.Append(CXXFLAGS = [ '-O0', '-g', '-fno-inline' ],
102 LINKFLAGS = [ '-g' ])
104 env.Append(CPPDEFINES = [ '$EXTRA_DEFINES' ],
105 LIBS = [ '$EXTRA_LIBS' ])
107 #return conf.Finish()
110 def GlobSources(exclude=[]):
111 testSources = glob.glob("*.test.cc")
112 sources = [ x for x in glob.glob("*.cc") if x not in testSources and x not in exclude ]
113 return (sources, testSources)
115 def StandardTargets(env):
116 all = env.Alias('all')
117 env.Clean(all, [ '.sconsign', '.sconf_temp', 'config.log' ])
118 env.Depends(all, '.')
120 def GlobalTargets(env):
123 def LibPath(lib): return '$LOCALLIBDIR/lib%s.a' % lib
125 def Objects(env, sources, testSources = None, LIBS = []):
126 if type(sources) == type(()):
127 testSources = sources[1]
132 objects = env.Object(sources)
135 test = env.BoostUnitTests(
138 test_source = testSources,
140 DEPENDS = [ env.File(LibPath(x)) for x in LIBS ])
141 env.Alias('all_tests', test)
142 # Hmm ... here I'd like to use an Alias instead of a file
143 # however the alias does not seem to live in the subdirectory
144 # which breaks 'scons -u test'
145 env.Alias(env.File('test'), test)
149 def Doxygen(env, doxyfile = "Doxyfile", extra_sources = []):
150 docs = env.Doxygen(doxyfile)
152 if isinstance(doc,SCons.Node.FS.Dir): continue
153 if os.path.basename(str(doc)) == '.stamp' : continue # file stamp
154 # otherwise it must be the tag file
159 # Postprocess the tag file to remove the (broken) namespace
163 env.Action([ "xsltproc -o TARGET.temp %s TARGET"
164 % os.path.join(basedir,"tagmunge.xsl"),
165 "mv TARGET.temp TARGET" ]))
166 env.Clean(doc,"$TARGET.temp")
167 env.Depends(docs,extra_sources)
169 env.Alias('all_docs', doc)
170 env.Clean('all_docs', doc)
171 env.Clean('all', doc)
175 TYPES = ('bug','todo'),
176 HTML_HEADER = None, HTML_FOOTER = None,
177 TITLE = "Cross-reference of action points"):
178 # Hmm .. this looks a bit scary :-) ...
181 # This iterates over all doc targets. These are all .stamp and .tag files
182 for node in env.Alias('all_docs')[0].sources:
183 # We are only interested in the xml targets. This is Doxyfile dependent :-(
184 if node.abspath.endswith('/xml/.stamp'):
185 # This is the list of xref categories
187 # Here we construct the pathname of the xml file for the category
188 xref = os.path.join(node.dir.abspath,type+'.xml')
189 # And now apply the xrefxtract.xslt tempalte to it. However, we must
190 # only call xsltproc if the source xml file is not empty (therefore the
192 xrefi = env.Command(xref+'i', [ xref, '%s/xrefxtract.xslt' % basedir, node ],
193 [ "test -s $SOURCE && xsltproc -o $TARGET" +
194 " --stringparam module $MODULE" +
195 " --stringparam type $TYPE" +
196 " ${SOURCES[1]} $SOURCE || touch $TARGET" ],
197 MODULE = node.dir.dir.dir.name,
199 # If the xref xml file does not exist we create it here as an empty
200 # file since doxygen will only create it if it is non-empty.
201 if not env.GetOption('clean') and not os.path.exists(xref):
202 if not os.path.exists(node.dir.abspath):
203 env.Execute(SCons.Defaults.Mkdir(node.dir.abspath))
204 env.Execute(SCons.Defaults.Touch(xref))
207 # And here we can now simply combine all the xrefi files
208 xref = env.Command("doc/html/xref.xml", xrefis,
209 [ "echo -e '<?xml version=\"1.0\"?>\\n<xref>' >$TARGET",
210 "cat $SOURCES >> $TARGET",
211 "echo '</xref>' >>$TARGET" ])
213 # Lastly we create the html file
214 sources = [ xref, "%s/xrefhtml.xslt" % basedir ]
215 if HTML_HEADER : sources.append(HTML_HEADER)
216 if HTML_FOOTER : sources.append(HTML_FOOTER)
221 "sed -e 's/\\$$title/$TITLE/g' -e 's/\\$$projectname/Overview/g' ${SOURCES[2]} > $TARGET")
222 commands.append("xsltproc --stringparam title '$TITLE' ${SOURCES[1]} $SOURCE >> $TARGET")
225 "sed -e 's/\\$$title/$TITLE/g' -e 's/\\$$projectname/Overview/g' ${SOURCES[%d]} >> $TARGET"
226 % (HTML_HEADER and 3 or 2))
228 xref = env.Command("doc/html/xref.html", sources, commands)
230 env.Alias('all_docs',xref)
233 def Lib(env, library, sources, testSources = None, LIBS = []):
234 objects = Objects(env,sources,testSources,LIBS=LIBS)
237 lib = env.Library(env.File(LibPath(library)),objects)
239 env.Append(ALLLIBS = library)
242 def Binary(env, binary, sources, testSources = None, LIBS = []):
243 objects = Objects(env,sources,testSources,LIBS=LIBS)
247 progEnv.Prepend(LIBS = LIBS)
248 program = progEnv.Program(target=binary,source=objects)
250 env.Depends(program, [ env.File(LibPath(x)) for x in LIBS ])