forked from openwsn-berkeley/openwsn-fw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
170 lines (148 loc) · 5.87 KB
/
SConstruct
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
import os
import sys
import SCons
#============================ banner ==========================================
banner = []
banner += [""]
banner += [" ___ _ _ _ ___ _ _ "]
banner += ["| . | ___ ___ ._ _ | | | |/ __>| \ |"]
banner += ["| | || . \/ ._>| ' || | | |\__ \| |"]
banner += ["`___'| _/\___.|_|_||__/_/ <___/|_\_|"]
banner += [" |_| openwsn.org"]
banner += [""]
banner = '\n'.join(banner)
print banner
#============================ options =========================================
#===== options
command_line_options = {
'board': ['telosb','wsn430v14','wsn430v13b','gina','z1','pc','python'],
'toolchain': ['mspgcc','iar','iar-proj','gcc'],
'fet_version': ['2','3'],
'verbose': ['0','1'],
'fastsim': ['1','0'],
}
def validate_option(key, value, env):
if key not in command_line_options:
raise ValueError("Unknown switch {0}.".format(key))
if value not in command_line_options[key]:
raise ValueError("Unknown {0} \"{1}\". Options are {2}.\n\n".format(key,value,','.join(command_line_options[key])))
command_line_vars = Variables()
command_line_vars.AddVariables(
(
'board', # key
'Board to build for.', # help
command_line_options['board'][0], # default
validate_option, # validator
None, # converter
),
(
'toolchain', # key
'Toolchain to use.', # help
command_line_options['toolchain'][0], # default
validate_option, # validator
None, # converter
),
(
'jtag', # key
'Location of the board to JTAG the binary to.', # help
'', # default
None, # validator
None, # converter
),
(
'fet_version', # key
'Firmware version running on the MSP-FET430uif.', # help
command_line_options['fet_version'][0], # default
validate_option, # validator
int, # converter
),
(
'bootload', # key
'Location of the board to bootload the binary on.',# help
'', # default
None, # validator
None, # converter
),
(
'verbose', # key
'Print complete compile/link comand.', # help
command_line_options['verbose'][0], # default
validate_option, # validator
int, # converter
),
(
'fastsim', # key
'Compiles the firmware for fast simulation.', # help
command_line_options['fastsim'][0], # default
validate_option, # validator
int, # converter
),
)
if os.name=='nt':
env = Environment(
tools = ['mingw'],
variables = command_line_vars,
)
else:
env = Environment(
variables = command_line_vars,
)
#===== help text
Help("\nUsage: scons board=<b> toolchain=<tc> project\n\nWhere:")
Help(command_line_vars.GenerateHelpText(env))
def default(env,target,source): print SCons.Script.help_text
Default(env.Command('default', None, default))
#============================ verbose =========================================
if not env['verbose']:
env[ 'CCCOMSTR'] = "Compiling $TARGET"
env[ 'SHCCCOMSTR'] = "Compiling (shared) $TARGET"
env[ 'ARCOMSTR'] = "Archiving $TARGET"
env['RANLIBCOMSTR'] = "Indexing $TARGET"
env[ 'LINKCOMSTR'] = "Linking $TARGET"
env['SHLINKCOMSTR'] = "Linking (shared) $TARGET"
#============================ load SConscript's ===============================
# initialize targets
env['targets'] = {
'all': [],
'all_std': [],
'all_bsp': [],
'all_drv': [],
'all_oos': [],
}
# include docs SConscript
# which will discover targets for this board/toolchain
env.SConscript(
os.path.join('docs','SConscript'),
exports = ['env'],
)
# include main SConscript
# which will discover targets for this board/toolchain
env.SConscript(
'SConscript',
exports = ['env'],
)
# declare target group alias
for k,v in env['targets'].items():
Alias(k,v)
#============================ admin targets ===================================
#===== list
def listFunction(env,target,source):
output = []
output += ['\n']
output += ['Avaiable targets for board={0} toolchain={1}'.format(env['board'],env['toolchain'])]
output += ['\n']
for k,v in env['targets'].items():
output += [' - {0}'.format(k)]
for t in v:
output += [' - {0}'.format(t)]
output = '\n'.join(output)
print output
list = env.Command('list', None, listFunction)
AlwaysBuild(list)
Alias('list',list)
#===== env
def envFunction(env,target,source):
print env.Dump()
envCommand = env.Command('env', None, envFunction)
AlwaysBuild(envCommand)
Alias('env',envCommand)