c704a1f9f4fa800de3d9395c06ce624a5b3023f4
[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', 'readline', 'rt', '$BOOSTREGEXLIB', '$BOOSTIOSTREAMSLIB' ],
12                 BOOSTREGEXLIB  = 'boost_regex',
13                 BOOSTIOSTREAMSLIB = 'boost_iostreams',
14                 CXXFLAGS       = [ '-Wno-long-long',
15                                    '${"$CXXFLAGS_"+(final and "final" or "debug")}' ],
16                 LINKFLAGS      = [ '${"$LINKFLAGS_"+(final and "final" or "debug")}' ],
17                 SENF_BUILDOPTS = [ '-j%s' % (env.GetOption('num_jobs') or "1") ],
18                 CXXFLAGS_debug  = [ '-O0', '-g', '-fno-inline' ],
19                 LINKFLAGS_debug = [ '-g', '-rdynamic' ],
20                 )
21
22     # Parse LOGLEVELS parameter
23     def parseLogOption(value):
24         stream, area, level = ( x.strip() for x in value.strip().split('|') )
25         stream = ''.join('(%s)' % x for x in stream.split('::') )
26         if area : area = ''.join( '(%s)' % x for x in area.split('::') )
27         else    : area = '(_)'
28         return '(( %s,%s,%s ))' % (stream,area,level)
29
30     def expandLogOption(target, source, env, for_signature):
31         return ' '.join( parseLogOption(x) for x in env.subst('$LOGLEVELS').split() )
32
33     # Add command-line options: 'LOGLEVELS' and 'final'
34     opts = Options()
35     opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: <stream>|[<area>]|<level> ...',
36               '${"$LOGLEVELS_"+(final and "final" or "debug")}' )
37     opts.Add( BoolOption('final', 'Build final (optimized) build', False) )
38     opts.Update(env)
39
40     if env.subst('$LOGLEVELS'):
41         env.Append( expandLogOption=expandLogOption )
42         env.Append( CPPDEFINES = { 'SENF_LOG_CONF': '$expandLogOption' } )
43
44     env.Help(opts.GenerateHelpText(env))
45
46     # If we have a symbolic link (or directory) 'senf', we use it as our
47     # senf repository
48     if os.path.exists('senf'):
49         print "\nUsing SENF in './senf'\n"
50         env.Append( LIBPATH = [ 'senf' ],
51                     CPPPATH = [ 'senf/include' ],
52                     SENF_BUILDOPTS = [ '${final and "final=1" or None}' ],
53                     CPPDEFINES = [ '${not(final) and "SENF_DEBUG" or None}' ] )
54
55         env.Default(
56             env.AlwaysBuild(
57                 env.Command('senf/libsenf.a', [],  [ 'scons -C %s $SENF_BUILDOPTS libsenf.a' % os.path.realpath('senf')])))
58     else:
59         print '\nUsing global SENF\n'