Fix debian build
[senf.git] / SConstruct
1 # -*- python -*-
2
3 import sys, glob, os.path, fnmatch
4 import SENFSCons, senfutil
5
6 # Fix for SCons 0.97 compatibility
7 try:
8     BoolVariable
9 except NameError:
10     BoolVariable = BoolOption
11
12 ###########################################################################
13 # Load utilities and setup libraries and configure build
14
15 env = Environment()
16
17 # Load all the local SCons tools
18 env.Tool('Doxygen')
19 env.Tool('Doxygen')
20 env.Tool('Dia2Png')
21 env.Tool('PkgDraw')
22 env.Tool('InstallSubdir')
23 env.Tool('CopyToDir')
24 env.Tool('Boost')
25 env.Tool('CombinedObject')
26 env.Tool('PhonyTarget')
27 env.Tool('InstallDir')
28
29 env.Help("""
30 Additional top-level build targets:
31
32 prepare      Create all target files not part of the repository
33 default      Build all default targets (like calling scons with no arguments)
34 examples     Build all examples
35 all_tests    Build and run unit tests for all modules
36 all_docs     Build documentation for all modules
37 all          Build everything
38 install_all  Install SENF into $$PREFIX
39 deb          Build debian source and binary package
40 debsrc       Build debian source package
41 debbin       Build debian binary package
42 linklint     Check links of doxygen documentation with 'linklint'
43 fixlinks     Fix broken links in doxygen documentation
44 valgrind     Run all tests under valgrind/memcheck
45 """)
46
47 env.Replace(
48    PKGDRAW                = 'doclib/pkgdraw',
49 )
50
51 env.Append(
52    ENV                    = { 'PATH' : os.environ.get('PATH') },
53    CLEAN_PATTERNS         = [ '*~', '#*#', '*.pyc', 'semantic.cache', '.sconsign*' ],
54
55    CPPPATH                = [ '#' ],
56    LOCALLIBDIR            = '#',
57    LIBPATH                = [ '$LOCALLIBDIR' ],
58    LIBS                   = [ '$LIBSENF$LIBADDSUFFIX', 'rt', '$BOOSTREGEXLIB', 
59                               '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB', '$BOOSTFSLIB' ], 
60    TEST_EXTRA_LIBS        = [  ],
61
62    PREFIX                 = '#/dist',
63    LIBINSTALLDIR          = '$PREFIX${syslayout and "/lib" or ""}',
64    BININSTALLDIR          = '$PREFIX${syslayout and "/bin" or ""}',
65    INCLUDEINSTALLDIR      = '$PREFIX${syslayout and "/include" or ""}',
66    CONFINSTALLDIR         = '${syslayout and "$LIBINSTALLDIR/senf" or "$PREFIX"}',
67    OBJINSTALLDIR          = '$CONFINSTALLDIR',
68    DOCINSTALLDIR          = '$PREFIX${syslayout and "/share/doc/senf" or "/manual"}',
69    SCONSINSTALLDIR        = '$CONFINSTALLDIR/site_scons',
70
71    CPP_INCLUDE_EXTENSIONS = [ '.h', '.hh', '.ih', '.mpp', '.cci', '.ct', '.cti' ],
72    CPP_EXCLUDE_EXTENSIONS = [ '.test.hh' ],
73
74    # These options are insane. Only useful for inline debugging. Need at least 1G free RAM
75    INLINE_OPTS_DEBUG      = [ '-finline-limit=20000', '-fvisibility-inlines-hidden', 
76                               '-fno-inline-functions', '-Winline' 
77                               '--param','large-function-growth=10000',
78                               '--param', 'large-function-insns=10000', 
79                               '--param','inline-unit-growth=10000' ],
80    INLINE_OPTS_NORMAL     = [ '-finline-limit=5000' ],
81    INLINE_OPTS            = [ '$INLINE_OPTS_NORMAL' ],
82    CXXFLAGS               = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long', '$INLINE_OPTS',
83                               '$CXXFLAGS_' ],
84    CXXFLAGS_              = senfutil.BuildTypeOptions('CXXFLAGS'),
85    CXXFLAGS_final         = [ '-O3' ],
86    CXXFLAGS_normal        = [ '-O0', '-g' ],
87    CXXFLAGS_debug         = [ '$CXXFLAGS_normal' ],
88
89    CPPDEFINES             = [ '$expandLogOption', '$CPPDEFINES_' ],
90    expandLogOption        = senfutil.expandLogOption,
91    CPPDEFINES_            = senfutil.BuildTypeOptions('CPPDEFINES'),
92    CPPDEFINES_final       = [ ],
93    CPPDEFINES_normal      = [ 'SENF_DEBUG' ],
94    CPPDEFINES_debug       = [ '$CPPDEFINES_normal' ],
95
96    LINKFLAGS              = [ '-rdynamic', '$LINKFLAGS_' ],
97    LINKFLAGS_             = senfutil.BuildTypeOptions('LINKFLAGS'),
98    LINKFLAGS_final        = [ ],
99    LINKFLAGS_normal       = [ '-Wl,-S' ],
100    LINKFLAGS_debug        = [ '-g' ],
101 )
102
103 env.SetDefault(
104     LIBSENF   = "senf",
105     final     = False,
106     debug     = False,
107     syslayout = False
108 )
109
110 # Set variables from command line
111 senfutil.parseArguments(
112     env,
113     BoolVariable('final', 'Build final (optimized) build', False),
114     BoolVariable('debug', 'Link in debug symbols', False),
115     BoolVariable('syslayout', 'Install in to system layout directories (lib/, include/ etc)', False),
116 )
117
118 Export('env')
119
120 # Create Doxyfile.local otherwise doxygen will barf on this non-existent file
121 # Create it even when cleaning, to silence the doxygen builder warnings
122 if not os.path.exists("Doxyfile.local"):
123     Execute(Touch("Doxyfile.local"))
124
125 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp") \
126    and not os.environ.get("SCONS") and COMMAND_LINE_TARGETS != [ 'prepare' ]:
127     env.Execute([ "scons prepare" ])
128
129 # Load SConscripts
130
131 SConscriptChdir(0)
132 SConscript("debian/SConscript")
133 SConscriptChdir(1)
134 if os.path.exists('SConscript.local') : SConscript('SConscript.local')
135 SConscript("senf/SConscript")
136 SConscript("Examples/SConscript")
137 SConscript("HowTos/SConscript")
138 SConscript("doclib/SConscript")
139
140 ###########################################################################
141 # Define build targets
142
143 #### doc
144 env.Depends(SENFSCons.Doxygen(env), env.Value(env['ENV']['REVISION']))
145
146 #### libsenf.a
147 libsenf = env.Library("$LOCALLIBDIR/${LIBSENF}${LIBADDSUFFIX}", env['ALLOBJECTS'])
148 env.Default(libsenf)
149 env.Install('$LIBINSTALLDIR', libsenf)
150
151 def create(target, source, env): 
152     file(str(target[0]), 'w').write(source[0].get_contents()+"\n")
153 env['BUILDERS']['CreateFile'] = Builder(action = create)
154
155 conf = env.CreateFile("${LOCALLIBDIR}/${LIBSENF}${LIBADDSUFFIX}.conf", 
156                       env.Value(env.subst("$_CPPDEFFLAGS")))
157 env.Default(conf)
158 env.Install('$CONFINSTALLDIR', conf)
159
160 #### install_all, default, all_tests, all
161 env.Install('${SCONSINSTALLDIR}', 'site_scons/senfutil.py')
162
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' ])
167
168 #### prepare
169 env.PhonyTarget('prepare', [], [])
170
171 #### valgrind
172 env.PhonyTarget('valgrind', [ 'all_tests' ], [ """
173     find -name .test.bin 
174         | while read test; do
175             echo;
176             echo "Running $$test";
177             echo;
178             valgrind --tool=memcheck --error-exitcode=99 --suppressions=valgrind.sup 
179                 $$test $BOOSTTESTARGS;
180             [ $$? -ne 99 ] || exit 1;
181         done
182 """.replace("\n"," ") ])
183
184 #### clean
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'))
189
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) ])
195
196 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
197     Execute(Touch(".prepare-stamp"))