3 import sys, glob, os.path, fnmatch
4 import SENFSCons, senfutil
6 # Fix for SCons 0.97 compatibility
10 BoolVariable = BoolOption
12 ###########################################################################
13 # Load utilities and setup libraries and configure build
17 # Load all the local SCons tools
21 env.Tool('InstallSubdir')
24 env.Tool('CombinedObject')
25 env.Tool('PhonyTarget')
26 env.Tool('InstallDir')
29 Additional top-level build targets:
31 prepare Create all target files not part of the repository
32 default Build all default targets (like calling scons with no arguments)
33 examples Build all examples
34 all_tests Build and run unit tests for all modules
35 all_docs Build documentation for all modules
37 install_all Install SENF into $$PREFIX
38 deb Build debian source and binary package
39 debsrc Build debian source package
40 debbin Build debian binary package
41 linklint Check links of doxygen documentation with 'linklint'
42 fixlinks Fix broken links in doxygen documentation
43 valgrind Run all tests under valgrind/memcheck
47 ENV = { 'PATH' : os.environ.get('PATH') },
48 CLEAN_PATTERNS = [ '*~', '#*#', '*.pyc', 'semantic.cache', '.sconsign*' ],
52 LIBPATH = [ '$LOCALLIBDIR' ],
53 LIBS = [ '$LIBSENF$LIBADDSUFFIX', 'rt', '$BOOSTREGEXLIB',
54 '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB', '$BOOSTFSLIB' ],
55 TEST_EXTRA_LIBS = [ ],
58 LIBINSTALLDIR = '$PREFIX${syslayout and "/lib" or ""}',
59 BININSTALLDIR = '$PREFIX${syslayout and "/bin" or ""}',
60 INCLUDEINSTALLDIR = '$PREFIX${syslayout and "/include" or ""}',
61 CONFINSTALLDIR = '${syslayout and "$LIBINSTALLDIR/senf" or "$PREFIX"}',
62 OBJINSTALLDIR = '$CONFINSTALLDIR',
63 DOCINSTALLDIR = '$PREFIX${syslayout and "/share/doc/senf" or "/manual"}',
64 SCONSINSTALLDIR = '$CONFINSTALLDIR/site_scons',
66 CPP_INCLUDE_EXTENSIONS = [ '.h', '.hh', '.ih', '.mpp', '.cci', '.ct', '.cti' ],
67 CPP_EXCLUDE_EXTENSIONS = [ '.test.hh' ],
69 # These options are insane. Only useful for inline debugging. Need at least 1G free RAM
70 INLINE_OPTS_DEBUG = [ '-finline-limit=20000', '-fvisibility-inlines-hidden',
71 '-fno-inline-functions', '-Winline'
72 '--param','large-function-growth=10000',
73 '--param', 'large-function-insns=10000',
74 '--param','inline-unit-growth=10000' ],
75 INLINE_OPTS_NORMAL = [ '-finline-limit=5000' ],
76 INLINE_OPTS = [ '$INLINE_OPTS_NORMAL' ],
77 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long', '$INLINE_OPTS',
79 CXXFLAGS_ = senfutil.BuildTypeOptions('CXXFLAGS'),
80 CXXFLAGS_final = [ '-O3' ],
81 CXXFLAGS_normal = [ '-O0', '-g' ],
82 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
84 CPPDEFINES = [ '$expandLogOption', '$CPPDEFINES_' ],
85 expandLogOption = senfutil.expandLogOption,
86 CPPDEFINES_ = senfutil.BuildTypeOptions('CPPDEFINES'),
87 CPPDEFINES_final = [ ],
88 CPPDEFINES_normal = [ 'SENF_DEBUG' ],
89 CPPDEFINES_debug = [ '$CPPDEFINES_normal' ],
91 LINKFLAGS = [ '-rdynamic', '$LINKFLAGS_' ],
92 LINKFLAGS_ = senfutil.BuildTypeOptions('LINKFLAGS'),
93 LINKFLAGS_final = [ ],
94 LINKFLAGS_normal = [ '-Wl,-S' ],
95 LINKFLAGS_debug = [ '-g' ],
105 # Set variables from command line
106 senfutil.parseArguments(
108 BoolVariable('final', 'Build final (optimized) build', False),
109 BoolVariable('debug', 'Link in debug symbols', False),
110 BoolVariable('syslayout', 'Install in to system layout directories (lib/, include/ etc)', False),
115 # Create Doxyfile.local otherwise doxygen will barf on this non-existent file
116 # Create it even when cleaning, to silence the doxygen builder warnings
117 if not os.path.exists("Doxyfile.local"):
118 Execute(Touch("Doxyfile.local"))
120 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp") \
121 and not os.environ.get("SCONS") and COMMAND_LINE_TARGETS != [ 'prepare' ]:
122 env.Execute([ "scons prepare" ])
127 SConscript("debian/SConscript")
129 if os.path.exists('SConscript.local') : SConscript('SConscript.local')
130 SConscript("senf/SConscript")
131 SConscript("Examples/SConscript")
132 SConscript("HowTos/SConscript")
133 SConscript("doclib/SConscript")
135 ###########################################################################
136 # Define build targets
139 env.Depends(SENFSCons.Doxygen(env), env.Value(env['ENV']['REVISION']))
142 libsenf = env.Library("$LOCALLIBDIR/${LIBSENF}${LIBADDSUFFIX}", env['ALLOBJECTS'])
144 env.Install('$LIBINSTALLDIR', libsenf)
146 def create(target, source, env):
147 file(str(target[0]), 'w').write(source[0].get_contents()+"\n")
148 env['BUILDERS']['CreateFile'] = Builder(action = create)
150 conf = env.CreateFile("${LOCALLIBDIR}/${LIBSENF}${LIBADDSUFFIX}.conf",
151 env.Value(env.subst("$_CPPDEFFLAGS")))
153 env.Install('$CONFINSTALLDIR', conf)
155 #### install_all, default, all_tests, all
156 env.Install('${SCONSINSTALLDIR}', [ 'site_scons/__init__.py',
157 'site_scons/senfutil.py',
158 'site_scons/yaptu.py' ])
159 env.InstallDir('${SCONSINSTALLDIR}', [ 'site_scons/site_tools', 'site_scons/lib' ],
160 FILTER_SUFFIXES=[ '','.css','.pl','.py','.sh','.sty','.xml','.xsl','.yap' ])
161 env.Install('${INCLUDEINSTALLDIR}', 'boost')
163 env.Alias('install_all', env.FindInstalledFiles())
164 env.Alias('default', DEFAULT_TARGETS)
165 env.Alias('all_tests', env.FindAllBoostUnitTests())
166 env.Alias('all', [ 'default', 'all_tests', 'examples', 'all_docs' ])
169 env.PhonyTarget('prepare', [], [])
172 env.PhonyTarget('valgrind', [ 'all_tests' ], [ """
174 | while read test; do
176 echo "Running $$test";
178 valgrind --tool=memcheck --error-exitcode=99 --suppressions=valgrind.sup
179 $$test $BOOSTTESTARGS;
180 [ $$? -ne 99 ] || exit 1;
182 """.replace("\n"," ") ])
185 env.Clean('all', '.prepare-stamp')
186 env.Clean('all', libsenf)
187 env.Clean('all', env.Dir('linklint')) # env.Dir to disambiguate from linklint PhonyTarget
188 env.Clean('all', env.Dir('dist'))
190 if env.GetOption('clean'):
191 env.Clean('all', [ os.path.join(path,f)
192 for path, subdirs, files in os.walk('.')
193 for pattern in env['CLEAN_PATTERNS']
194 for f in fnmatch.filter(files,pattern) ])
196 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
197 Execute(Touch(".prepare-stamp"))