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