Merge "Merge branch 'master' into notification-service" into notification-service
[platform/upstream/iotivity.git] / auto_build.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import platform
6 import subprocess
7 import multiprocessing
8
9 # help message
10 def helpmsg(script):
11     helpstr = '''
12 Usage:
13     build:
14         python %s <targetbuild>
15         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
16         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_unsecured_with_tcp\" & \"linux_unsecured_with_rd\".
17         Any selection will build both debug and release versions of all available targets in the scope you've selected.
18         To choose any specific command, please use the SCons commandline directly. Please refer to [IOTIVITY_REPO]/Readme.scons.txt.
19     clean:
20         python %s -c
21     '''
22     print (helpstr % (script, script))
23     sys.exit()
24
25 def call_scons(build_options, extra_option_str):
26     """
27     This function formats and runs a scons command
28     Arguments:
29     build_options    -- {Dictionary} build flags (keys) associated with values;
30     extra_option_str -- {String} extra options to append to scons command
31     """
32     cmd_line = "scons VERBOSE=" + VERBOSE
33     for key in build_options:
34         cmd_line += " " + key + "=" + str(build_options[key])
35
36     cmd_line += " " + str(extra_option_str)
37
38     print ("Running : " + cmd_line)
39     subprocess.Popen([cmd_line], shell=True).wait()
40
41 def build_all(flag, extra_option_str):
42     if platform.system() == "Linux":
43         build_linux_unsecured(flag, extra_option_str)
44         build_linux_secured(flag, extra_option_str)
45         build_linux_unsecured_with_ra(flag, extra_option_str)
46         build_linux_secured_with_ra(flag, extra_option_str)
47         build_linux_unsecured_with_rm(flag, extra_option_str)
48         build_linux_unsecured_with_rd(flag, extra_option_str)
49         build_linux_secured_with_rd(flag, extra_option_str)
50         build_linux_unsecured_with_mq(flag, extra_option_str)
51         build_linux_unsecured_with_tcp(flag, extra_option_str)
52         build_simulator(flag, extra_option_str)
53
54     build_android(flag, extra_option_str)
55     build_arduino(flag, extra_option_str)
56     build_tizen(flag, extra_option_str)
57
58     if platform.system() == "Windows":
59         build_windows(flag, extra_option_str)
60
61     if platform.system() == "Darwin":
62         build_darwin(flag, extra_option_str)
63
64 def build_linux(flag, extra_option_str):
65     build_linux_unsecured(flag, extra_option_str)
66     build_linux_secured(flag, extra_option_str)
67
68 def build_linux_unsecured(flag, extra_option_str):
69     print ("*********** Build for linux ************")
70     build_options = {
71                         'RELEASE':flag,
72                     }
73     call_scons(build_options, extra_option_str)
74
75 def build_linux_unsecured_with_tcp(flag, extra_option_str):
76     print ("*********** Build for linux with TCP ************")
77     build_options = {
78                         'RELEASE':flag,
79                         'WITH_TCP': 1,
80                         'TARGET_TRANSPORT': 'IP',
81                     }
82     call_scons(build_options, extra_option_str)
83
84 def build_linux_unsecured_with_rm(flag, extra_option_str):
85     print ("*********** Build for linux with RoutingManager************")
86     build_options = {
87                         'ROUTING':'GW',
88                         'RELEASE':flag,
89                     }
90     call_scons(build_options, extra_option_str)
91
92 def build_linux_secured(flag, extra_option_str):
93     print ("*********** Build for linux with Security *************")
94     build_options = {
95                         'RELEASE':flag,
96                         'SECURED':1,
97                     }
98     call_scons(build_options, extra_option_str)
99
100 def build_linux_unsecured_with_ra(flag, extra_option_str):
101     print ("*********** Build for linux With Remote Access *************")
102     build_options = {
103                         'RELEASE':flag,
104                         'WITH_RA':1,
105                         'WITH_RA_IBB':1,
106                     }
107     call_scons(build_options, extra_option_str)
108
109 def build_linux_secured_with_ra(flag, extra_option_str):
110     print ("*********** Build for linux With Remote Access & Security ************")
111     build_options = {
112                         'RELEASE':flag,
113                         'WITH_RA':1,
114                         'WITH_RA_IBB':1,
115                         'SECURED':1,
116                     }
117     call_scons(build_options, extra_option_str)
118
119 def build_linux_unsecured_with_rd(flag, extra_option_str):
120     print ("*********** Build for linux With Resource Directory *************")
121     build_options = {
122                         'RELEASE':flag,
123                         'WITH_RD':1,
124                     }
125     call_scons(build_options, extra_option_str)
126
127 def build_linux_secured_with_rd(flag, extra_option_str):
128     print ("*********** Build for linux With Resource Directory & Security ************")
129     build_options = {
130                         'RELEASE':flag,
131                         'WITH_RD':1,
132                         'SECURED':1,
133                     }
134     call_scons(build_options, extra_option_str)
135
136 def build_linux_unsecured_with_mq(flag, extra_option_str):
137     print ("*********** Build for linux With Message Queue ************")
138     build_options = {
139                         'RELEASE':flag,
140                         'WITH_MQ':'PUB,SUB,BROKER',
141                     }
142     call_scons(build_options, extra_option_str)
143
144 def build_linux_unsecured_with_tcp(flag, extra_option_str):
145     print ("*********** Build for linux With tcp ************")
146     build_options = {
147                         'RELEASE':flag,
148                         'WITH_TCP':'1',
149                     }
150     call_scons(build_options, extra_option_str)
151
152 def build_android(flag, extra_option_str):
153     # Note: for android, as oic-resource uses C++11 feature stoi and to_string,
154     # it requires gcc-4.9, currently only android-ndk-r10(for linux)
155     # and windows android-ndk-r10(64bit target version) support these features.
156
157     build_android_x86(flag, extra_option_str)
158     build_android_x86_with_rm(flag, extra_option_str)
159     build_android_armeabi(flag, extra_option_str)
160     build_android_armeabi_with_rm(flag, extra_option_str)
161
162 def build_android_x86(flag, extra_option_str):
163     print ("*********** Build for android x86 *************")
164     build_options = {
165                         'TARGET_OS':'android',
166                         'TARGET_ARCH':'x86',
167                         'RELEASE':flag,
168                         'TARGET_TRANSPORT':'IP',
169                     }
170     call_scons(build_options, extra_option_str)
171
172     build_options['TARGET_TRANSPORT'] = 'BT'
173     call_scons(build_options, extra_option_str)
174
175     build_options['TARGET_TRANSPORT'] = 'BLE'
176     call_scons(build_options, extra_option_str)
177
178 def build_android_x86_with_rm(flag, extra_option_str):
179     print ("*********** Build for android x86 with Routing Manager *************")
180     build_options = {
181                         'TARGET_OS':'android',
182                         'TARGET_ARCH':'x86',
183                         'ROUTING':'GW',
184                         'RELEASE':flag,
185                         'TARGET_TRANSPORT':'IP',
186                     }
187     call_scons(build_options, extra_option_str)
188
189     build_options['TARGET_TRANSPORT'] = 'BT'
190     call_scons(build_options, extra_option_str)
191
192     build_options['TARGET_TRANSPORT'] = 'BLE'
193     call_scons(build_options, extra_option_str)
194
195 def build_android_armeabi(flag, extra_option_str):
196     print ("*********** Build for android armeabi *************")
197     build_options = {
198                         'TARGET_OS':'android',
199                         'TARGET_ARCH':'armeabi',
200                         'RELEASE':flag,
201                         'TARGET_TRANSPORT':'IP',
202                     }
203     call_scons(build_options, extra_option_str)
204
205     build_options['TARGET_TRANSPORT'] = 'BT'
206     call_scons(build_options, extra_option_str)
207
208     build_options['TARGET_TRANSPORT'] = 'BLE'
209     call_scons(build_options, extra_option_str)
210
211 def build_android_armeabi_with_rm(flag, extra_option_str):
212     print ("*********** Build for android armeabi with Routing Manager*************")
213     build_options = {
214                         'TARGET_OS':'android',
215                         'TARGET_ARCH':'armeabi',
216                         'ROUTING':'GW',
217                         'RELEASE':flag,
218                         'TARGET_TRANSPORT':'IP',
219                     }
220     call_scons(build_options, extra_option_str)
221
222     build_options['TARGET_TRANSPORT'] = 'BT'
223     call_scons(build_options, extra_option_str)
224
225     build_options['TARGET_TRANSPORT'] = 'BLE'
226     call_scons(build_options, extra_option_str)
227
228 def build_arduino(flag, extra_option_str):
229     print ("*********** Build for arduino avr *************")
230     extra_option_str = "resource " + extra_option_str
231     build_options = {
232                         'TARGET_OS':'arduino',
233                         'UPLOAD':'false',
234                         'BOARD':'mega',
235                         'TARGET_ARCH':'avr',
236                         'TARGET_TRANSPORT':'IP',
237                         'SHIELD':'ETH',
238                         'RELEASE':flag,
239                     }
240     call_scons(build_options, extra_option_str)
241
242     build_options['SHIELD'] = 'WIFI'
243     call_scons(build_options, extra_option_str)
244
245     build_options['TARGET_TRANSPORT'] = 'BLE'
246     build_options['SHIELD']           = 'RBL_NRF8001'
247     call_scons(build_options, extra_option_str)
248
249     print ("*********** Build for arduino arm *************")
250     build_options['BOARD']            = 'arduino_due_x'
251     build_options['TARGET_ARCH']      = 'arm'
252     build_options['TARGET_TRANSPORT'] = 'IP'
253     build_options['SHIELD']           = 'ETH'
254     call_scons(build_options, extra_option_str)
255
256     build_options['SHIELD'] = 'WIFI'
257     call_scons(build_options, extra_option_str)
258
259     # BLE support for the Arduino Due is currently unavailable.
260
261 def build_tizen(flag, extra_option_str):
262     print ("*********** Build for Tizen *************")
263     cmd_line = "/bin/sh " + os.getcwd() + "/gbsbuild.sh"
264     print ("Running : " + cmd_line)
265     subprocess.Popen([cmd_line], shell=True).wait()
266
267     print ("*********** Build for Tizen octbstack lib and sample *************")
268     extra_option_str = "-f resource/csdk/stack/samples/tizen/build/SConscript " + extra_option_str
269     build_options = {
270                         'TARGET_OS':'tizen',
271                         'TARGET_TRANSPORT':'IP',
272                         'LOGGING':'true',
273                         'RELEASE':flag,
274                     }
275     call_scons(build_options, extra_option_str)
276
277     print ("*********** Build for Tizen octbstack lib and sample with Security*************")
278     build_options['SECURED'] = 1
279     call_scons(build_options, extra_option_str)
280
281     print ("*********** Build for Tizen octbstack lib and sample with Routing Manager*************")
282     del build_options['SECURED']
283     build_options['ROUTING'] = 'GW'
284     call_scons(build_options, extra_option_str)
285
286 # Mac OS and iOS
287 def build_darwin(flag, extra_option_str):
288     print ("*********** Build for OSX *************")
289     build_options = {
290                         'TARGET_OS':'darwin',
291                         'SYS_VERSION':'10.9',
292                         'RELEASE':flag,
293                     }
294     call_scons(build_options, extra_option_str)
295
296     print ("*********** Build for IOS i386 *************")
297     build_options = {
298                         'TARGET_OS':'ios',
299                         'TARGET_ARCH':'i386',
300                         'SYS_VERSION':'7.0',
301                         'RELEASE':flag,
302                     }
303     call_scons(build_options, extra_option_str)
304
305     print ("*********** Build for IOS x86_64 *************")
306     build_options['TARGET_ARCH'] = 'x86_64'
307     call_scons(build_options, extra_option_str)
308
309     print ("*********** Build for IOS armv7 *************")
310     build_options['TARGET_ARCH'] = 'armv7'
311     call_scons(build_options, extra_option_str)
312
313     print ("*********** Build for IOS armv7s *************")
314     build_options['TARGET_ARCH'] = 'armv7s'
315     call_scons(build_options, extra_option_str)
316
317     print ("*********** Build for IOS arm64 *************")
318     build_options['TARGET_ARCH'] = 'arm64'
319     call_scons(build_options, extra_option_str)
320
321 # Windows
322 def build_windows(flag, extra_option_str):
323     print ("*********** Build for Windows *************")
324     os.environ["SCONSFLAGS"] = ""
325     build_options = {
326                         'TARGET_OS':'windows',
327                         'TARGET_ARCH':'amd64',
328                         'RELEASE':flag,
329                         'WITH_RA':0,
330                         'TARGET_TRANSPORT':'IP',
331                         'SECURED':1,
332                         'WITH_TCP':0,
333                         'BUILD_SAMPLE':'ON',
334                         'LOGGING':'off',
335                         'TEST':1,
336                         'WITH_RD':1,
337                     }
338     call_scons(build_options, extra_option_str)
339
340 # Windows msys
341 def build_msys(flag, extra_option_str):
342     print ("*********** Build for msys_nt *************")
343     os.environ["SCONSFLAGS"] = ""
344     build_options = {
345                         'TARGET_OS':'msys_nt',
346                         'TARGET_ARCH':'x86_64',
347                         'RELEASE':flag,
348                         'WITH_RA':0,
349                         'TARGET_TRANSPORT':'IP',
350                         'SECURED':1,
351                         'WITH_TCP':0,
352                         'BUILD_SAMPLE':'ON',
353                         'LOGGING':'off',
354                         'TEST':1,
355                         'WITH_RD':1,
356                     }
357     call_scons(build_options, extra_option_str)
358
359 def build_simulator(flag, extra_option_str):
360     print ("*********** Build for simulator plugin *************")
361     build_options = {
362                         'SIMULATOR':1,
363                         'RELEASE':flag,
364                     }
365     call_scons(build_options, extra_option_str)
366
367 def unit_tests():
368     print ("*********** Unit test Start *************")
369     build_options = {
370                         'RELEASE':'false',
371                     }
372     extra_option_str = "resource -c"
373     call_scons(build_options, extra_option_str)
374
375     build_options = {
376                         'LOGGING':'false',
377                         'RELEASE':'false',
378                     }
379     extra_option_str = "resource"
380     call_scons(build_options, extra_option_str)
381
382     build_options = {
383                         'TEST':1,
384                         'RELEASE':'false',
385                     }
386     extra_option_str = "resource"
387     call_scons(build_options, extra_option_str)
388
389     print ("*********** Unit test Stop *************")
390
391 # Main module starts here
392 if os.getenv("SCONSFLAGS", "") == "":
393     os.environ["SCONSFLAGS"] = "-Q -j " + str(multiprocessing.cpu_count())
394
395 arg_num     = len(sys.argv)
396 script_name = sys.argv[0]
397
398 # May be overridden in user's shell
399 VERBOSE = os.getenv("VERBOSE", "1")
400
401 if arg_num == 1:
402     build_all("true", "")
403     build_all("false", "")
404     unit_tests()
405
406 elif arg_num == 2:
407     if str(sys.argv[1]) == '-c':
408         build_all("true", "-c")
409         build_all("false", "-c")
410
411     elif str(sys.argv[1]) == "all":
412         build_all("true", "")
413         build_all("false", "")
414         unit_tests()
415
416     elif str(sys.argv[1]) == "linux":
417         build_all("true", "")
418         build_all("false", "")
419
420     elif str(sys.argv[1]) == "linux_unsecured":
421         build_linux_unsecured("true", "")
422         build_linux_unsecured("false", "")
423         build_linux_unsecured_with_rm("true", "")
424         build_linux_unsecured_with_rm("false", "")
425
426     elif str(sys.argv[1]) == "linux_secured":
427         build_linux_secured("true", "")
428         build_linux_secured("false", "")
429
430     elif str(sys.argv[1]) == "linux_unsecured_with_ra":
431         build_linux_unsecured_with_ra("true", "")
432         build_linux_unsecured_with_ra("false", "")
433
434     elif str(sys.argv[1]) == "linux_secured_with_ra":
435         build_linux_secured_with_ra("true", "")
436         build_linux_secured_with_ra("false", "")
437
438     elif str(sys.argv[1]) == "linux_unsecured_with_rd":
439         build_linux_unsecured_with_rd("true", "")
440         build_linux_unsecured_with_rd("false", "")
441
442     elif str(sys.argv[1]) == "linux_secured_with_rd":
443         build_linux_secured_with_rd("true", "")
444         build_linux_secured_with_rd("false", "")
445
446     elif str(sys.argv[1]) == "linux_unsecured_with_mq":
447         build_linux_unsecured_with_mq("true", "")
448         build_linux_unsecured_with_mq("false", "")
449
450     elif str(sys.argv[1]) == "linux_unsecured_with_tcp":
451         build_linux_unsecured_with_tcp("true", "")
452         build_linux_unsecured_with_tcp("false", "")
453
454     elif str(sys.argv[1]) == "android":
455         build_android("true", "")
456         build_android("false", "")
457
458     elif str(sys.argv[1]) == "android_x86":
459         build_android_x86("true", "")
460         build_android_x86("false", "")
461         build_android_x86_with_rm("true", "")
462         build_android_x86_with_rm("false", "")
463
464     elif str(sys.argv[1]) == "android_armeabi":
465         build_android_armeabi("true", "")
466         build_android_armeabi("false", "")
467         build_android_armeabi_with_rm("true", "")
468         build_android_armeabi_with_rm("false", "")
469
470     elif str(sys.argv[1]) == "arduino":
471         build_arduino("true", "")
472         build_arduino("false", "")
473
474     elif str(sys.argv[1]) == "windows":
475         build_windows("true", "")
476         build_windows("false", "")
477
478     elif str(sys.argv[1]) == "msys":
479         build_msys("true", "")
480         build_msys("false", "")
481
482     elif str(sys.argv[1]) == "tizen":
483         build_tizen("true", "")
484         build_tizen("false", "")
485
486     elif str(sys.argv[1]) == "simulator":
487         build_simulator("true", "")
488         build_simulator("false", "")
489
490     elif str(sys.argv[1]) == "darwin":
491         build_darwin("true", "")
492         build_darwin("false", "")
493
494     elif str(sys.argv[1]) == "unit_tests":
495         unit_tests()
496
497     else:
498         helpmsg(script_name)
499 else:
500         helpmsg(script_name)
501
502 print ("===================== done =====================")