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 PKGDRAW = 'doclib/pkgdraw',
51 ENV = { 'PATH' : os.environ.get('PATH') },
52 CLEAN_PATTERNS = [ '*~', '#*#', '*.pyc', 'semantic.cache', '.sconsign*' ],
56 LIBPATH = [ '$LOCALLIBDIR' ],
57 LIBS = [ '$LIBSENF$LIBADDSUFFIX', 'rt', '$BOOSTREGEXLIB',
58 '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB', '$BOOSTFSLIB' ],
59 TEST_EXTRA_LIBS = [ ],
62 LIBINSTALLDIR = '$PREFIX${syslayout and "/lib" or ""}',
63 BININSTALLDIR = '$PREFIX${syslayout and "/bin" or ""}',
64 INCLUDEINSTALLDIR = '$PREFIX${syslayout and "/include" or ""}',
65 CONFINSTALLDIR = '${syslayout and "$LIBINSTALLDIR/senf" or "$PREFIX"}',
66 OBJINSTALLDIR = '$CONFINSTALLDIR',
67 DOCINSTALLDIR = '$PREFIX${syslayout and "/share/doc/senf" or "/manual"}',
68 SCONSINSTALLDIR = '$CONFINSTALLDIR/site_scons',
70 CPP_INCLUDE_EXTENSIONS = [ '.h', '.hh', '.ih', '.mpp', '.cci', '.ct', '.cti' ],
71 CPP_EXCLUDE_EXTENSIONS = [ '.test.hh' ],
73 # These options are insane. Only useful for inline debugging. Need at least 1G free RAM
74 INLINE_OPTS_DEBUG = [ '-finline-limit=20000', '-fvisibility-inlines-hidden',
75 '-fno-inline-functions', '-Winline'
76 '--param','large-function-growth=10000',
77 '--param', 'large-function-insns=10000',
78 '--param','inline-unit-growth=10000' ],
79 INLINE_OPTS_NORMAL = [ '-finline-limit=5000' ],
80 INLINE_OPTS = [ '$INLINE_OPTS_NORMAL' ],
81 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long', '$INLINE_OPTS',
83 CXXFLAGS_ = senfutil.BuildTypeOptions('CXXFLAGS'),
84 CXXFLAGS_final = [ '-O3' ],
85 CXXFLAGS_normal = [ '-O0', '-g' ],
86 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
88 CPPDEFINES = [ '$expandLogOption', '$CPPDEFINES_' ],
89 expandLogOption = senfutil.expandLogOption,
90 CPPDEFINES_ = senfutil.BuildTypeOptions('CPPDEFINES'),
91 CPPDEFINES_final = [ ],
92 CPPDEFINES_normal = [ 'SENF_DEBUG' ],
93 CPPDEFINES_debug = [ '$CPPDEFINES_normal' ],
95 LINKFLAGS = [ '-rdynamic', '$LINKFLAGS_' ],
96 LINKFLAGS_ = senfutil.BuildTypeOptions('LINKFLAGS'),
97 LINKFLAGS_final = [ ],
98 LINKFLAGS_normal = [ '-Wl,-S' ],
99 LINKFLAGS_debug = [ '-g' ],
109 # Set variables from command line
110 senfutil.parseArguments(
112 BoolVariable('final', 'Build final (optimized) build', False),
113 BoolVariable('debug', 'Link in debug symbols', False),
114 BoolVariable('syslayout', 'Install in to system layout directories (lib/, include/ etc)', False),
119 # Create Doxyfile.local otherwise doxygen will barf on this non-existent file
120 # Create it even when cleaning, to silence the doxygen builder warnings
121 if not os.path.exists("Doxyfile.local"):
122 Execute(Touch("Doxyfile.local"))
124 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp") \
125 and not os.environ.get("SCONS") and COMMAND_LINE_TARGETS != [ 'prepare' ]:
126 env.Execute([ "scons prepare" ])
131 SConscript("debian/SConscript")
133 if os.path.exists('SConscript.local') : SConscript('SConscript.local')
134 SConscript("senf/SConscript")
135 SConscript("Examples/SConscript")
136 SConscript("HowTos/SConscript")
137 SConscript("doclib/SConscript")
139 ###########################################################################
140 # Define build targets
143 env.Depends(SENFSCons.Doxygen(env), env.Value(env['ENV']['REVISION']))
146 libsenf = env.Library("$LOCALLIBDIR/${LIBSENF}${LIBADDSUFFIX}", env['ALLOBJECTS'])
148 env.Install('$LIBINSTALLDIR', libsenf)
150 def create(target, source, env):
151 file(str(target[0]), 'w').write(source[0].get_contents()+"\n")
152 env['BUILDERS']['CreateFile'] = Builder(action = create)
154 conf = env.CreateFile("${LOCALLIBDIR}/${LIBSENF}${LIBADDSUFFIX}.conf",
155 env.Value(env.subst("$_CPPDEFFLAGS")))
157 env.Install('$CONFINSTALLDIR', conf)
159 #### install_all, default, all_tests, all
160 env.Install('${SCONSINSTALLDIR}', [ 'site_scons/__init__.py',
161 'site_scons/senfutil.py',
162 'site_scons/yaptu.py' ])
163 env.InstallDir('${SCONSINSTALLDIR}', [ 'site_scons/site_tools', 'site_scons/lib' ],
164 FILTER_SUFFIXES=[ '', '.css', '.pl', '.py', '.sh', '.xml', '.xsl', '.yap' ])
165 env.Install('${INCLUDEINSTALLDIR}', 'boost')
167 env.Alias('install_all', env.FindInstalledFiles())
168 env.Alias('default', DEFAULT_TARGETS)
169 env.Alias('all_tests', env.FindAllBoostUnitTests())
170 env.Alias('all', [ 'default', 'all_tests', 'examples', 'all_docs' ])
173 env.PhonyTarget('prepare', [], [])
176 env.PhonyTarget('valgrind', [ 'all_tests' ], [ """
178 | while read test; do
180 echo "Running $$test";
182 valgrind --tool=memcheck --error-exitcode=99 --suppressions=valgrind.sup
183 $$test $BOOSTTESTARGS;
184 [ $$? -ne 99 ] || exit 1;
186 """.replace("\n"," ") ])
189 env.Clean('all', '.prepare-stamp')
190 env.Clean('all', libsenf)
191 env.Clean('all', env.Dir('linklint')) # env.Dir to disambiguate from linklint PhonyTarget
192 env.Clean('all', env.Dir('dist'))
194 if env.GetOption('clean'):
195 env.Clean('all', [ os.path.join(path,f)
196 for path, subdirs, files in os.walk('.')
197 for pattern in env['CLEAN_PATTERNS']
198 for f in fnmatch.filter(files,pattern) ])
200 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
201 Execute(Touch(".prepare-stamp"))