1 import os.path, SCons.Options, SCons.Environment, SCons.Script.SConscript, glob
11 basedir = os.path.split(__file__)[0]
15 if opts is not None: return
16 opts = SCons.Options.Options('SConfig')
17 opts.Add('CXX', 'C++ compiler to use', 'g++')
18 opts.Add('EXTRA_DEFINES', 'Additional preprocessor defines', '')
19 opts.Add('EXTRA_LIBS', 'Additional libraries to link against', '')
20 opts.Add(SCons.Options.BoolOption('final','Enable optimization',0))
29 opts.Add('BOOST_INCLUDES', 'Boost include directory', '')
30 opts.Add('BOOST_VARIANT', 'The boost variant to use', '')
31 opts.Add('BOOST_TOOLSET', 'The boost toolset to use', '')
32 opts.Add('BOOST_RUNTIME', 'The boost runtime to use', '')
33 opts.Add('BOOST_DEBUG_RUNTIME', 'The boost debug runtime to use', '')
34 opts.Add('BOOST_LIBDIR', 'The directory of the boost libraries', '')
35 Finalizer(FinalizeBoost)
37 def FinalizeBoost(env):
38 env.Tool('BoostUnitTests', [basedir])
40 if env['BOOST_TOOLSET']:
42 if env['final'] : runtime += env.get('BOOST_RUNTIME','')
43 else : runtime += env.get('BOOST_DEBUG_RUNTIME','gd')
44 if env['STLPORT_LIB'] : runtime += "p"
45 if runtime: runtime = "-" + runtime
46 env['BOOST_VARIANT'] = "-" + env['BOOST_TOOLSET'] + runtime
48 env['BOOSTTESTLIB'] = 'libboost_unit_test_framework' + env['BOOST_VARIANT']
50 env.Append(LIBPATH = [ '$BOOST_LIBDIR' ],
51 CPPPATH = [ '$BOOST_INCLUDES' ])
56 opts.Add('STLPORT_INCLUDES', 'STLport include directory', '')
57 opts.Add('STLPORT_LIB', 'Name of the stlport library or empty to not use stlport', '')
58 opts.Add('STLPORT_DEBUGLIB', 'Name of the stlport debug library','')
59 opts.Add('STLPORT_LIBDIR', 'The directory of the stlport libraries','')
60 Finalizer(FinalizeSTLPort)
62 def FinalizeSTLPort(env):
63 if env['STLPORT_LIB']:
64 if not env['STLPORT_DEBUGLIB']:
65 env['STLPORT_DEBUGLIB'] = env['STLPORT_LIB'] + '_stldebug'
66 env.Append(LIBPATH = [ '$STLPORT_LIBDIR' ],
67 CPPPATH = [ '$STLPORT_INCLUDES' ])
69 env.Append(LIBS = [ '$STLPORT_LIB' ])
71 env.Append(LIBS = [ '$STLPORT_DEBUGLIB' ],
72 CPPDEFINES = [ '_STLP_DEBUG' ])
74 def MakeEnvironment():
75 global opts, finalizers
77 env = SCons.Environment.Environment(options=opts)
78 if SCons.Script.SConscript.Arguments.get('final'):
80 env.Help(opts.GenerateHelpText(env))
81 #conf = env.Configure()
83 if os.environ.has_key('SSH_AUTH_SOCK'):
84 env.Append( ENV = { 'SSH_AUTH_SOCK': os.environ['SSH_AUTH_SOCK'] } )
86 for finalizer in finalizers:
89 for tool in SCONS_TOOLS:
90 env.Tool(tool, [basedir])
92 env.Append(CXXFLAGS = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long' ],
93 LOCALLIBDIR = [ '#' ],
94 LIBPATH = [ '$LOCALLIBDIR' ])
97 env.Append(CXXFLAGS = [ '-O3' ],
98 CPPDEFINES = [ 'NDEBUG' ])
100 env.Append(CXXFLAGS = [ '-O0', '-g', '-fno-inline' ],
101 LINKFLAGS = [ '-g' ])
103 env.Append(CPPDEFINES = [ '$EXTRA_DEFINES' ],
104 LIBS = [ '$EXTRA_LIBS' ])
106 #return conf.Finish()
109 def GlobSources(exclude=[]):
110 testSources = glob.glob("*.test.cc")
111 sources = [ x for x in glob.glob("*.cc") if x not in testSources and x not in exclude ]
112 return (sources, testSources)
114 def StandardTargets(env):
115 all = env.Alias('all')
116 env.Clean(all, [ '.sconsign', '.sconf_temp', 'config.log' ])
117 env.Depends(all, '.')
119 def GlobalTargets(env):
120 command = "find -name .svn -prune -o \( -name '*.hh' -o -name '*.ih' -o -name '*.cc' -o -name '*.cci' -o -name '*.ct' -o -name '*.cti' -o -name '*.mpp' \) -print " \
121 "| xargs -r awk -F '//' '/%s/{print ARGV[ARGIND] \":\" FNR \":\" $2}' > $TARGET"
122 env.AlwaysBuild(env.Command('TODOS',None,[ command % 'TODO' ]))
123 env.AlwaysBuild(env.Command('FIXMES',None,[ command % ' FIXME' ]))
124 env.AlwaysBuild(env.Command('BUGS',None,[ command % 'BUG' ] ))
125 env.Alias('status',[ 'TODOS', 'FIXMES', 'BUGS' ])
127 def LibPath(lib): return '$LOCALLIBDIR/lib%s.a' % lib
129 def Objects(env, sources, testSources = None, LIBS = []):
130 if type(sources) == type(()):
131 testSources = sources[1]
136 objects = env.Object(sources)
139 test = env.BoostUnitTests(
142 test_source = testSources,
144 DEPENDS = [ env.File(LibPath(x)) for x in LIBS ])
145 env.Alias('all_tests', test)
146 # Hmm ... here I'd like to use an Alias instead of a file
147 # however the alias does not seem to live in the subdirectory
148 # which breaks 'scons -u test'
149 env.Alias(env.File('test'), test)
153 def Doxygen(env, doxyfile = "Doxyfile", extra_sources = []):
154 docs = env.Doxygen(doxyfile)
155 # The last target is the (optional) tagfile
156 if os.path.basename(str(docs[-1])) != '.stamp':
157 # Postprocess the tag file to remove the (broken) namespace
161 env.Action([ "xsltproc -o ${TARGETS[-1]}.temp %s ${TARGETS[-1]}"
162 % os.path.join(basedir,"tagmunge.xsl"),
163 "mv ${TARGETS[-1]}.temp ${TARGETS[-1]}" ]))
164 env.Clean(docs[-1],"$TARGET.temp")
165 env.Depends(docs,extra_sources)
166 env.Alias('all_docs', *docs)
169 def Lib(env, library, sources, testSources = None, LIBS = []):
170 objects = Objects(env,sources,testSources,LIBS=LIBS)
173 lib = env.Library(env.File(LibPath(library)),objects)
175 env.Append(ALLLIBS = library)
178 def Binary(env, binary, sources, testSources = None, LIBS = []):
179 objects = Objects(env,sources,testSources,LIBS=LIBS)
183 progEnv.Prepend(LIBS = LIBS)
184 program = progEnv.Program(target=binary,source=objects)
186 env.Depends(program, [ env.File(LibPath(x)) for x in LIBS ])