File: SConstruct

package info (click to toggle)
alljoyn-thin-client-1509 15.09a-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,240 kB
  • sloc: ansic: 55,937; cpp: 2,995; python: 361; sh: 174; makefile: 39
file content (198 lines) | stat: -rw-r--r-- 8,581 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import os
import platform
import re

#######################################################
# Custom Configure functions
#######################################################
def CheckCommand(context, cmd):
    context.Message('Checking for %s command...' % cmd)
    r = WhereIs(cmd)
    context.Result(r is not None)
    return r

def CheckAJLib(context, ajlib, ajheader, sconsvarname, ajdistpath):
    prog = "#include <%s>\nint main(void) { return 0; }" % ajheader
    context.Message('Checking for AllJoyn library %s...' % ajlib)

    prevLIBS = context.env['LIBS']
    prevLIBPATH = context.env.get('LIBPATH', [])
    prevCPPPATH = context.env.get('CPPPATH', [])

    # Check if library is in standard system locations
    context.env.Append(LIBS = ajlib)
    defpath = ''  # default path is a system directory
    if not context.TryLink(prog, '.c'):
        # Check if library is in project default location
        context.env.Append(LIBPATH = ajdistpath + '/lib', CPPPATH = ajdistpath + '/include')
        if context.TryLink(prog, '.c'):
            defpath = ajdistpath  # default path is the dist directory
        # Remove project default location from LIBPATH and CPPPATH
        context.env.Replace(LIBPATH = prevLIBPATH, CPPPATH = prevCPPPATH)

    vars = Variables()
    vars.Add(PathVariable(sconsvarname,
                          'Path to %s dist directory' % ajlib,
                          os.environ.get('AJ_%s' % sconsvarname, defpath),
                          lambda k, v, e : v == '' or PathVariable.PathIsDir(k, v, e)))
    vars.Update(context.env)
    Help(vars.GenerateHelpText(context.env))

    # Get the actual library path to use ('' == system path, may be same as ajdistpath)
    libpath = env.get(sconsvarname, '')
    if libpath is not '':
        libpath = str(context.env.Dir(libpath))
        # Add the user specified (or ajdistpath) to LIBPATH and CPPPATH
        context.env.Append(LIBPATH = libpath + '/lib', CPPPATH = libpath + '/include')

    # The real test for the library
    r = context.TryLink(prog, '.c')
    if not r:
        context.env.Replace(LIBS = prevLIBS, LIBPATH = prevLIBPATH, CPPPATH = prevCPPPATH)
    context.Result(r)
    return r

#######################################################
# Initialize our build environment
#######################################################
env = Environment()
Export('env')

#######################################################
# Default target platform
#######################################################
if platform.system() == 'Linux':
    default_target = 'linux'
elif platform.system() == 'Windows':
    default_target = 'win32'
elif platform.system() == 'Darwin':
    default_target = 'darwin'

#######################################################
# Build variables
#######################################################
debug_restrict_options = (
    '0', 'AJ_DEBUG_OFF',
    '1', 'AJ_DEBUG_ERROR',
    '2', 'AJ_DEBUG_WARN',
    '3', 'AJ_DEBUG_INFO',
    '4', 'AJ_DEBUG_DUMP',
    '5', 'AJ_DEBUG_ALL'
)
target_options = [ t.split('.')[-1] for t in os.listdir('.') if re.match('^SConscript\.target\.[-_0-9A-Za-z]+$', t) ]

vars = Variables()
vars.Add(BoolVariable('V',              'Build verbosity',             False))
vars.Add(EnumVariable('TARG',           'Target platform variant',     os.environ.get('AJ_TARG', default_target), allowed_values = target_options))
vars.Add(EnumVariable('VARIANT',        'Build variant',               os.environ.get('AJ_VARIANT', 'debug'),     allowed_values = ('debug', 'release')))
vars.Add(EnumVariable('DEBUG_RESTRICT', 'Set compiled in debug level', os.environ.get('AJ_DEBUG_RESTRICT'),       allowed_values = debug_restrict_options))
vars.Add('CC',  'C Compiler override')
vars.Add('CXX', 'C++ Compiler override')
vars.Add(EnumVariable('NDEBUG', 'Override NDEBUG default for release variant', 'defined', allowed_values=('defined', 'undefined')))
vars.Update(env)
Help(vars.GenerateHelpText(env))

#######################################################
# Setup non-verbose output
#######################################################
if not env['V']:
    env.Replace( CCCOMSTR =     '\t[CC]      $SOURCE',
                 SHCCCOMSTR =   '\t[CC-SH]   $SOURCE',
                 CXXCOMSTR =    '\t[CXX]     $SOURCE',
                 SHCXXCOMSTR =  '\t[CXX-SH]  $SOURCE',
                 LINKCOMSTR =   '\t[LINK]    $TARGET',
                 SHLINKCOMSTR = '\t[LINK-SH] $TARGET',
                 JAVACCOMSTR =  '\t[JAVAC]   $SOURCE',
                 JARCOMSTR =    '\t[JAR]     $TARGET',
                 ARCOMSTR =     '\t[AR]      $TARGET',
                 ASCOMSTR =     '\t[AS]      $TARGET',
                 RANLIBCOMSTR = '\t[RANLIB]  $TARGET',
                 INSTALLSTR =   '\t[INSTALL] $TARGET',
                 WSCOMSTR =     '\t[WS]      $WS' )

#######################################################
# Load target setup
#######################################################
env['build'] = True
env['build_shared'] = False
env['build_unit_tests'] = True
env['connectivity_options'] = [ 'tcp' ]

env.SConscript('SConscript.target.$TARG')

vars = Variables()
vars.Add('CONNECTIVITY', 'Connectivity mechanism to connect to a routing node (any of ' + ', '.join(env['connectivity_options']) + ')', os.environ.get('AJ_CONNECTIVITY', ' '.join(env['connectivity_options'])))
vars.Update(env)
Help(vars.GenerateHelpText(env))
env['connectivity'] = [ opt.upper() for opt in env['connectivity_options'] if opt in env['CONNECTIVITY'].lower() ]

if len(env['connectivity']) == 0 and not GetOption('help'):
    print '*** Must enable at least one of %s' % ', '.join(env['connectivity_options'])
    Exit(1)

#######################################################
# Build Configuration
#######################################################
config = Configure(env, custom_tests = { 'CheckCommand' : CheckCommand,
                                         'CheckAJLib' : CheckAJLib })
found_ws = config.CheckCommand('uncrustify')
env = config.Finish()

#######################################################
# Compilation defines
#######################################################
if env.has_key('DEBUG_RESTRICT'):
    env.Append(CPPDEFINES = { 'AJ_DEBUG_RESTRICT' : env['DEBUG_RESTRICT'] })
if env['VARIANT'] == 'release' and env['NDEBUG'] == 'defined':
    env.Append(CPPDEFINES = [ 'NDEBUG' ])

env.Append(CPPDEFINES = [ 'AJ_' + conn for conn in env['connectivity'] ])

#######################################################
# Include path
#######################################################
env.Append(CPPPATH = [ '#dist/include' ])

#######################################################
# Process commandline defines
#######################################################
env.Append(CPPDEFINES = [ v for k, v in ARGLIST if k.lower() == 'define' ])

#######################################################
# Install header files
#######################################################
env.Install('#dist/include/ajtcl', env.Glob('inc/*.h'))
env.Install('#dist/include/ajtcl', env.Glob('src/target/$TARG/aj_target.h'))
# Need to force a dpendency here because SCons can't follow nested
# #include dependencies otherwise
env.Depends('#build/$VARIANT', '#dist/include')

#######################################################
# Build the various parts
#######################################################
if env['build']:
    env.SConscript('src/SConscript',       variant_dir='#build/$VARIANT/src',       duplicate = 0)
    env.SConscript('samples/SConscript',   variant_dir='#build/$VARIANT/samples',   duplicate = 0)
    env.SConscript('test/SConscript',      variant_dir='#build/$VARIANT/test',      duplicate = 0)
    env.SConscript('unit_test/SConscript', variant_dir='#build/$VARIANT/unit_test', duplicate = 0)

#######################################################
# Run the whitespace checker
#######################################################
# Set the location of the uncrustify config file
if found_ws:
    import sys
    sys.path.append(os.getcwd() + '/tools')
    import whitespace

    def wsbuild(target, source, env):
        return whitespace.main([ env['WS'], os.getcwd() + '/tools/ajuncrustify.cfg' ])

    vars = Variables()
    vars.Add(EnumVariable('WS', 'Whitespace Policy Checker', os.environ.get('AJ_WS', 'off'), allowed_values = ('check', 'detail', 'fix', 'off')))

    vars.Update(config.env)
    Help(vars.GenerateHelpText(config.env))

    if env.get('WS', 'off') != 'off':
        env.Command('#ws_ajtcl', '#dist', Action(wsbuild, '$WSCOMSTR'))