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