Move debian and documentation specific parts of SConstruct into SConscript files
[senf.git] / SConstruct
1 # -*- python -*-
2
3 import sys, glob, os.path, datetime, pwd, time, fnmatch, string
4 sys.path.append(Dir('#/senfscons').abspath)
5 sys.path.append(Dir('#/doclib').abspath)
6 import SENFSCons, senfutil
7
8 ###########################################################################
9 # Load utilities and setup libraries and configure build
10
11 SENFSCons.UseBoost()
12 SENFSCons.UseSTLPort()
13 env = SENFSCons.MakeEnvironment()
14
15 env.Help("""
16 Additional top-level build targets:
17
18 prepare      Create all source files not part of the repository
19 all_tests    Build and run unit tests for all modules
20 all_docs     Build documentation for all modules
21 all          Build everything
22 install_all  Install SENF into $PREFIX
23 deb          Build debian source and binary package
24 debsrc       Build debian source package
25 debbin       Build debian binary package
26 linklint     Check links of doxygen documentation with 'linklint'
27 fixlinks     Fix broken links in doxygen documentation
28 valgrind     Run all tests under valgrind/memcheck
29 """)
30
31 # Options used to debug inlining:
32 #
33 # INLINE_OPTS = [ '-finline-limit=20000', '--param','large-function-growth=10000',
34 #                 '--param', 'large-function-insns=10000', '--param','inline-unit-growth=10000',
35 #                 '-fvisibility-inlines-hidden', '-fno-inline-functions', '-Winline' ]
36 #
37 # BEWARE: You need lots of ram to compile with these settings (approx 1G)
38
39 INLINE_OPTS = [ '-finline-limit=5000' ]
40
41 env.Append(
42    CPPPATH         = [ '#/include' ],
43    CXXFLAGS        = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long' ] + INLINE_OPTS,
44    LIBS            = [ 'rt', '$BOOSTREGEXLIB', '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB',
45                        '$BOOSTFSLIB' ],
46    TEST_EXTRA_LIBS = [ ],
47    ENV             = { 'PATH' : os.environ.get('PATH') },
48    CLEAN_PATTERNS  = [ '*~', '#*#', '*.pyc', 'semantic.cache', '.sconsign', '.sconsign.dblite' ],
49 )
50
51 env.SetDefault(
52     LIBSENF = "senf"
53 )
54
55 # Parse the log option command line parameter into the SENF_LOG_CONF macro
56 senfutil.setLogOption(env)
57
58 Export('env')
59
60 # Create Doxyfile.local otherwise doxygen will barf on this non-existent file
61 # Create it even when cleaning, to silence the doxygen builder warnings
62 if not os.path.exists("Doxyfile.local"):
63     Execute(Touch("Doxyfile.local"))
64
65 # Create local_config.h
66 if not env.GetOption('clean') and not os.path.exists("local_config.hh"):
67     Execute(Touch("local_config.hh"))
68
69 ###########################################################################
70 # Define build targets
71
72 # Before defining any targets, check wether this is the first build in
73 # pristine directory tree. If so, call 'scons prepare' so the dependencies
74 # created later are correct
75
76 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp") \
77    and not os.environ.get("SCONS") and COMMAND_LINE_TARGETS != [ 'prepare' ]:
78     env.Execute([ "scons prepare" ])
79 env.Clean('all', '.prepare-stamp')
80
81 # Load SConscripts. Need to load debian and doclib first (they change the global environment)
82 SConscript("debian/SConscript")
83 SConscript("doclib/SConscript")
84 SConscript(list(set(glob.glob("*/SConscript")) - set(("debian/SConscript", "doclib/SConscript"))))
85
86 # Define the main targets
87 SENFSCons.StandardTargets(env)
88 SENFSCons.GlobalTargets(env)
89
90 env.Depends( SENFSCons.Doxygen(env), env.Value(env['ENV']['REVISION']) )
91
92 libsenf = env.Library(env.subst("$LIBSENF$LIBADDSUFFIX"), env['ALLOBJECTS'])
93 env.Default(libsenf)
94 env.Clean('all', libsenf)
95 env.Alias('default', libsenf)
96
97 SENFSCons.InstallIncludeFiles(env, [ 'config.hh' ])
98 env.Alias('install_all', env.Install('$LIBINSTALLDIR', libsenf))
99
100 if env.GetOption('clean'):
101     env.Clean('all', [ os.path.join(path,f)
102                        for path, subdirs, files in os.walk('.')
103                        for pattern in env['CLEAN_PATTERNS']
104                        for f in fnmatch.filter(files,pattern) ])
105
106 SENFSCons.PhonyTarget(env, 'prepare', [ 'true' ])
107
108 SENFSCons.PhonyTarget(env, 'valgrind', [ """
109     find -name .test.bin 
110         | while read test; do
111             echo;
112             echo "Running $$test";
113             echo;
114             valgrind --tool=memcheck --error-exitcode=99 --suppressions=valgrind.sup 
115                 $$test $BOOSTTESTARGS;
116             [ $$? -ne 99 ] || exit 1;
117         done
118 """.replace("\n"," ") ], [ 'all_tests' ])
119
120 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
121     Execute(Touch(".prepare-stamp"))