Import SCons-1.2.0 into repository and magically use own scons
[senf.git] / SConstruct
1 # -*- python -*-
2
3 import sys, glob, os.path, fnmatch
4 import SENFSCons, senfutil
5
6 ###########################################################################
7 # Load utilities and setup libraries and configure build
8
9 env = Environment()
10
11 env.Decider('MD5-timestamp')
12 env.EnsureSConsVersion(1,2)
13
14 # Load all the local SCons tools
15 env.Tool('Doxygen')
16 env.Tool('Dia2Png')
17 env.Tool('PkgDraw')
18 env.Tool('InstallSubdir')
19 env.Tool('CopyToDir')
20 env.Tool('Boost')
21 env.Tool('CombinedObject')
22 env.Tool('PhonyTarget')
23 env.Tool('InstallDir')
24
25 env.Help("""
26 Additional top-level build targets:
27
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
33 all          Build everything
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 valgrind     Run all tests under valgrind/memcheck
41 """)
42
43 env.Append(
44    ENV                    = { 'PATH' : os.environ.get('PATH') },
45    CLEAN_PATTERNS         = [ '*~', '#*#', '*.pyc', 'semantic.cache', '.sconsign*' ],
46
47    CPPPATH                = [ '#' ],
48    LOCALLIBDIR            = '#',
49    LIBPATH                = [ '$LOCALLIBDIR' ],
50    LIBS                   = [ '$LIBSENF$LIBADDSUFFIX', 'rt', '$BOOSTREGEXLIB', 
51                               '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB', '$BOOSTFSLIB' ], 
52    TEST_EXTRA_LIBS        = [  ],
53
54    PREFIX                 = '#/dist',
55    LIBINSTALLDIR          = '$PREFIX${syslayout and "/lib" or ""}',
56    BININSTALLDIR          = '$PREFIX${syslayout and "/bin" or ""}',
57    INCLUDEINSTALLDIR      = '$PREFIX${syslayout and "/include" or ""}',
58    CONFINSTALLDIR         = '${syslayout and "$LIBINSTALLDIR/senf" or "$PREFIX"}',
59    OBJINSTALLDIR          = '$CONFINSTALLDIR',
60    DOCINSTALLDIR          = '$PREFIX${syslayout and "/share/doc/senf" or "/manual"}',
61    SCONSINSTALLDIR        = '$CONFINSTALLDIR/site_scons',
62
63    CPP_INCLUDE_EXTENSIONS = [ '.h', '.hh', '.ih', '.mpp', '.cci', '.ct', '.cti' ],
64    CPP_EXCLUDE_EXTENSIONS = [ '.test.hh' ],
65
66    # These options are insane. Only useful for inline debugging. Need at least 1G free RAM
67    INLINE_OPTS_DEBUG      = [ '-finline-limit=20000', '-fvisibility-inlines-hidden', 
68                               '-fno-inline-functions', '-Winline' 
69                               '--param','large-function-growth=10000',
70                               '--param', 'large-function-insns=10000', 
71                               '--param','inline-unit-growth=10000' ],
72    INLINE_OPTS_NORMAL     = [ '-finline-limit=5000' ],
73    INLINE_OPTS            = [ '$INLINE_OPTS_NORMAL' ],
74    CXXFLAGS               = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long', '$INLINE_OPTS',
75                               '$CXXFLAGS_' ],
76    CXXFLAGS_              = senfutil.BuildTypeOptions('CXXFLAGS'),
77    CXXFLAGS_final         = [ '-O3' ],
78    CXXFLAGS_normal        = [ '-O0', '-g' ],
79    CXXFLAGS_debug         = [ '$CXXFLAGS_normal' ],
80
81    CPPDEFINES             = [ '$expandLogOption', '$CPPDEFINES_' ],
82    expandLogOption        = senfutil.expandLogOption,
83    CPPDEFINES_            = senfutil.BuildTypeOptions('CPPDEFINES'),
84    CPPDEFINES_final       = [ ],
85    CPPDEFINES_normal      = [ 'SENF_DEBUG' ],
86    CPPDEFINES_debug       = [ '$CPPDEFINES_normal' ],
87
88    LINKFLAGS              = [ '-rdynamic', '$LINKFLAGS_' ],
89    LINKFLAGS_             = senfutil.BuildTypeOptions('LINKFLAGS'),
90    LINKFLAGS_final        = [ ],
91    LINKFLAGS_normal       = [ '-Wl,-S' ],
92    LINKFLAGS_debug        = [ '-g' ],
93 )
94
95 env.SetDefault(
96     LIBSENF   = "senf",
97     final     = False,
98     debug     = False,
99     syslayout = False
100 )
101
102 # Set variables from command line
103 senfutil.parseArguments(
104     env,
105     BoolVariable('final', 'Build final (optimized) build', False),
106     BoolVariable('debug', 'Link in debug symbols', False),
107     BoolVariable('syslayout', 'Install in to system layout directories (lib/, include/ etc)', False),
108 )
109
110 Export('env')
111
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"))
116
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" ])
120
121 # Load SConscripts
122
123 SConscriptChdir(0)
124 SConscript("debian/SConscript")
125 SConscriptChdir(1)
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")
131
132 ###########################################################################
133 # Define build targets
134
135 #### doc
136 env.Depends(SENFSCons.Doxygen(env), env.Value(env['ENV']['REVISION']))
137
138 #### libsenf.a
139 libsenf = env.Library("$LOCALLIBDIR/${LIBSENF}${LIBADDSUFFIX}", env['ALLOBJECTS'])
140 env.Default(libsenf)
141 env.Install('$LIBINSTALLDIR', libsenf)
142
143 def create(target, source, env): 
144     file(str(target[0]), 'w').write(source[0].get_contents()+"\n")
145 env['BUILDERS']['CreateFile'] = Builder(action = create)
146
147 conf = env.CreateFile("${LOCALLIBDIR}/${LIBSENF}${LIBADDSUFFIX}.conf", 
148                       env.Value(env.subst("$_CPPDEFFLAGS")))
149 env.Default(conf)
150 env.Install('$CONFINSTALLDIR', conf)
151
152 #### install_all, default, all_tests, all
153 env.Install('${SCONSINSTALLDIR}', [ 'site_scons/__init__.py',
154                                     'site_scons/senfutil.py',
155                                     'site_scons/yaptu.py' ])
156 env.InstallDir('${SCONSINSTALLDIR}', [ 'site_scons/site_tools', 'site_scons/lib' ],
157                FILTER_SUFFIXES=[ '','.css','.pl','.py','.sh','.sty','.xml','.xsl','.yap' ])
158 env.Install('${INCLUDEINSTALLDIR}', 'boost')
159
160 env.Alias('install_all', env.FindInstalledFiles())
161 env.Alias('default', DEFAULT_TARGETS)
162 env.Alias('all_tests', env.FindAllBoostUnitTests())
163 env.Alias('all', [ 'default', 'all_tests', 'examples', 'all_docs' ])
164
165 #### prepare
166 env.PhonyTarget('prepare', [], [])
167
168 #### valgrind
169 env.PhonyTarget('valgrind', [ 'all_tests' ], [ """
170     find -name .test.bin 
171         | while read test; do
172             echo;
173             echo "Running $$test";
174             echo;
175             valgrind --tool=memcheck --error-exitcode=99 --suppressions=valgrind.sup 
176                 $$test $BOOSTTESTARGS;
177             [ $$? -ne 99 ] || exit 1;
178         done
179 """.replace("\n"," ") ])
180
181 #### clean
182 env.Clean('all', '.prepare-stamp')
183 env.Clean('all', libsenf)
184 env.Clean('all', env.Dir('linklint')) # env.Dir to disambiguate from linklint PhonyTarget
185 env.Clean('all', env.Dir('dist'))
186
187 if env.GetOption('clean'):
188     env.Clean('all', [ os.path.join(path,f)
189                        for path, subdirs, files in os.walk('.')
190                        for pattern in env['CLEAN_PATTERNS']
191                        for f in fnmatch.filter(files,pattern) ])
192
193 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
194     Execute(Touch(".prepare-stamp"))