3 import sys, glob, os.path, fnmatch
4 import SENFSCons, senfutil
6 ###########################################################################
7 # Load utilities and setup libraries and configure build
11 # Load all the local SCons tools
15 env.Tool('InstallSubdir')
18 env.Tool('CombinedObject')
19 env.Tool('PhonyTarget')
22 Additional top-level build targets:
24 prepare Create all target files not part of the repository
25 default Build all default targets (like calling scons with no arguments)
26 examples Build all examples
27 all_tests Build and run unit tests for all modules
28 all_docs Build documentation for all modules
30 install_all Install SENF into $PREFIX
31 deb Build debian source and binary package
32 debsrc Build debian source package
33 debbin Build debian binary package
34 linklint Check links of doxygen documentation with 'linklint'
35 fixlinks Fix broken links in doxygen documentation
36 valgrind Run all tests under valgrind/memcheck
39 class BuildTypeOptions:
40 def __init__(self, var):
43 def __call__(self, target, source, env, for_signature):
44 type = env['final'] and "final" or env['debug'] and "debug" or "normal"
45 return env[self._var + "_" + type]
48 PKGDRAW = 'doclib/pkgdraw',
52 ENV = { 'PATH' : os.environ.get('PATH') },
53 CLEAN_PATTERNS = [ '*~', '#*#', '*.pyc', 'semantic.cache', '.sconsign*', '.sconsign' ],
57 LIBPATH = [ '$LOCALLIBDIR' ],
58 LIBS = [ '$LIBSENF$LIBADDSUFFIX', 'rt', '$BOOSTREGEXLIB',
59 '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB', '$BOOSTFSLIB' ],
60 TEST_EXTRA_LIBS = [ ],
63 LIBINSTALLDIR = '$PREFIX${syslayout and "/lib" or ""}',
64 BININSTALLDIR = '$PREFIX${syslayout and "/bin" or ""',
65 INCLUDEINSTALLDIR = '$PREFIX${syslayout and "/include" or ""}',
66 OBJINSTALLDIR = '$LIBINSTALLDIR${syslayout and "/$LIBINSTALLDIR/senf" or ""',
67 DOCINSTALLDIR = '$PREFIX/docs',
68 CPP_INCLUDE_EXTENSIONS = [ '.h', '.hh', '.ih', '.mpp', '.cci', '.ct', '.cti' ],
69 CPP_EXCLUDE_EXTENSIONS = [ '.test.hh' ],
71 # These options are insane. Only useful for inline debugging. Need at least 1G free RAM
72 INLINE_OPTS_DEBUG = [ '-finline-limit=20000', '-fvisibility-inlines-hidden',
73 '-fno-inline-functions', '-Winline'
74 '--param','large-function-growth=10000',
75 '--param', 'large-function-insns=10000',
76 '--param','inline-unit-growth=10000' ],
77 INLINE_OPTS_NORMAL = [ '-finline-limit=5000' ],
78 INLINE_OPTS = [ '$INLINE_OPTS_NORMAL' ],
79 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long', '$INLINE_OPTS',
81 CXXFLAGS_ = BuildTypeOptions('CXXFLAGS'),
82 CXXFLAGS_final = [ '-O3' ],
83 CXXFLAGS_normal = [ '-O0', '-g' ],
84 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
86 CPPDEFINES = [ '$expandLogOption', '$CPPDEFINES_' ],
87 expandLogOption = senfutil.expandLogOption,
88 CPPDEFINES_ = BuildTypeOptions('CPPDEFINES'),
89 CPPDEFINES_final = [ ],
90 CPPDEFINES_normal = [ 'SENF_DEBUG' ],
91 CPPDEFINES_debug = [ '$CPPDEFINES_normal' ],
93 LINKFLAGS = [ '-rdynamic', '$LINKFLAGS_' ],
94 LINKFLAGS_ = BuildTypeOptions('LINKFLAGS'),
95 LINKFLAGS_final = [ ],
96 LINKFLAGS_normal = [ '-Wl,-S' ],
97 LINKFLAGS_debug = [ ],
107 # Set variables from command line
108 env.Replace(**ARGUMENTS)
112 # Create Doxyfile.local otherwise doxygen will barf on this non-existent file
113 # Create it even when cleaning, to silence the doxygen builder warnings
114 if not os.path.exists("Doxyfile.local"):
115 Execute(Touch("Doxyfile.local"))
117 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp") \
118 and not os.environ.get("SCONS") and COMMAND_LINE_TARGETS != [ 'prepare' ]:
119 env.Execute([ "scons prepare" ])
124 SConscript("debian/SConscript")
126 if os.path.exists('SConscript.local') : SConscript('SConscript.local')
127 SConscript("senf/SConscript")
128 SConscript("Examples/SConscript")
129 SConscript("HowTos/SConscript")
130 SConscript("doclib/SConscript")
132 ###########################################################################
133 # Define build targets
136 env.Depends(SENFSCons.Doxygen(env), env.Value(env['ENV']['REVISION']))
139 libsenf = env.Library("$LOCALLIBDIR/${LIBSENF}${LIBADDSUFFIX}", env['ALLOBJECTS'])
142 env.Install('$LIBINSTALLDIR', libsenf)
144 #### install_all, default, all_tests, all
145 env.Alias('install_all', env.FindInstalledFiles())
146 env.Alias('default', DEFAULT_TARGETS)
147 env.Alias('all_tests', env.FindAllBoostUnitTests())
148 env.Alias('all', [ 'default', 'all_tests', 'examples', 'all_docs' ])
151 env.PhonyTarget('prepare', [], [])
154 env.PhonyTarget('valgrind', [ 'all_tests' ], [ """
156 | while read test; do
158 echo "Running $$test";
160 valgrind --tool=memcheck --error-exitcode=99 --suppressions=valgrind.sup
161 $$test $BOOSTTESTARGS;
162 [ $$? -ne 99 ] || exit 1;
164 """.replace("\n"," ") ])
167 env.Clean('all', '.prepare-stamp')
168 env.Clean('all', libsenf)
169 env.Clean('all', env.Dir('linklint')) # env.Dir to disambiguate from linklint PhonyTarget
171 if env.GetOption('clean'):
172 env.Clean('all', [ os.path.join(path,f)
173 for path, subdirs, files in os.walk('.')
174 for pattern in env['CLEAN_PATTERNS']
175 for f in fnmatch.filter(files,pattern) ])
177 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
178 Execute(Touch(".prepare-stamp"))