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