634de09f7998607eef48da5d83ba659eb9047bcf
[ti-bt/build-utils.git] / wl18xx_build_bt.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 "************************************"
21         echo
22         echo "This script compiles the BT modules components"
23         echo "The script can build each component as standalone by invoking: \"./wl18xx_build_bt.sh <module name> <build/rebuild>\""
24         echo "For example: \"./wl12xx_build_bt.sh bt-modules rebuild\""
25         echo
26         echo "Available components are:"
27         echo "bt-modules, bluez, hcidump, obexd, bt-obex, firmware, wl1271-demo"
28         echo
29         echo "You may also build all components by typing: \"./wl18xx_build_bt.sh all build\""
30         echo
31         echo "Prerequisites"
32         echo "============="
33         echo "The following variables should be exported in order to run the script:"
34         echo "1) ROOTFS - should point to the root filesystem where the BT components will be installed"
35         echo "2) WORK_SPACE - should point to the workspace where the components will be downloaded and compiled"
36         echo "3) KLIB_BUILD - should point to the kernel which the compat bluetooth will be compiled against."
37         echo "4) Path to cross compiler in PATH"
38         echo ""
39 }
41 function all()
42 {
43         get_machine_used
44         bt-modules 1
45         uim 1
46         expat 1
47         libffi
48         glib 1
49         dbus 1
50         libIConv 1
51         zlib 1
52         gettext 1
53         alsa-lib 1
54         dbus-glib 1
55         check 1
56         python 1
57         pygobject 1
58         dbus-python 1
59         bluez 1
60         hcidump 1
61         ncurses 1
62         readline 1
63         openobex 1
64         libical 1
65         obexd 1
66         bt-obex 1
67         firmware 1
68         wl1271-demo 1
69 }
71 function apply_patches()
72 {
73         [ ! -e $LS ] && echo "Please set full path of ls utility in setup-env file." && exit 1
74         files=`$LS *.patch`
75         for f in ${files}; do patch -p1 -i ${f} || exit 1; done
76         return 0
77 }
78 function bt-modules()
79 {
80         if [ x"$KLIB_BUILD" = "x" ]; then
81                 echo "Please set KLIB_BUILD variable to point to your Linux kernel"
82                 exit 1
83         fi
85         cd ${WORK_SPACE} || exit 1
86         COMPONENT_NAME=`basename ${compat_bluetooth[$BUILD_VERSION]}`
87         COMPONENT_DIR="compat-bluetooth"
88         download_component "${compat_bluetooth[$BUILD_VERSION]}"
89         if [ ${CURRENT_OPTION} = "2" ]; then
90                 add_fingerprint 0
91                 patch -p1 -i ${old_dir}/patches/0001-compat-wireless-usb-missing-macro.patch
93                 ./scripts/driver-select bt || exit 1
94                 make KLIB=${ROOTFS} bt || exit 1
96                 make KLIB=${ROOTFS} "install-modules" || exit 1
97                 add_fingerprint 1
98         fi
99         echo "bt-modules built successfully"
102 function alsa-lib
104         cd ${WORK_SPACE} || exit 1
105         COMPONENT_NAME="alsa-lib-1.0.26.tar.gz"
106         COMPONENT_DIR="alsa-lib-1.0.26"
107         download_component "http://fossies.org/linux/misc/alsa-lib-1.0.26.tar.gz"
108         if [ ${CURRENT_OPTION} = "2" ]; then
109                 add_fingerprint 0
110                 ./configure --prefix=${MY_PREFIX} --host=${BUILD_HOST} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --disable-python || exit 1
111                 make || exit 1
112                 make install DESTDIR=${ROOTFS} || exit 1
113                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
114                 add_fingerprint 1
115         fi
116         echo "alsa-lib built successfully"
119 function bluez()
121         if  [ $# -eq 1 ]; then
122                 START_MODULE="bluez-4.98"
123         fi
124         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
125         check
126         dbus
127         glib
128         uim
130         cd ${WORK_SPACE} || exit 1
131         COMPONENT_NAME="bluez-4.98.tar.gz"
132         #COMPONENT_REV="18a5dc6cdcf0828443c415eaea82b6834a8f9825"
133         COMPONENT_DIR="bluez-4.98"
134         download_component "http://kernel.org/pub/linux/bluetooth/bluez-4.98.tar.gz"
135         if [ ${CURRENT_OPTION} = "2" ]; then
136                 add_fingerprint 0
137                 patch -p1 -i ${old_dir}/patches/0003-socket-enable-for-bluez-4_98.patch || exit 1
138                 patch -p1 -i ${old_dir}/patches/0004-bluez-enable-source-interface.patch || exit 1
140                 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
141                 make LIBS='-lffi' || exit 1
142                 make install DESTDIR=${ROOTFS} || exit 1
143                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
144                 cp audio/audio.conf input/input.conf ${ROOTFS}${MY_SYSCONFDIR}/bluetooth/ || exit 1
145                 cp test/agent ${ROOTFS}${MY_PREFIX}/bin/agent || exit 1
146                 mkdir -p ${ROOTFS}/usr/share/bluetooth
148                 cd test
149                 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'
150                 echo "installing tests in ${ROOTFS}/usr/share/bluetooth"
151                 cp ${list} ${ROOTFS}/usr/share/bluetooth
152                 cd -
153                 add_fingerprint 1
154         fi
155         echo "bluez built successfully"
156
158 function hcidump
160         cd ${WORK_SPACE} || exit 1
161         COMPONENT_NAME="bluez-hcidump-2.4.tar.gz"
162         COMPONENT_DIR="bluez-hcidump-2.4"
163         download_component "http://www.kernel.org/pub/linux/bluetooth/bluez-hcidump-2.4.tar.gz"
164         if [ ${CURRENT_OPTION} = "2" ]; then
165                 add_fingerprint 0
166                 patch -p1 -i ${old_dir}/patches/0001-blueti-Add-TI-Logger-dump.patch || exit 1
167                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || exit 1
168                 make || exit 1
169                 make install DESTDIR=${ROOTFS} || exit 1
170                 add_fingerprint 1
171         fi
172         echo "hcidump built successfully"
175 function ncurses
177         cd ${WORK_SPACE} || exit 1
178         COMPONENT_NAME="ncurses-5.9.tar.gz"
179         COMPONENT_DIR="ncurses-5.9"
180         download_component "http://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz"
181         if [ ${CURRENT_OPTION} = "2" ]; then
182                 add_fingerprint 0
183                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR}  -with-shared --without-debug --without-normal || exit 1
184                 make || exit 1
185                 make install DESTDIR=${ROOTFS} || exit 1
186                 add_fingerprint 1
187         fi
188         echo "ncurses built successfully"
191 function readline
193         cd ${WORK_SPACE} || exit 1
194         COMPONENT_NAME="readline-6.2.tar.gz"
195         COMPONENT_DIR="readline-6.2"
196         download_component "ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz"
197         if [ ${CURRENT_OPTION} = "2" ]; then
198                 add_fingerprint 0
199                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || 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 "readline built successfully"
209 function openobex
211         cd ${WORK_SPACE} || exit 1
212         COMPONENT_NAME="openobex-1.5.tar.gz"
213         COMPONENT_DIR="openobex-1.5"
214         download_component "http://ftp.osuosl.org/pub/linux/bluetooth/openobex-1.5.tar.gz"
215         if [ ${CURRENT_OPTION} = "2" ]; then
216         #       wget 'http://mirror.anl.gov/pub/linux/bluetooth/openobex-1.5.tar.gz' || exit 1
217                 add_fingerprint 0
218                 sed -i '11227 i *)\n;;' configure || exit 1
219                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --enable-apps --disable-usb || exit 1
220                 sed -i 's/^\(libdir=\).*/\1\$\{prefix\}\/lib/g' openobex.pc || exit 1
221                 make || exit 1
222                 make install DESTDIR=${ROOTFS} || exit 1
223                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
224                 add_fingerprint 1
225         fi
226         echo "openobex built successfully"
229 function libical
231         cd ${WORK_SPACE} || exit 1
232         COMPONENT_NAME="libical-0.44.tar.gz"
233         COMPONENT_DIR="libical-0.44"
234         download_component "http://downloads.sourceforge.net/project/freeassociation/libical/libical-0.44/libical-0.44.tar.gz"
235         if [ ${CURRENT_OPTION} = "2" ]; then
236                 add_fingerprint 0
237                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} || exit 1
238                 make || exit 1
239                 make install DESTDIR=${ROOTFS} || exit 1
240                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
241                 add_fingerprint 1
242         fi
243         echo "libical built successfully"
246 function obexd
248         if  [ $# -eq 1 ]; then
249                 START_MODULE="obexd-0.34.tar.gz"
250         fi
251         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
252         bluez
253         libical
254         readline
255         ncurses
257         cd ${WORK_SPACE} || exit 1
258         COMPONENT_NAME="obexd-0.34.tar.gz"
259         COMPONENT_DIR="obexd-0.34"
260         download_component "http://www.kernel.org/pub/linux/bluetooth/obexd-0.34.tar.gz"
261         if [ ${CURRENT_OPTION} = "2" ]; then
262                 add_fingerprint 0
263                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} || exit 1
264                 wget http://processors.wiki.ti.com/images/4/43/Obexd-patches_v1.tar.gz || exit 1
265                 echo "Openning archive: Obexd-patches_v1.tar.gz" && tar -xzf Obexd-patches_v1.tar.gz || exit 1
266                 apply_patches
267                 make || exit 1
268                 make install DESTDIR=${ROOTFS} || exit 1
269                 test -d ${ROOTFS}/usr/share/bluetooth || mkdir -p  ${ROOTFS}/usr/share/bluetooth
270                 list='exchange-business-cards  ftp-client  list-folders  pbap-client send-files'
271                 for f in ${list}; do
272                         install -c test/$f ${ROOTFS}/usr/share/bluetooth || exit 1
273                 done
274                 add_fingerprint 1
275         fi
276         echo "obexd built successfully"
279 function bt-obex
281         if  [ $# -eq 1 ]; then
282                 START_MODULE="bluez-tools"
283         fi
284         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
285         dbus-glib
286         readline
287         ncurses
289         cd ${WORK_SPACE} || exit 1
290         COMPONENT_NAME="bluez-tools"
291         COMPONENT_REV="171181b6ef6c94aefc828dc7fd8de136b9f97532"
292         COMPONENT_DIR="bluez-tools"
293         download_component "git://gitorious.org/bluez-tools/bluez-tools.git"
294         if [ ${CURRENT_OPTION} = "2" ]; then
295                 add_fingerprint 0
296                 [ ! -e Bt-obex-patches.zip ] && { wget 'http://processors.wiki.ti.com/images/f/f5/Bt-obex-patches.zip' || exit 1; }
297                 unzip -o Bt-obex-patches.zip || exit 1
298                 apply_patches
299                 #patch -p1 -i ${old_dir}/patches/0001-bt-obex-new-dbus-api-for-obexd.patch
300                 #patch -p1 -i ${old_dir}/patches/0001-manager-adoptation-to-new-manager-interface-of-bluez.patch
302                 /usr/bin/libtoolize || exit 1
303                 /usr/bin/aclocal || exit 1
304                 /usr/bin/autoheader || exit 1
305                 /usr/bin/automake --add-missing || exit 1
306                 /usr/bin/autoconf || exit 1
307                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} || exit 1
308                 make LIBS="-ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0 -liconv -lffi -lz -lncurses" || exit 1
309                 make install DESTDIR=${ROOTFS} || exit 1
310                 add_fingerprint 1
311         fi
312         echo "bt-obex built successfully"
315 function wl1271-demo
317         START_MODULE="wl1271-bluetooth"
318         cd ${WORK_SPACE} || exit 1
319         COMPONENT_NAME="wl1271-bluetooth"
320         COMPONENT_DIR="wl1271-bluetooth"
321         COMPONENT_REV="ae9a9a961dd9821d30a0b9c32612f3a552c81d4e"
322         download_component "git://github.com/TI-ECS/wl1271-bluetooth.git"
323         if [ ${CURRENT_OPTION} = "2" ]; then
324                 add_fingerprint 0
325                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/gallery || exit 1
326                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
327                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/ftp_folder || exit 1
329                 if [ x"$MACHINE_TYPE" = "x" ]; then
330                         get_machine_used
331                 fi
333                 cp ./gallery/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/gallery || exit 1
334                 cp ./script/common/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
335                 cp ./script/${MACHINE_TYPE}/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
336                 cp ./ftp_folder/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/ftp_folder || exit 1
337                 add_fingerprint 1
338         fi
339         echo "wl1271-demo built successfully"
342 function bt-enable
344         cd ${WORK_SPACE} || exit 1
345         if [ x"$KLIB_BUILD" = "x" ]; then
346                 echo "Please set KLIB_BUILD variable to point to your Linux kernel"
347                 exit 1
348         fi
349         COMPONENT_NAME="bt_enable"
350         COMPONENT_REV="dd75971705ada8fb0e88a0fb3f68833086c5bba4"
351         COMPONENT_DIR="bt_enable"
352         download_component "git://github.com/TI-ECS/bt_enable.git"
353         if [ ${CURRENT_OPTION} = "2" ]; then
354                 [ ! -e Bt-enable-standalone-makefile.zip ] && { wget 'http://processors.wiki.ti.com/images/8/8f/Bt-enable-standalone-makefile.zip' || exit 1; }
355           unzip -o Bt-enable-standalone-makefile.zip || exit 1
356           apply_patches
358           if [ x"$MACHINE_TYPE" = "x" ]; then
359                   get_machine_used
360           fi
361           cp ./gpio_en_${MACHINE_TYPE}.c ./gpio_en.c
362           make DEST_DIR=${ROOTFS} KERNEL_DIR=${KLIB_BUILD} || exit 1
363           make DEST_DIR=${ROOTFS} KERNEL_DIR=${KLIB_BUILD} install || exit 1
364           add_fingerprint 1
365         fi
366         echo "bt-enable built successfully"
369 #==================================================================================
370 # Main
371 #==================================================================================
372 old_dir=`pwd`
373 MACHINE_TYPE=""
375 source setup-env || exit 1
376 source ./functions/common-functions
377 # if there are no sufficient arguments...
378 if  [ $# -lt 2 ]; then
379         usage
380         exit 0
381 fi
383 if [ x"$CROSS_COMPILE" = "x" ]; then
384         echo "define CROSS_COMPILE variable"
385         exit 1
386 fi
388 which ${CROSS_COMPILE}gcc > /dev/null
390 if [ $? -ne 0 ]; then
391         echo "No toolchain in path"
392         exit 1
393 fi
396 if [ x"$ROOTFS" = "x" ]; then
397         echo "Please set ROOTFS variable to point to your root filesystem"
398         exit 1
399 fi
401 if [ x"$WORK_SPACE" = "x" ]; then
402         echo "Please set WORK_SPACE variable to point to your preferred work space"
403         exit 1
404 fi
406 FINGURE_PRINT_DIR="${WORK_SPACE}/.FingurePrint"
407 mkdir -p ${FINGURE_PRINT_DIR} || exit 1
409 USER_OPTION=0
410 CURRENT_OPTION=0
412 case "$2" in
413         build)
414                 USER_OPTION=1
415         ;;
416         rebuild)
417                 USER_OPTION=2
418         ;;
419         *)
420                 echo "Unknown option $2"
421                 exit 1
422         ;;
423 esac
425 CURRENT_OPTION=${USER_OPTION}
427 MODULE_TO_INVOKE=$1
428 $MODULE_TO_INVOKE 1
430 cd ${old_dir}