cb44ae4751feebfaf80c9ebf6d1636da95e2d19c
[ti-bt/build-utils.git] / BlueZ_4.98_wl18xx_build_bt_for_SDK7.sh
1 #!/bin/bash
3 #                            \\\// 
4 #                           -(o o)- 
5 #========================oOO==(_)==OOo=======================
6 #
7 # This file contains the Bluetooth components which should
8 # be built and installed on the target filesystem
9 #
11 BUILD_VERSION="r8"
12 #declare -A compat_bluetooth["r8"]="https://gforge.ti.com/gf/download/frsrelease/990/6319/compat-bluetooth-ol-r8.a5.01_Nov_12_2012.tar.gz"
14 function usage()
15 {
16         echo
17         echo
18         echo "*******************************************************************"
19         echo "***************** Bluetooth Modules Builder Script ****************"
20         echo "* This script is only for demo purposes, It is not fully verified *"
21         echo "*******************************************************************"
22         echo
23         echo "This script compiles the BT modules components"
24         echo "The script can build each component as standalone by invoking: \"./wl18xx_build_bt.sh <module name> <build/rebuild>\""
25         echo "For example: \"./wl12xx_build_bt.sh bt-modules rebuild\""
26         echo
27         echo "Available components are:"
28         echo "bt-modules, bluez, hcidump, obexd, bt-obex, firmware, wl1271-demo"
29         echo
30         echo "You may also build all components by typing: \"./wl18xx_build_bt.sh all build\""
31         echo
32         echo "Prerequisites"
33         echo "============="
34         echo "The following variables should be exported in order to run the script:"
35         echo "1) ROOTFS - should point to the root filesystem where the BT components will be installed"
36         echo "2) WORK_SPACE - should point to the workspace where the components will be downloaded and compiled"
37         echo "3) KLIB_BUILD - should point to the kernel which the compat bluetooth will be compiled against."
38         echo "4) Path to cross compiler in PATH"
39         echo ""
40 }
42 function all()
43 {
44         get_machine_used
45         #bt-modules 1
46         #uim 1
47         expat 1
48         libffi
49         glib 1
50         dbus 1
51         libIConv 1
52         zlib 1
53         gettext 1
54         alsa-lib 1
55         dbus-glib 1
56         check 1
57         python 1
58         pygobject 1
59         dbus-python 1
60         bluez 1
61         hcidump 1
62         ncurses 1
63         readline 1
64         openobex 1
65         libical 1
66         obexd 1
67         bt-obex 1
68         firmware 1
69         wl1271-demo 1
70 }
72 function apply_patches()
73 {
74         [ ! -e $LS ] && echo "Please set full path of ls utility in setup-env file." && exit 1
75         files=`$LS *.patch`
76         for f in ${files}; do patch -p1 -i ${f} || exit 1; done
77         return 0
78 }
80 function alsa-lib
81 {
82         cd ${WORK_SPACE} || exit 1
83         COMPONENT_NAME="alsa-lib-1.0.27.2.tar.gz"
84         COMPONENT_DIR="alsa-lib-1.0.27.2"
85         download_component "http://fossies.org/linux/misc/alsa-lib-1.0.27.2.tar.gz"
86         if [ ${CURRENT_OPTION} = "2" ]; then
87                 add_fingerprint 0
88                 ./configure --prefix=${MY_PREFIX} --host=${BUILD_HOST} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --disable-python || exit 1
89                 make || exit 1
90                 make install DESTDIR=${ROOTFS} || exit 1
91                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
92                 add_fingerprint 1
93         fi
94         echo "alsa-lib built successfully"
95 }
97 #compat
98 function bluez()
99 {
100         if  [ $# -eq 1 ]; then
101                 START_MODULE="bluez-4.98"
102         fi
103         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
104         check
105         dbus
106         glib
107         #uim
109         cd ${WORK_SPACE} || exit 1
110         COMPONENT_NAME="bluez-4.98.tar.gz"
111         #COMPONENT_REV="18a5dc6cdcf0828443c415eaea82b6834a8f9825"
112         COMPONENT_DIR="bluez-4.98"
113         download_component "http://kernel.org/pub/linux/bluetooth/bluez-4.98.tar.gz"
114         if [ ${CURRENT_OPTION} = "2" ]; then
115                 add_fingerprint 0
116                 patch -p1 -i ${old_dir}/patches/0003-socket-enable-for-bluez-4_98.patch || exit 1
117                 patch -p1 -i ${old_dir}/patches/0004-bluez-enable-source-interface.patch || exit 1
119                 LIBS='-liconv' ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --enable-alsa --enable-tools --enable-test --enable-audio --enable-serial --enable-service --enable-gstreamer --enable-usb --enable-tools --enable-bccmd --enable-hid2hci --enable-dfutool --enable-pand --disable-cups --enable-debug --enable-gatt --enable-hid2hci --enable-health
120                 make LIBS='-lffi' || exit 1
121                 make install DESTDIR=${ROOTFS} || exit 1
122                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
123                 cp audio/audio.conf input/input.conf ${ROOTFS}${MY_SYSCONFDIR}/bluetooth/ || exit 1
124                 cp test/agent ${ROOTFS}${MY_PREFIX}/bin/agent || exit 1
125                 mkdir -p ${ROOTFS}/usr/share/bluetooth
127                 cd test
128                 list='simple-agent list-devices simple-service test-adapter test-attrib test-audio test-device test-discovery test-health test-health-sink test-input test-manager test-network test-oob test-proximity test-sap-server test-service test-telephony test-textfile test-thermometer uuidtest rctest monitor-bluetooth mpris-player lmptest gaptest hciemu hsmicro hsplay hstest l2test attest avtest bdaddr btiotest'
129                 echo "installing tests in ${ROOTFS}/usr/share/bluetooth"
130                 cp ${list} ${ROOTFS}/usr/share/bluetooth
131                 cd -
132                 add_fingerprint 1
133         fi
134         echo "bluez built successfully"
135
137 function hcidump
139         cd ${WORK_SPACE} || exit 1
140         COMPONENT_NAME="bluez-hcidump-2.4.tar.gz"
141         COMPONENT_DIR="bluez-hcidump-2.4"
142         download_component "http://www.kernel.org/pub/linux/bluetooth/bluez-hcidump-2.4.tar.gz"
143         if [ ${CURRENT_OPTION} = "2" ]; then
144                 add_fingerprint 0
145                 patch -p1 -i ${old_dir}/patches/0001-blueti-Add-TI-Logger-dump.patch || exit 1
146                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || exit 1
147                 make || exit 1
148                 make install DESTDIR=${ROOTFS} || exit 1
149                 add_fingerprint 1
150         fi
151         echo "hcidump built successfully"
154 function ncurses
156         cd ${WORK_SPACE} || exit 1
157         COMPONENT_NAME="ncurses-5.9.tar.gz"
158         COMPONENT_DIR="ncurses-5.9"
159         download_component "http://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz"
160         if [ ${CURRENT_OPTION} = "2" ]; then
161                 add_fingerprint 0
162                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR}  -with-shared --without-debug --without-normal || exit 1
163                 make || exit 1
164                 make install DESTDIR=${ROOTFS} || exit 1
165                 add_fingerprint 1
166         fi
167         echo "ncurses built successfully"
170 function readline
172         cd ${WORK_SPACE} || exit 1
173         COMPONENT_NAME="readline-6.2.tar.gz"
174         COMPONENT_DIR="readline-6.2"
175         download_component "ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz"
176         if [ ${CURRENT_OPTION} = "2" ]; then
177                 add_fingerprint 0
178                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || exit 1
179                 make || exit 1
180                 make install DESTDIR=${ROOTFS} || exit 1
181                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
182                 add_fingerprint 1
183         fi
184         echo "readline built successfully"
188 function openobex
190         cd ${WORK_SPACE} || exit 1
191         COMPONENT_NAME="openobex-1.5.tar.gz"
192         COMPONENT_DIR="openobex-1.5"
193         download_component "http://ftp.osuosl.org/pub/linux/bluetooth/openobex-1.5.tar.gz"
194         if [ ${CURRENT_OPTION} = "2" ]; then
195         #       wget 'http://mirror.anl.gov/pub/linux/bluetooth/openobex-1.5.tar.gz' || exit 1
196                 add_fingerprint 0
197                 sed -i '11227 i *)\n;;' configure || exit 1
198                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --enable-apps --disable-usb || exit 1
199                 sed -i 's/^\(libdir=\).*/\1\$\{prefix\}\/lib/g' openobex.pc || exit 1
200                 make || exit 1
201                 make install DESTDIR=${ROOTFS} || exit 1
202                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
203                 add_fingerprint 1
204         fi
205         echo "openobex built successfully"
208 function libical
210         cd ${WORK_SPACE} || exit 1
211         COMPONENT_NAME="libical-0.44.tar.gz"
212         COMPONENT_DIR="libical-0.44"
213         download_component "http://downloads.sourceforge.net/project/freeassociation/libical/libical-0.44/libical-0.44.tar.gz"
214         if [ ${CURRENT_OPTION} = "2" ]; then
215                 add_fingerprint 0
216                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} || exit 1
217                 make || exit 1
218                 make install DESTDIR=${ROOTFS} || exit 1
219                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
220                 add_fingerprint 1
221         fi
222         echo "libical built successfully"
225 function obexd
227         if  [ $# -eq 1 ]; then
228                 START_MODULE="obexd-0.34.tar.gz"
229         fi
230         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
231         bluez
232         libical
233         readline
234         ncurses
236         cd ${WORK_SPACE} || exit 1
237         COMPONENT_NAME="obexd-0.34.tar.gz"
238         COMPONENT_DIR="obexd-0.34"
239         download_component "http://www.kernel.org/pub/linux/bluetooth/obexd-0.34.tar.gz"
240         if [ ${CURRENT_OPTION} = "2" ]; then
241                 add_fingerprint 0
242                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} || exit 1
243                 #wget http://processors.wiki.ti.com/images/4/43/Obexd-patches_v1.tar.gz || exit 1
244                 #echo "Openning archive: Obexd-patches_v1.tar.gz" && tar -xzf Obexd-patches_v1.tar.gz || exit 1
245                 apply_patches
246                 make || exit 1
247                 make install DESTDIR=${ROOTFS} || exit 1
248                 test -d ${ROOTFS}/usr/share/bluetooth || mkdir -p  ${ROOTFS}/usr/share/bluetooth
249                 list='exchange-business-cards  ftp-client  list-folders  pbap-client send-files'
250                 for f in ${list}; do
251                         install -c test/$f ${ROOTFS}/usr/share/bluetooth || exit 1
252                 done
253                 add_fingerprint 1
254         fi
255         echo "obexd built successfully"
258 function bt-obex
260         if  [ $# -eq 1 ]; then
261                 START_MODULE="bluez-tools"
262         fi
263         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
264         dbus-glib
265         readline
266         ncurses
268         cd ${WORK_SPACE} || exit 1
269         COMPONENT_NAME="bluez-tools"
270         COMPONENT_REV="171181b6ef6c94aefc828dc7fd8de136b9f97532"
271         COMPONENT_DIR="bluez-tools"
272         download_component "git://gitorious.org/bluez-tools/bluez-tools.git"
273         if [ ${CURRENT_OPTION} = "2" ]; then
274                 add_fingerprint 0
275                 #[ ! -e Bt-obex-patches.zip ] && { wget 'http://processors.wiki.ti.com/images/f/f5/Bt-obex-patches.zip' || exit 1; }
276                 #unzip -o Bt-obex-patches.zip || exit 1
277                 apply_patches
278                 #patch -p1 -i ${old_dir}/patches/0001-bt-obex-new-dbus-api-for-obexd.patch
279                 #patch -p1 -i ${old_dir}/patches/0001-manager-adoptation-to-new-manager-interface-of-bluez.patch
281                 /usr/bin/libtoolize || exit 1
282                 /usr/bin/aclocal || exit 1
283                 /usr/bin/autoheader || exit 1
284                 /usr/bin/automake --add-missing || exit 1
285                 /usr/bin/autoconf || exit 1
286                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} || exit 1
287                 make LIBS="-ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0 -liconv -lffi -lz -lncurses" || exit 1
288                 make install DESTDIR=${ROOTFS} || exit 1
289                 add_fingerprint 1
290         fi
291         echo "bt-obex built successfully"
294 function wl1271-demo
296         START_MODULE="wl1271-bluetooth"
297         cd ${WORK_SPACE} || exit 1
298         COMPONENT_NAME="wl1271-bluetooth"
299         COMPONENT_DIR="wl1271-bluetooth"
300         COMPONENT_REV="ae9a9a961dd9821d30a0b9c32612f3a552c81d4e"
301         download_component "git://github.com/TI-ECS/wl1271-bluetooth.git"
302         if [ ${CURRENT_OPTION} = "2" ]; then
303                 add_fingerprint 0
304                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/gallery || exit 1
305                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
306                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/ftp_folder || exit 1
308                 if [ x"$MACHINE_TYPE" = "x" ]; then
309                         get_machine_used
310                 fi
312                 cp ./gallery/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/gallery || exit 1
313                 cp ./script/common/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
314                 cp ./script/${MACHINE_TYPE}/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
315                 cp ./ftp_folder/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/ftp_folder || exit 1
316                 add_fingerprint 1
317         fi
318         echo "wl1271-demo built successfully"
321 function bt-enable
323         cd ${WORK_SPACE} || exit 1
324         if [ x"$KLIB_BUILD" = "x" ]; then
325                 echo "Please set KLIB_BUILD variable to point to your Linux kernel"
326                 exit 1
327         fi
328         COMPONENT_NAME="bt_enable"
329         COMPONENT_REV="dd75971705ada8fb0e88a0fb3f68833086c5bba4"
330         COMPONENT_DIR="bt_enable"
331         download_component "git://github.com/TI-ECS/bt_enable.git"
332         if [ ${CURRENT_OPTION} = "2" ]; then
333                 [ ! -e Bt-enable-standalone-makefile.zip ] && { wget 'http://processors.wiki.ti.com/images/8/8f/Bt-enable-standalone-makefile.zip' || exit 1; }
334           unzip -o Bt-enable-standalone-makefile.zip || exit 1
335           apply_patches
337           if [ x"$MACHINE_TYPE" = "x" ]; then
338                   get_machine_used
339           fi
340           cp ./gpio_en_${MACHINE_TYPE}.c ./gpio_en.c
341           make DEST_DIR=${ROOTFS} KERNEL_DIR=${KLIB_BUILD} || exit 1
342           make DEST_DIR=${ROOTFS} KERNEL_DIR=${KLIB_BUILD} install || exit 1
343           add_fingerprint 1
344         fi
345         echo "bt-enable built successfully"
348 #==================================================================================
349 # Main
350 #==================================================================================
351 old_dir=`pwd`
352 MACHINE_TYPE=""
354 source setup-env || exit 1
355 source ./functions/common-functions
356 # if there are no sufficient arguments...
357 if  [ $# -lt 2 ]; then
358         usage
359         exit 0
360 fi
362 if [ x"$CROSS_COMPILE" = "x" ]; then
363         echo "define CROSS_COMPILE variable"
364         exit 1
365 fi
367 which ${CROSS_COMPILE}gcc > /dev/null
369 if [ $? -ne 0 ]; then
370         echo "No toolchain in path"
371         exit 1
372 fi
375 if [ x"$ROOTFS" = "x" ]; then
376         echo "Please set ROOTFS variable to point to your root filesystem"
377         exit 1
378 fi
380 if [ x"$WORK_SPACE" = "x" ]; then
381         echo "Please set WORK_SPACE variable to point to your preferred work space"
382         exit 1
383 fi
385 FINGURE_PRINT_DIR="${WORK_SPACE}/.FingurePrint"
386 mkdir -p ${FINGURE_PRINT_DIR} || exit 1
388 USER_OPTION=0
389 CURRENT_OPTION=0
391 case "$2" in
392         build)
393                 USER_OPTION=1
394         ;;
395         rebuild)
396                 USER_OPTION=2
397         ;;
398         *)
399                 echo "Unknown option $2"
400                 exit 1
401         ;;
402 esac
404 CURRENT_OPTION=${USER_OPTION}
406 MODULE_TO_INVOKE=$1
407 $MODULE_TO_INVOKE 1
409 cd ${old_dir}