Corrected empty body 'if' warning
[platform/upstream/iotivity.git] / auto_build.sh
1 #! /bin/bash
2
3 # Ideally we will capture the exit code of each step and try them all before failing
4 # the build script.  For now, use set -e and fail the build at first failure.
5 set -e
6
7 function build_all()
8 {
9         if [ $(uname -s) = "Linux" ]
10         then
11                 build_linux_unsecured $1 $2
12                 build_linux_secured $1 $2
13                 build_linux_unsecured_with_ra $1 $2
14                 build_linux_secured_with_ra $1 $2
15                 build_linux_unsecured_with_rm $1 $2
16                 build_linux_unsecured_with_rd $1 $2
17                 build_linux_secured_with_rd $1 $2
18                 build_simulator $1 $2
19         fi
20
21         build_android $1 $2
22
23         build_arduino $1 $2
24
25         build_tizen $1 $2
26
27         if [ $(uname -s) = "Darwin" ]
28         then
29                 build_darwin $1 $2
30         fi
31 }
32
33 function build_linux()
34 {
35         build_linux_unsecured $1 $2
36
37         build_linux_secured $1 $2
38 }
39
40 function build_linux_unsecured()
41 {
42         echo "*********** Build for linux ************"
43         scons RELEASE=$1 $2
44 }
45
46 function build_linux_unsecured_with_rm()
47 {
48         echo "*********** Build for linux with RoutingManager************"
49         scons ROUTING=GW RELEASE=$1 $2
50 }
51
52 function build_linux_secured()
53 {
54         echo "*********** Build for linux with Security *************"
55         scons RELEASE=$1 SECURED=1 $2
56 }
57
58 function build_linux_unsecured_with_ra()
59 {
60
61         echo "*********** Build for linux With Remote Access *************"
62         scons RELEASE=$1 WITH_RA=1 WITH_RA_IBB=1 $2
63 }
64
65 function build_linux_secured_with_ra()
66 {
67         echo "*********** Build for linux With Remote Access & Security ************"
68         scons RELEASE=$1 WITH_RA=1 WITH_RA_IBB=1 SECURED=1 $2
69 }
70
71 function build_linux_unsecured_with_rd()
72 {
73         echo "*********** Build for linux With Resource Directory *************"
74         scons RELEASE=$1 WITH_RD=1 $2
75 }
76
77 function build_linux_secured_with_rd()
78 {
79         echo "*********** Build for linux With Resource Directory & Security ************"
80         scons RELEASE=$1 WITH_RD=1 SECURED=1 $2
81 }
82
83 function build_android()
84 {
85         # Note: for android, as oic-resource uses C++11 feature stoi and to_string,
86         # it requires gcc-4.9, currently only android-ndk-r10(for linux)
87         # and windows android-ndk-r10(64bit target version) support these features.
88
89         build_android_x86 $1 $2
90         build_android_x86_with_rm $1 $2
91         build_android_armeabi $1 $2
92         build_android_armeabi_with_rm $1 $2
93 }
94
95 function build_android_x86()
96 {
97         echo "*********** Build for android x86 *************"
98         scons TARGET_OS=android TARGET_ARCH=x86 RELEASE=$1 TARGET_TRANSPORT=IP $2
99         scons TARGET_OS=android TARGET_ARCH=x86 RELEASE=$1 TARGET_TRANSPORT=BT $2
100         scons TARGET_OS=android TARGET_ARCH=x86 RELEASE=$1 TARGET_TRANSPORT=BLE $2
101 }
102
103 function build_android_x86_with_rm()
104 {
105         echo "*********** Build for android x86 with Routing Manager *************"
106         scons TARGET_OS=android TARGET_ARCH=x86 ROUTING=GW RELEASE=$1 TARGET_TRANSPORT=IP $2
107         scons TARGET_OS=android TARGET_ARCH=x86 ROUTING=GW RELEASE=$1 TARGET_TRANSPORT=BT $2
108         scons TARGET_OS=android TARGET_ARCH=x86 ROUTING=GW RELEASE=$1 TARGET_TRANSPORT=BLE $2
109 }
110
111 function build_android_armeabi()
112 {
113         echo "*********** Build for android armeabi *************"
114         scons TARGET_OS=android TARGET_ARCH=armeabi RELEASE=$1 TARGET_TRANSPORT=IP $2
115         scons TARGET_OS=android TARGET_ARCH=armeabi RELEASE=$1 TARGET_TRANSPORT=BT $2
116         scons TARGET_OS=android TARGET_ARCH=armeabi RELEASE=$1 TARGET_TRANSPORT=BLE $2
117 }
118
119 function build_android_armeabi_with_rm()
120 {
121         echo "*********** Build for android armeabi with Routing Manager*************"
122         scons TARGET_OS=android TARGET_ARCH=armeabi ROUTING=GW RELEASE=$1 TARGET_TRANSPORT=IP $2
123         scons TARGET_OS=android TARGET_ARCH=armeabi ROUTING=GW RELEASE=$1 TARGET_TRANSPORT=BT $2
124         scons TARGET_OS=android TARGET_ARCH=armeabi ROUTING=GW RELEASE=$1 TARGET_TRANSPORT=BLE $2
125 }
126
127 function build_arduino()
128 {
129         echo "*********** Build for arduino avr *************"
130         scons resource TARGET_OS=arduino UPLOAD=false BOARD=mega TARGET_ARCH=avr TARGET_TRANSPORT=IP SHIELD=ETH RELEASE=$1 $2
131         scons resource TARGET_OS=arduino UPLOAD=false BOARD=mega TARGET_ARCH=avr TARGET_TRANSPORT=IP SHIELD=WIFI RELEASE=$1 $2
132         scons resource TARGET_OS=arduino UPLOAD=false BOARD=mega TARGET_ARCH=avr TARGET_TRANSPORT=BLE SHIELD=RBL_NRF8001 RELEASE=$1 $2
133
134         echo "*********** Build for arduino arm *************"
135         scons resource TARGET_OS=arduino UPLOAD=false BOARD=arduino_due_x TARGET_ARCH=arm TARGET_TRANSPORT=IP SHIELD=ETH RELEASE=$1 $2
136         scons resource TARGET_OS=arduino UPLOAD=false BOARD=arduino_due_x TARGET_ARCH=arm TARGET_TRANSPORT=IP SHIELD=WIFI RELEASE=$1 $2
137         # BLE support for the Arduino Due is currently unavailable.
138 }
139
140 function build_tizen()
141 {
142         echo "*********** Build for Tizen *************"
143         ./gbsbuild.sh
144
145         echo "*********** Build for Tizen CA lib and sample *************"
146         scons -f resource/csdk/connectivity/build/tizen/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true RELEASE=$1 $2
147
148         echo "*********** Build for Tizen CA lib and sample with Security *************"
149         scons -f resource/csdk/connectivity/build/tizen/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true SECURED=1 RELEASE=$1 $2
150
151         echo "*********** Build for Tizen octbstack lib and sample *************"
152         scons -f resource/csdk/stack/samples/tizen/build/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true RELEASE=$1 $2
153
154         echo "*********** Build for Tizen octbstack lib and sample with Security*************"
155         scons -f resource/csdk/stack/samples/tizen/build/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true SECURED=1 RELEASE=$1 $2
156
157         echo "*********** Build for Tizen octbstack lib and sample with Routing Manager*************"
158         scons -f resource/csdk/stack/samples/tizen/build/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true ROUTING=GW RELEASE=$1 $2
159 }
160
161 function build_darwin() # Mac OSx and iOS
162 {
163         echo "*********** Build for OSX *************"
164         scons TARGET_OS=darwin SYS_VERSION=10.9 RELEASE=$1 $2
165
166         echo "*********** Build for IOS i386 *************"
167         scons TARGET_OS=ios TARGET_ARCH=i386 SYS_VERSION=7.0 RELEASE=$1 $2
168
169         echo "*********** Build for IOS x86_64 *************"
170         scons TARGET_OS=ios TARGET_ARCH=x86_64 SYS_VERSION=7.0 RELEASE=$1 $2
171
172         echo "*********** Build for IOS armv7 *************"
173         scons TARGET_OS=ios TARGET_ARCH=armv7 SYS_VERSION=7.0 RELEASE=$1 $2
174
175         echo "*********** Build for IOS armv7s *************"
176         scons TARGET_OS=ios TARGET_ARCH=armv7s SYS_VERSION=7.0 RELEASE=$1 $2
177
178         echo "*********** Build for IOS arm64 *************"
179         scons TARGET_OS=ios TARGET_ARCH=arm64 SYS_VERSION=7.0 RELEASE=$1 $2
180 }
181
182 function build_simulator()
183 {
184         echo "*********** Build for simulator plugin *************"
185         scons SIMULATOR=1 RELEASE=$1 $2
186 }
187
188 function unit_tests()
189 {
190         echo "*********** Unit test Start *************"
191         scons resource RELEASE=false -c
192         scons resource LOGGING=false RELEASE=false
193         scons resource TEST=1 RELEASE=false
194         echo "*********** Unit test Stop *************"
195 }
196
197 function  help()
198 {
199         echo "Usage:"
200         echo "  build:"
201         echo "     `basename $0` <target_build>"
202         echo "      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"
203         echo "      Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\", \"linux_secured_with_ra\", \"linux_secured_with_rd\" & \"linux_unsecured_with_rd\"."
204         echo "      Any selection will build both debug and release versions of all available targets in the scope you've"
205         echo "      selected. To choose any specific command, please use the SCons commandline directly. Please refer"
206         echo "      to [IOTIVITY_REPO]/Readme.scons.txt."
207         echo "  clean:"
208         echo "     `basename $0` -c"
209 }
210
211 # Suppress "Reading ..." message and enable parallel build
212 export SCONSFLAGS="-Q -j 4"
213
214 if [ $# -eq 1 ]
215 then
216         if [ $1 = '-c' ]
217         then
218                 build_all true $1
219                 build_all false $1
220                 exit 0
221         elif [ $1 = 'all' ]
222         then
223                 build_all true
224                 build_all false
225                 unit_tests
226         elif [ $1 = 'linux' ]
227         then
228                 build_linux true
229                 build_linux false
230         elif [ $1 = 'linux_unsecured' ]
231         then
232                 build_linux_unsecured true
233                 build_linux_unsecured false
234                 build_linux_unsecured_with_rm true
235                 build_linux_unsecured_with_rm false
236         elif [ $1 = 'linux_secured' ]
237         then
238                 build_linux_secured true
239                 build_linux_secured false
240         elif [ $1 = 'linux_unsecured_with_ra' ]
241         then
242                 build_linux_unsecured_with_ra true
243                 build_linux_unsecured_with_ra false
244         elif [ $1 = 'linux_secured_with_ra' ]
245         then
246                 build_linux_secured_with_ra true
247                 build_linux_secured_with_ra false
248         elif [ $1 = 'linux_unsecured_with_rd' ]
249         then
250                 build_linux_unsecured_with_rd true
251                 build_linux_unsecured_with_rd false
252         elif [ $1 = 'linux_secured_with_rd' ]
253         then
254                 build_linux_secured_with_rd true
255                 build_linux_secured_with_rd false
256         elif [ $1 = 'android' ]
257         then
258                 build_android true
259                 build_android false
260         elif [ $1 = 'android_x86' ]
261         then
262         build_android_x86 true
263         build_android_x86 false
264                 build_android_x86_with_rm true
265                 build_android_x86_with_rm false
266         elif [ $1 = 'android_armeabi' ]
267         then
268         build_android_armeabi true
269         build_android_armeabi false
270                 build_android_armeabi_with_rm true
271                 build_android_armeabi_with_rm false
272         elif [ $1 = 'arduino' ]
273         then
274                 build_arduino true
275                 build_arduino false
276         elif [ $1 = 'tizen' ]
277         then
278                 build_tizen true
279                 build_tizen false
280         elif [ $1 = 'simulator' ]
281     then
282                 build_simulator true
283                 build_simulator false
284         elif [ $1 = 'darwin' ]
285         then
286                 build_darwin true
287                 build_darwin false
288         elif [ $1 = 'unit_tests' ]
289         then
290                 unit_tests
291         else
292                 help
293                 exit -1
294         fi
295 elif [ $# -eq 0 ]
296 then
297         build_all true
298         build_all false
299         unit_tests
300 else
301         help
302         exit -1
303 fi
304
305 echo "===================== done ====================="