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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
#!/usr/bin/python
import os
import sys
import platform
import subprocess
import multiprocessing
# help message
def helpmsg(script):
helpstr = '''
Usage:
build:
python %s <targetbuild>
Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_unsecured_with_ra, linux_secured_with_ra, linux_unsecured_with_rd, linux_secured_with_rd, android, arduino, tizen, simulator, darwin, windows, msys
Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\", \"linux_secured_with_ra\", \"linux_secured_with_rd\", \"linux_unsecured_with_mq\", \"linux_secured_with_tcp\" & \"linux_unsecured_with_tcp\" & \"linux_unsecured_with_rd\".
Any selection will build both debug and release versions of all available targets in the scope you've selected.
To choose any specific command, please use the SCons commandline directly. Please refer to [IOTIVITY_REPO]/Readme.scons.txt.
clean:
python %s -c
'''
print (helpstr % (script, script))
sys.exit()
def call_scons(build_options, extra_option_str):
"""
This function formats and runs a scons command
Arguments:
build_options -- {Dictionary} build flags (keys) associated with values;
extra_option_str -- {String} extra options to append to scons command
"""
cmd_line = "scons VERBOSE=" + VERBOSE
for key in build_options:
cmd_line += " " + key + "=" + str(build_options[key])
cmd_line += " " + str(extra_option_str)
print ("Running : " + cmd_line)
sys.stdout.flush()
exit_code = subprocess.Popen([cmd_line], shell=True).wait()
if exit_code != 0:
exit(exit_code)
def build_all(flag, extra_option_str):
if platform.system() == "Linux":
build_linux_unsecured(flag, extra_option_str)
build_linux_secured(flag, extra_option_str)
build_linux_unsecured_with_ra(flag, extra_option_str)
build_linux_secured_with_ra(flag, extra_option_str)
build_linux_unsecured_with_rm(flag, extra_option_str)
build_linux_unsecured_with_rd(flag, extra_option_str)
build_linux_secured_with_rd(flag, extra_option_str)
build_linux_unsecured_with_mq(flag, extra_option_str)
build_linux_unsecured_with_tcp(flag, extra_option_str)
build_linux_secured_with_tcp(flag, extra_option_str)
build_simulator(flag, extra_option_str)
build_android(flag, extra_option_str)
build_arduino(flag, extra_option_str)
build_tizen(flag, extra_option_str)
if platform.system() == "Windows":
build_windows(flag, extra_option_str)
if platform.system() == "Darwin":
build_darwin(flag, extra_option_str)
def build_linux(flag, extra_option_str):
build_linux_unsecured(flag, extra_option_str)
build_linux_secured(flag, extra_option_str)
def build_linux_unsecured(flag, extra_option_str):
print ("*********** Build for linux ************")
build_options = {
'RELEASE':flag,
}
call_scons(build_options, extra_option_str)
def build_linux_secured_with_tcp(flag, extra_option_str):
print ("*********** Build for linux with Secured TCP ************")
build_options = {
'RELEASE':flag,
'WITH_TCP': 1,
'WITH_CLOUD':1,
'SECURED':1,
}
call_scons(build_options, extra_option_str)
def build_linux_unsecured_with_tcp(flag, extra_option_str):
print ("*********** Build for linux with TCP ************")
build_options = {
'RELEASE':flag,
'WITH_TCP': 1,
'TARGET_TRANSPORT': 'IP',
}
call_scons(build_options, extra_option_str)
def build_linux_unsecured_with_rm(flag, extra_option_str):
print ("*********** Build for linux with RoutingManager************")
build_options = {
'ROUTING':'GW',
'RELEASE':flag,
}
call_scons(build_options, extra_option_str)
def build_linux_secured(flag, extra_option_str):
print ("*********** Build for linux with Security *************")
build_options = {
'RELEASE':flag,
'SECURED':1,
}
call_scons(build_options, extra_option_str)
def build_linux_unsecured_with_ra(flag, extra_option_str):
print ("*********** Build for linux With Remote Access *************")
build_options = {
'RELEASE':flag,
'WITH_RA':1,
'WITH_RA_IBB':1,
}
call_scons(build_options, extra_option_str)
def build_linux_secured_with_ra(flag, extra_option_str):
print ("*********** Build for linux With Remote Access & Security ************")
build_options = {
'RELEASE':flag,
'WITH_RA':1,
'WITH_RA_IBB':1,
'SECURED':1,
}
call_scons(build_options, extra_option_str)
def build_linux_unsecured_with_rd(flag, extra_option_str):
print ("*********** Build for linux With Resource Directory *************")
build_options = {
'RELEASE':flag,
'RD_MODE':'all',
}
call_scons(build_options, extra_option_str)
def build_linux_secured_with_rd(flag, extra_option_str):
print ("*********** Build for linux With Resource Directory & Security ************")
build_options = {
'RELEASE':flag,
'RD_MODE':'all',
'SECURED':1,
}
call_scons(build_options, extra_option_str)
def build_linux_unsecured_with_mq(flag, extra_option_str):
print ("*********** Build for linux With Message Queue ************")
build_options = {
'RELEASE':flag,
'WITH_MQ':'PUB,SUB,BROKER',
}
call_scons(build_options, extra_option_str)
def build_linux_unsecured_with_tcp(flag, extra_option_str):
print ("*********** Build for linux With tcp ************")
build_options = {
'RELEASE':flag,
'WITH_TCP':'1',
}
call_scons(build_options, extra_option_str)
def build_android(flag, extra_option_str):
# Note: for android, as oic-resource uses C++11 feature stoi and to_string,
# it requires gcc-4.9, currently only android-ndk-r10(for linux)
# and windows android-ndk-r10(64bit target version) support these features.
print ("*********** Build for android armeabi *************")
build_options = {
'TARGET_OS':'android',
'TARGET_ARCH':'armeabi',
'RELEASE':flag,
}
call_scons(build_options, extra_option_str)
def build_android_x86(flag, extra_option_str):
print ("*********** Build for android x86 *************")
build_options = {
'TARGET_OS':'android',
'TARGET_ARCH':'x86',
'RELEASE':flag,
'TARGET_TRANSPORT':'IP',
}
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BT'
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BLE'
call_scons(build_options, extra_option_str)
def build_android_x86_with_rm(flag, extra_option_str):
print ("*********** Build for android x86 with Routing Manager *************")
build_options = {
'TARGET_OS':'android',
'TARGET_ARCH':'x86',
'ROUTING':'GW',
'RELEASE':flag,
'TARGET_TRANSPORT':'IP',
}
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BT'
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BLE'
call_scons(build_options, extra_option_str)
def build_android_armeabi(flag, extra_option_str):
print ("*********** Build for android armeabi *************")
build_options = {
'TARGET_OS':'android',
'TARGET_ARCH':'armeabi',
'RELEASE':flag,
'TARGET_TRANSPORT':'IP',
}
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BT'
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BLE'
call_scons(build_options, extra_option_str)
def build_android_armeabi_with_rm(flag, extra_option_str):
print ("*********** Build for android armeabi with Routing Manager*************")
build_options = {
'TARGET_OS':'android',
'TARGET_ARCH':'armeabi',
'ROUTING':'GW',
'RELEASE':flag,
'TARGET_TRANSPORT':'IP',
}
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BT'
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BLE'
call_scons(build_options, extra_option_str)
def build_arduino(flag, extra_option_str):
print ("*********** Build for arduino avr *************")
extra_option_str = "resource " + extra_option_str
build_options = {
'TARGET_OS':'arduino',
'UPLOAD':'false',
'BOARD':'mega',
'TARGET_ARCH':'avr',
'TARGET_TRANSPORT':'IP',
'SHIELD':'ETH',
'RELEASE':flag,
}
call_scons(build_options, extra_option_str)
build_options['SHIELD'] = 'WIFI'
call_scons(build_options, extra_option_str)
build_options['TARGET_TRANSPORT'] = 'BLE'
build_options['SHIELD'] = 'RBL_NRF8001'
call_scons(build_options, extra_option_str)
print ("*********** Build for arduino arm *************")
build_options['BOARD'] = 'arduino_due_x'
build_options['TARGET_ARCH'] = 'arm'
build_options['TARGET_TRANSPORT'] = 'IP'
build_options['SHIELD'] = 'ETH'
call_scons(build_options, extra_option_str)
build_options['SHIELD'] = 'WIFI'
call_scons(build_options, extra_option_str)
# BLE support for the Arduino Due is currently unavailable.
def build_tizen(flag, extra_option_str):
print ("*********** Build for Tizen *************")
cmd_line = "/bin/sh " + os.getcwd() + "/gbsbuild.sh"
print ("Running : " + cmd_line)
subprocess.Popen([cmd_line], shell=True).wait()
print ("*********** Build for Tizen octbstack lib and sample *************")
extra_option_str = "-f resource/csdk/stack/samples/tizen/build/SConscript " + extra_option_str
build_options = {
'TARGET_OS':'tizen',
'TARGET_TRANSPORT':'IP',
'LOGGING':'true',
'RELEASE':flag,
}
call_scons(build_options, extra_option_str)
print ("*********** Build for Tizen octbstack lib and sample with Security*************")
build_options['SECURED'] = 1
call_scons(build_options, extra_option_str)
print ("*********** Build for Tizen octbstack lib and sample with Routing Manager*************")
del build_options['SECURED']
build_options['ROUTING'] = 'GW'
call_scons(build_options, extra_option_str)
# Mac OS and iOS
def build_darwin(flag, extra_option_str):
print ("*********** Build for OSX *************")
build_options = {
'TARGET_OS':'darwin',
'SYS_VERSION':'10.9',
'RELEASE':flag,
}
call_scons(build_options, extra_option_str)
print ("*********** Build for IOS i386 *************")
build_options = {
'TARGET_OS':'ios',
'TARGET_ARCH':'i386',
'SYS_VERSION':'7.0',
'RELEASE':flag,
}
call_scons(build_options, extra_option_str)
print ("*********** Build for IOS x86_64 *************")
build_options['TARGET_ARCH'] = 'x86_64'
call_scons(build_options, extra_option_str)
print ("*********** Build for IOS armv7 *************")
build_options['TARGET_ARCH'] = 'armv7'
call_scons(build_options, extra_option_str)
print ("*********** Build for IOS armv7s *************")
build_options['TARGET_ARCH'] = 'armv7s'
call_scons(build_options, extra_option_str)
print ("*********** Build for IOS arm64 *************")
build_options['TARGET_ARCH'] = 'arm64'
call_scons(build_options, extra_option_str)
# Windows
def build_windows(flag, extra_option_str):
print ("*********** Build for Windows *************")
os.environ["SCONSFLAGS"] = ""
build_options = {
'TARGET_OS':'windows',
'TARGET_ARCH':'amd64',
'RELEASE':flag,
'WITH_RA':0,
'TARGET_TRANSPORT':'IP',
'SECURED':1,
'WITH_TCP':0,
'BUILD_SAMPLE':'ON',
'LOGGING':'off',
'TEST':1,
'RD_MODE':'all',
}
call_scons(build_options, extra_option_str)
# Windows msys
def build_msys(flag, extra_option_str):
print ("*********** Build for msys_nt *************")
os.environ["SCONSFLAGS"] = ""
build_options = {
'TARGET_OS':'msys_nt',
'TARGET_ARCH':'x86_64',
'RELEASE':flag,
'WITH_RA':0,
'TARGET_TRANSPORT':'IP',
'SECURED':1,
'WITH_TCP':0,
'BUILD_SAMPLE':'ON',
'LOGGING':'off',
'TEST':1,
'RD_MODE':'all',
}
call_scons(build_options, extra_option_str)
def build_simulator(flag, extra_option_str):
print ("*********** Build for simulator plugin *************")
build_options = {
'SIMULATOR':1,
'RELEASE':flag,
}
call_scons(build_options, extra_option_str)
def unit_tests():
print ("*********** Unit test Start *************")
build_options = {
'RELEASE':'false',
'LOGGING':'true'
}
extra_option_str = "resource -c"
call_scons(build_options, extra_option_str)
build_options = {
'LOGGING':'true',
'RELEASE':'false',
}
extra_option_str = "resource"
call_scons(build_options, extra_option_str)
build_options = {
'TEST':1,
'RELEASE':'false',
'LOGGING':'true',
}
call_scons(build_options, extra_option_str)
build_options = {
'TEST':1,
'SECURED':1,
'RELEASE':'false',
'LOGGING':'true',
}
call_scons(build_options, extra_option_str)
print ("*********** Unit test Stop *************")
# Main module starts here
if os.getenv("SCONSFLAGS", "") == "":
os.environ["SCONSFLAGS"] = "-Q -j " + str(multiprocessing.cpu_count())
arg_num = len(sys.argv)
script_name = sys.argv[0]
# May be overridden in user's shell
VERBOSE = os.getenv("VERBOSE", "1")
if arg_num == 1:
build_all("true", "")
build_all("false", "")
unit_tests()
elif arg_num == 2:
if str(sys.argv[1]) == '-c':
build_all("true", "-c")
build_all("false", "-c")
elif str(sys.argv[1]) == "all":
build_all("true", "")
build_all("false", "")
unit_tests()
elif str(sys.argv[1]) == "linux":
build_linux("true", "")
build_linux("false", "")
elif str(sys.argv[1]) == "linux_unsecured":
build_linux_unsecured("true", "")
build_linux_unsecured("false", "")
build_linux_unsecured_with_rm("true", "")
build_linux_unsecured_with_rm("false", "")
elif str(sys.argv[1]) == "linux_secured":
build_linux_secured("true", "")
build_linux_secured("false", "")
elif str(sys.argv[1]) == "linux_unsecured_with_ra":
build_linux_unsecured_with_ra("true", "")
build_linux_unsecured_with_ra("false", "")
elif str(sys.argv[1]) == "linux_secured_with_ra":
build_linux_secured_with_ra("true", "")
build_linux_secured_with_ra("false", "")
elif str(sys.argv[1]) == "linux_unsecured_with_rd":
build_linux_unsecured_with_rd("true", "")
build_linux_unsecured_with_rd("false", "")
elif str(sys.argv[1]) == "linux_secured_with_rd":
build_linux_secured_with_rd("true", "")
build_linux_secured_with_rd("false", "")
elif str(sys.argv[1]) == "linux_unsecured_with_mq":
build_linux_unsecured_with_mq("true", "")
build_linux_unsecured_with_mq("false", "")
elif str(sys.argv[1]) == "linux_unsecured_with_tcp":
build_linux_unsecured_with_tcp("true", "")
build_linux_unsecured_with_tcp("false", "")
elif str(sys.argv[1]) == "linux_secured_with_tcp":
build_linux_secured_with_tcp("false", "")
build_linux_secured_with_tcp("true", "")
elif str(sys.argv[1]) == "android":
build_android("true", "")
build_android("false", "")
elif str(sys.argv[1]) == "android_x86":
build_android_x86("true", "")
build_android_x86("false", "")
build_android_x86_with_rm("true", "")
build_android_x86_with_rm("false", "")
elif str(sys.argv[1]) == "android_armeabi":
build_android_armeabi("true", "")
build_android_armeabi("false", "")
build_android_armeabi_with_rm("true", "")
build_android_armeabi_with_rm("false", "")
elif str(sys.argv[1]) == "arduino":
build_arduino("true", "")
build_arduino("false", "")
elif str(sys.argv[1]) == "windows":
build_windows("true", "")
build_windows("false", "")
elif str(sys.argv[1]) == "msys":
build_msys("true", "")
build_msys("false", "")
elif str(sys.argv[1]) == "tizen":
build_tizen("true", "")
build_tizen("false", "")
elif str(sys.argv[1]) == "simulator":
build_simulator("true", "")
build_simulator("false", "")
elif str(sys.argv[1]) == "darwin":
build_darwin("true", "")
build_darwin("false", "")
elif str(sys.argv[1]) == "unit_tests":
unit_tests()
else:
helpmsg(script_name)
else:
helpmsg(script_name)
print ("===================== done =====================")
|