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