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