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