750f641ab23a937b328d6d86e91388de27de90bd
[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         echo "*********** Build Boost for android ***********"
67         # disable parallel build for android as gradle depends on scons to finish first
68         export SCONSFLAGS="-Q"
69
70         echo "*********** Build for android x86 *************"
71         scons TARGET_OS=android TARGET_ARCH=x86 RELEASE=$1 TARGET_TRANSPORT=IP $2
72         scons TARGET_OS=android TARGET_ARCH=x86 RELEASE=$1 TARGET_TRANSPORT=BT $2
73         scons TARGET_OS=android TARGET_ARCH=x86 RELEASE=$1 TARGET_TRANSPORT=BLE $2
74
75         echo "*********** Build for android x86_64 *************"
76         scons TARGET_OS=android TARGET_ARCH=x86_64 RELEASE=$1 TARGET_TRANSPORT=IP $2
77         scons TARGET_OS=android TARGET_ARCH=x86_64 RELEASE=$1 TARGET_TRANSPORT=BT $2
78         scons TARGET_OS=android TARGET_ARCH=x86_64 RELEASE=$1 TARGET_TRANSPORT=BLE $2
79
80         echo "*********** Build for android armeabi *************"
81         scons TARGET_OS=android TARGET_ARCH=armeabi RELEASE=$1 TARGET_TRANSPORT=IP $2
82         scons TARGET_OS=android TARGET_ARCH=armeabi RELEASE=$1 TARGET_TRANSPORT=BT $2
83         scons TARGET_OS=android TARGET_ARCH=armeabi RELEASE=$1 TARGET_TRANSPORT=BLE $2
84
85         # enable parallel build
86         export SCONSFLAGS="-Q -j 4"
87 }
88
89 function build_arduino()
90 {
91         echo "*********** Build for arduino avr *************"
92         scons resource TARGET_OS=arduino UPLOAD=false BOARD=mega TARGET_ARCH=avr TARGET_TRANSPORT=IP SHIELD=ETH RELEASE=$1 $2
93         scons resource TARGET_OS=arduino UPLOAD=false BOARD=mega TARGET_ARCH=avr TARGET_TRANSPORT=IP SHIELD=WIFI RELEASE=$1 $2
94         scons resource TARGET_OS=arduino UPLOAD=false BOARD=mega TARGET_ARCH=avr TARGET_TRANSPORT=BLE SHIELD=RBL_NRF8001 RELEASE=$1 $2
95
96         echo "*********** Build for arduino arm *************"
97         scons resource TARGET_OS=arduino UPLOAD=false BOARD=arduino_due_x TARGET_ARCH=arm TARGET_TRANSPORT=IP SHIELD=ETH RELEASE=$1 $2
98         scons resource TARGET_OS=arduino UPLOAD=false BOARD=arduino_due_x TARGET_ARCH=arm TARGET_TRANSPORT=IP SHIELD=WIFI RELEASE=$1 $2
99         # BLE support for the Arduino Due is currently unavailable.
100 }
101
102 function build_tizen()
103 {
104         echo "*********** Build for Tizen CA lib and sample *************"
105         scons -f resource/csdk/connectivity/build/tizen/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true RELEASE=$1 $2
106
107         echo "*********** Build for Tizen CA lib and sample with Security *************"
108         scons -f resource/csdk/connectivity/build/tizen/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true SECURED=1 RELEASE=$1 $2
109 }
110
111 function build_darwin() # Mac OSx and iOS
112 {
113         echo "*********** Build for OSX *************"
114         scons TARGET_OS=darwin SYS_VERSION=10.9 RELEASE=$1 $2
115
116         echo "*********** Build for IOS i386 *************"
117         scons TARGET_OS=ios TARGET_ARCH=i386 SYS_VERSION=7.0 RELEASE=$1 $2
118
119         echo "*********** Build for IOS x86_64 *************"
120         scons TARGET_OS=ios TARGET_ARCH=x86_64 SYS_VERSION=7.0 RELEASE=$1 $2
121
122         echo "*********** Build for IOS armv7 *************"
123         scons TARGET_OS=ios TARGET_ARCH=armv7 SYS_VERSION=7.0 RELEASE=$1 $2
124
125         echo "*********** Build for IOS armv7s *************"
126         scons TARGET_OS=ios TARGET_ARCH=armv7s SYS_VERSION=7.0 RELEASE=$1 $2
127
128         echo "*********** Build for IOS arm64 *************"
129         scons TARGET_OS=ios TARGET_ARCH=arm64 SYS_VERSION=7.0 RELEASE=$1 $2
130 }
131
132 function unit_tests()
133 {
134         echo "*********** Unit test Start *************"
135         scons resource RELEASE=false -c
136         scons resource LOGGING=false RELEASE=false
137         scons resource TEST=1 RELEASE=false
138         echo "*********** Unit test Stop *************"
139 }
140
141 function  help()
142 {
143         echo "Usage:"
144         echo "  build:"
145         echo "     `basename $0` <target_build>"
146         echo "      Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_unsecured_with_ra, linux_secured_with_ra, android, arduino, tizen, darwin"
147         echo "      Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\" & \"linux_secured_with_ra\"."
148         echo "      Any selection will build both debug and release versions of all available targets in the scope you've"
149         echo "      selected. To choose any specific command, please use the SCons commandline directly. Please refer"
150         echo "      to [IOTIVITY_REPO]/Readme.scons.txt."
151         echo "  clean:"
152         echo "     `basename $0` -c"
153 }
154
155 # Suppress "Reading ..." message and enable parallel build
156 export SCONSFLAGS="-Q -j 4"
157
158 if [ $# -eq 1 ]
159 then
160         if [ $1 = '-c' ]
161         then
162                 build_all true $1
163                 build_all false $1
164                 exit 0
165         elif [ $1 = 'all' ]
166         then
167                 build_all true
168                 build_all false
169                 unit_tests
170         elif [ $1 = 'linux' ]
171         then
172                 build_linux true
173                 build_linux false
174         elif [ $1 = 'linux_unsecured' ]
175         then
176                 build_linux_unsecured true
177                 build_linux_unsecured false
178         elif [ $1 = 'linux_secured' ]
179         then
180                 build_linux_secured true
181                 build_linux_secured false
182         elif [ $1 = 'linux_unsecured_with_ra' ]
183         then
184                 build_linux_unsecured_with_ra true
185                 build_linux_unsecured_with_ra false
186         elif [ $1 = 'linux_secured_with_ra' ]
187         then
188                 build_linux_secured_with_ra true
189                 build_linux_secured_with_ra false
190         elif [ $1 = 'android' ]
191         then
192                 build_android true
193                 build_android false
194         elif [ $1 = 'arduino' ]
195         then
196                 build_arduino true
197                 build_arduino false
198         elif [ $1 = 'tizen' ]
199         then
200                 build_tizen true
201                 build_tizen false
202         elif [ $1 = 'darwin' ]
203         then
204                 build_darwin true
205                 build_darwin false
206         elif [ $1 = 'unit_tests' ]
207         then
208                 unit_tests
209         else
210                 help
211                 exit -1
212         fi
213 elif [ $# -eq 0 ]
214 then
215         build_all true
216         build_all false
217         unit_tests
218 else
219         help
220         exit -1
221 fi
222
223 echo "===================== done ====================="