Fix debian package build
[senf.git] / site_scons / 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, senf_paths = []):
25     senf_paths.extend(('senf', '../senf', os.path.dirname(os.path.dirname(__file__))))
26     env.Append( LIBS           = [ 'senf', 'rt', '$BOOSTREGEXLIB',
27                                    '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB',
28                                    '$BOOSTFSLIB' ],
29                 BOOSTREGEXLIB  = 'boost_regex',
30                 BOOSTIOSTREAMSLIB = 'boost_iostreams',
31                 BOOSTSIGNALSLIB = 'boost_signals',
32                 BOOSTFSLIB = 'boost_filesystem',
33                 CXXFLAGS       = [ '-Wno-long-long',
34                                    '${"$CXXFLAGS_"+(final and "final" or "debug")}',
35                                    '${profile and ("-g","-pg") or None}' ],
36                 LINKFLAGS      = [ '${"$LINKFLAGS_"+(final and "final" or "debug")}',
37                                    '${profile and "-pg" or None}' ],
38                 SENF_BUILDOPTS = [ '-j%s' % (env.GetOption('num_jobs') or "1") ],
39                 CXXFLAGS_debug  = [ '-O0', '-g', '-fno-inline' ],
40                 LINKFLAGS_debug = [ '-g', '-rdynamic' ],
41                 
42                 expandLogOption = expandLogOption,
43                 CPPDEFINES      = [ '$expandLogOptions' ],
44                 )
45
46     # Add command-line options: 'LOGLEVELS' and 'final'
47     opts = Options()
48     opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: <stream>|[<area>]|<level> ...',
49               '${"$LOGLEVELS_"+(final and "final" or "debug")}' )
50     opts.Add( BoolOption('final', 'Build final (optimized) build', False) )
51     opts.Add( BoolOption('debug', 'Link in debug symbols', False) )
52     opts.Add( BoolOption('profile', 'Add profile information', False) )
53     opts.Update(env)
54
55     env.Help(opts.GenerateHelpText(env))
56
57     # If we have a symbolic link (or directory) 'senf', we use it as our
58     # senf repository
59     for path in senf_paths:
60         if os.path.exists(os.path.join(path,"senf/config.hh")):
61             print "\nUsing SENF in '%s/'\n" % os.path.abspath(path)
62             env.Append( LIBPATH = [ path ],
63                         CPPPATH = [ path ],
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             #env.Default(
69             #    env.AlwaysBuild(
70             #        env.Command('senf/libsenf.a', [],  [ 'scons -C %s $SENF_BUILDOPTS libsenf.a' % os.path.realpath('senf')])))
71             break
72     else:
73         print '\nUsing global SENF\n'