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