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