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