Move debian and documentation specific parts of SConstruct into SConscript files
[senf.git] / senfscons / senfutil.py
1 import os.path
2 from SCons.Script import *
3
4 def setLogOption(env):
5     # Parse LOGLEVELS parameter
6     def parseLogOption(value):
7         stream, area, level = ( x.strip() for x in value.strip().split('|') )
8         stream = ''.join('(%s)' % x for x in stream.split('::') )
9         if area : area = ''.join( '(%s)' % x for x in area.split('::') )
10         else    : area = '(_)'
11         return '(( %s,%s,%s ))' % (stream,area,level)
12
13     def expandLogOption(target, source, env, for_signature):
14         return ' '.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )
15
16     if env.subst('$LOGLEVELS'):
17         env.Append( expandLogOption=expandLogOption )
18         env.Append( CPPDEFINES = { 'SENF_LOG_CONF': '$expandLogOption' } )
19
20
21 ###########################################################################
22 # This looks much more complicated than it is: We do three things here:
23 # a) switch between final or debug options
24 # b) parse the LOGLEVELS parameter into the correct SENF_LOG_CONF syntax
25 # c) check for a local SENF, set options accordingly and update that SENF if needed
26
27 def SetupForSENF(env):
28     env.Append( LIBS           = [ 'senf', 'rt', '$BOOSTREGEXLIB',
29                                    '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB',
30                                    '$BOOSTFSLIB' ],
31                 BOOSTREGEXLIB  = 'boost_regex',
32                 BOOSTIOSTREAMSLIB = 'boost_iostreams',
33                 BOOSTSIGNALSLIB = 'boost_signals',
34                 BOOSTFSLIB = 'boost_filesystem',
35                 CXXFLAGS       = [ '-Wno-long-long',
36                                    '${"$CXXFLAGS_"+(final and "final" or "debug")}',
37                                    '${profile and ("-g","-pg") or None}' ],
38                 LINKFLAGS      = [ '${"$LINKFLAGS_"+(final and "final" or "debug")}',
39                                    '${profile and "-pg" or None}' ],
40                 SENF_BUILDOPTS = [ '-j%s' % (env.GetOption('num_jobs') or "1") ],
41                 CXXFLAGS_debug  = [ '-O0', '-g', '-fno-inline' ],
42                 LINKFLAGS_debug = [ '-g', '-rdynamic' ],
43                 )
44
45     # Add command-line options: 'LOGLEVELS' and 'final'
46     opts = Options()
47     opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: <stream>|[<area>]|<level> ...',
48               '${"$LOGLEVELS_"+(final and "final" or "debug")}' )
49     opts.Add( BoolOption('final', 'Build final (optimized) build', False) )
50     opts.Add( BoolOption('debug', 'Link in debug symbols', False) )
51     opts.Add( BoolOption('profile', 'Add profile information', False) )
52     opts.Update(env)
53
54     env.Help(opts.GenerateHelpText(env))
55
56     setLogOption(env)
57
58     # If we have a symbolic link (or directory) 'senf', we use it as our
59     # senf repository
60     if os.path.exists('senf'):
61         print "\nUsing SENF in './senf'\n"
62         env.Append( LIBPATH = [ 'senf' ],
63                     CPPPATH = [ 'senf/include' ],
64                     SENF_BUILDOPTS = [ '${final and "final=1" or None}',
65                                        '${debug and "debug=1" or None}',
66                                        '${profile and "profile=1" or None}' ],
67                     CPPDEFINES = [ '${not(final) and "SENF_DEBUG" or None}' ] )
68
69         #env.Default(
70         #    env.AlwaysBuild(
71         #        env.Command('senf/libsenf.a', [],  [ 'scons -C %s $SENF_BUILDOPTS libsenf.a' % os.path.realpath('senf')])))
72     else:
73         print '\nUsing global SENF\n'