3 import sys, glob, os.path, fnmatch
4 import SENFSCons, senfutil
6 ###########################################################################
7 # Load utilities and setup libraries and configure build
11 env.Decider('MD5-timestamp')
12 env.EnsureSConsVersion(1,2)
14 # Load all the local SCons tools
18 env.Tool('InstallSubdir')
21 env.Tool('CombinedObject')
22 env.Tool('PhonyTarget')
23 env.Tool('InstallDir')
26 Additional top-level build targets:
28 prepare Create all target files not part of the repository
29 default Build all default targets (like calling scons with no arguments)
30 examples Build all examples
31 all_tests Build and run unit tests for all modules
32 all_docs Build documentation for all modules
34 install_all Install SENF into $$PREFIX
35 deb Build debian source and binary package
36 debsrc Build debian source package
37 debbin Build debian binary package
38 linklint Check links of doxygen documentation with 'linklint'
39 fixlinks Fix broken links in doxygen documentation
40 all_valgrinds Run all tests under valgrind/memcheck
41 lcov Generate test coverage output in doc/lcov and lcov.info
45 ENV = { 'PATH' : os.environ.get('PATH'), 'HOME' : os.environ.get('HOME') },
46 CLEAN_PATTERNS = [ '*~', '#*#', '*.pyc', 'semantic.cache', '.sconsign*',
47 '*.gcno', '*.gcda', '*.gcov' ],
51 LIBPATH = [ '$LOCALLIBDIR' ],
52 LIBS = [ '$LIBSENF$LIBADDSUFFIX', 'rt', '$BOOSTREGEXLIB',
53 '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB', '$BOOSTFSLIB' ],
54 TEST_EXTRA_LIBS = [ ],
55 VALGRINDARGS = [ '--num-callers=50' ],
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' ],
102 SCONS = "./tools/scons -j$CONCURRENCY_LEVEL",
103 CONCURRENCY_LEVEL = env.GetOption('num_jobs') or 1,
104 TOPDIR = env.Dir('#').abspath,
107 # Set variables from command line
108 senfutil.parseArguments(
110 BoolVariable('final', 'Build final (optimized) build', False),
111 BoolVariable('debug', 'Link in debug symbols', False),
112 BoolVariable('syslayout', 'Install in to system layout directories (lib/, include/ etc)', False),
117 # Create Doxyfile.local otherwise doxygen will barf on this non-existent file
118 # Create it even when cleaning, to silence the doxygen builder warnings
119 if not os.path.exists("doclib/Doxyfile.local"):
120 Execute(Touch("doclib/Doxyfile.local"))
122 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp") \
123 and not os.environ.get("SCONS") and COMMAND_LINE_TARGETS != [ 'prepare' ]:
124 env.Execute([ "scons prepare" ])
129 SConscript("debian/SConscript")
131 if os.path.exists('SConscript.local') : SConscript('SConscript.local')
132 SConscript("senf/SConscript")
133 SConscript("Examples/SConscript")
134 SConscript("HowTos/SConscript")
135 SConscript("doclib/SConscript")
137 ###########################################################################
138 # Define build targets
141 libsenf = env.Library("$LOCALLIBDIR/${LIBSENF}${LIBADDSUFFIX}", env['ALLOBJECTS'])
143 env.Install('$LIBINSTALLDIR', libsenf)
145 def create(target, source, env):
146 file(str(target[0]), 'w').write(source[0].get_contents()+"\n")
147 env['BUILDERS']['CreateFile'] = Builder(action = create)
149 conf = env.CreateFile("${LOCALLIBDIR}/${LIBSENF}${LIBADDSUFFIX}.conf",
150 env.Value(env.subst("$_CPPDEFFLAGS")))
152 env.Install('$CONFINSTALLDIR', conf)
154 #### install_all, default, all_tests, all
155 env.Install('${SCONSINSTALLDIR}', [ 'site_scons/__init__.py',
156 'site_scons/senfutil.py',
157 'site_scons/yaptu.py' ])
158 env.InstallDir('${SCONSINSTALLDIR}', [ 'site_scons/site_tools', 'site_scons/lib' ],
159 FILTER_SUFFIXES=[ '','.css','.pl','.py','.sh','.sty','.xml','.xsl','.yap' ])
160 env.Install('${INCLUDEINSTALLDIR}', 'boost')
162 env.Alias('install_all', env.FindInstalledFiles())
163 env.Alias('default', DEFAULT_TARGETS)
164 env.Alias('all_tests', env.FindAllBoostUnitTests())
165 env.Alias('all', [ 'default', 'all_tests', 'examples', 'all_docs' ])
168 env.PhonyTarget('prepare', [], [])
171 for test in env.FindAllBoostUnitTests():
172 stamp = env.Command(test[0].dir.File('.test-valgrind.stamp'),
173 [ test[0].dir.File('.test.bin'), 'tools/valgrind.sup' ],
174 [ """valgrind --tool=memcheck
176 --suppressions=${SOURCES[1]}
178 ${SOURCES[0]} $BOOSTTESTARGS;
179 [ $$? -ne 99 ] || exit 1""".replace("\n"," "),
181 alias = env.Command(test[0].dir.File('valgrind'), stamp, [ env.NopAction() ])
182 env.Alias('all_valgrinds', alias)
185 env.PhonyTarget('lcov', [], [
186 '$SCONS debug=1 CCFLAGS+="-fprofile-arcs -ftest-coverage" LIBS+="gcov" all_tests',
187 '$LCOV --directory $TOPDIR/senf --capture --output-file /tmp/senf_lcov.info --base-directory $TOPDIR',
188 '$LCOV --output-file lcov.info --remove /tmp/senf_lcov.info "*/include/*" "*/boost/*" "*.test.*" ',
189 '$GENHTML --output-directory doc/lcov --title all_tests lcov.info',
190 'rm /tmp/senf_lcov.info' ])
193 env.Clean('all', '.prepare-stamp')
194 env.Clean('all', libsenf)
195 env.Clean('all', env.Dir('dist'))
196 env.Clean('all', 'lcov.info')
198 if env.GetOption('clean'):
199 env.Clean('all', [ os.path.join(path,f)
200 for path, subdirs, files in os.walk('.')
201 for pattern in env['CLEAN_PATTERNS']
202 for f in fnmatch.filter(files,pattern) ])
204 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
205 Execute(Touch(".prepare-stamp"))