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