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