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