added disclaimer.txt and disclaimer to the scripts
[ti-bt/build-utils.git] / wl12xx_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 #
12 function usage()
13 {
14         echo
15         echo
16         echo "*******************************************************************"
17         echo "***************** Bluetooth Modules Builder Script ****************"
18         echo "* This script is only for demo purposes, It is not fully verified *"
19         echo "*******************************************************************"
20         echo
21         echo "This script compiles the BT modules components"
22         echo "The script can build each component as standalone by invoking: \"./wl12xx_build_bt.sh <module name> <build/rebuild>\""
23         echo "For example: \"./wl12xx_build_bt.sh bt-modules rebuild\""
24         echo
25         echo "Available components are:"
26         echo "bt-modules, expat, dbus, libIConv, zlib, gettext, glib, dbus-glib, check, bluez, hcidump, ncurses"
27         echo "readline, alsa-lib, openobex, libical, obexd, bt-obex, firmware, wl1271-demo, bt-enable"
28         echo
29         echo "You may also build all components by typing: \"./wl12xx_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         expat 1
46         dbus 1
47         libIConv 1
48         zlib 1
49         gettext 1
50         glib 1
51         dbus-glib 1
52         check 1
53         bluez 1
54         hcidump 1
55         ncurses 1
56         readline 1
57         alsa-lib 1
58         openobex 1
59         libical 1
60         obexd 1
61         bt-obex 1
62         firmware 1
63         wl1271-demo 1
64         bt-enable 1
65 }
67 function apply_patches()
68 {
69         [ ! -e $LS ] && echo "Please set full path of ls utility in setup-env file." && exit 1
70         files=`$LS *.patch`
71         for f in ${files}; do patch -p1 -i ${f} || exit 1; done
72         return 0
73 }
74 function bt-modules()
75 {
76         if [ x"$KLIB_BUILD" = "x" ]; then
77                 echo "Please set KLIB_BUILD variable to point to your Linux kernel"
78                 exit 1
79         fi
81         cd ${WORK_SPACE} || exit 1
82         COMPONENT_NAME="ti-compat-bluetooth-2012-02-20.tar.gz"
83         COMPONENT_DIR="compat-bluetooth"
84         download_component "https://gforge.ti.com/gf/download/frsrelease/802/5435/ti-compat-bluetooth-2012-02-20.tar.gz"
85         if [ ${CURRENT_OPTION} = "2" ]; then
86                 add_fingerprint 0
87                 [ ! -e Compat-patch-zip-v1.zip ] && { wget http://processors.wiki.ti.com/images/9/99/Compat-patch-zip-v1.zip || exit 1; }
88                 unzip -o Compat-patch-zip-v1.zip || exit 1
89                 apply_patches
91                 ./scripts/driver-select bt || exit 1
92                 make KLIB=${ROOTFS} INSTALL_MOD_PATH=${ROOTFS} "install-modules" || exit 1
93                 add_fingerprint 1
94         fi
95         echo "bt-modules built successfully"
96 }
98 function expat()
99 {
100         cd ${WORK_SPACE} || exit 1
101         COMPONENT_NAME="expat-2.0.1.tar.gz"
102         COMPONENT_DIR="expat-2.0.1"
103         
104         download_component "http://downloads.sourceforge.net/project/expat/expat/2.0.1/expat-2.0.1.tar.gz"
105         if [ ${CURRENT_OPTION} = "2" ]; then
106                 add_fingerprint 0
107                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} 2>&1>${BUILD_LOG_FILE} || exit 1
108                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
109                 make install DESTDIR=${ROOTFS} || exit 1
110                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
111                 add_fingerprint 1
112         fi
113         echo "expat built successfully"
117 function dbus()
119         if  [ $# -eq 1 ]; then
120                 START_MODULE="dbus-1.4.1.tar.gz"
121         fi
122         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
123         expat
125         cd ${WORK_SPACE} || exit 1
126         COMPONENT_NAME="dbus-1.4.1.tar.gz"
127         COMPONENT_DIR="dbus-1.4.1"
128         download_component "http://dbus.freedesktop.org/releases/dbus/dbus-1.4.1.tar.gz"
129         if [ ${CURRENT_OPTION} = "2" ]; then
130                 add_fingerprint 0
131                 echo "ac_cv_func_pipe2=no" > arm-linux.cache || exit 1
132                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache --disable-inotify --without-x 2>&1>>${BUILD_LOG_FILE} || exit 1
133                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
134                 make install DESTDIR=${ROOTFS} || exit 1
135                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
136                 echo "messagebus:x:102:105::${MY_LOCALSTATEDIR}/run/dbus:/bin/false" >> ${ROOTFS}${MY_SYSCONFDIR}/passwd || exit 1
137                 add_fingerprint 1
138         fi
139         echo "dbus built successfully"
143 function libIConv()
145         cd ${WORK_SPACE} || exit 1
146         COMPONENT_NAME="libiconv-1.13.1.tar.gz"
147         COMPONENT_DIR="libiconv-1.13.1"
148         download_component "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz"
149         if [ ${CURRENT_OPTION} = "2" ]; then
150                 add_fingerprint 0
151                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
152                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
153                 make install DESTDIR=${ROOTFS} || exit 1
154                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
155                 add_fingerprint 1
156         fi
157         echo "libIConv built successfully"
160 function zlib()
162         cd ${WORK_SPACE} || exit 1
163         COMPONENT_NAME="zlib-1.2.7.tar.gz"
164         COMPONENT_DIR="zlib-1.2.7"
165         download_component "http://zlib.net/zlib-1.2.7.tar.gz"
166         if [ ${CURRENT_OPTION} = "2" ]; then
167                 add_fingerprint 0
168                 ./configure --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
169                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
170                 make install DESTDIR=${ROOTFS} || exit 1
171                 add_fingerprint 1
172         fi
173         echo "zlib built successfully"
176 function gettext()
178         cd ${WORK_SPACE} || exit 1
179         COMPONENT_NAME="gettext-0.18.tar.gz"
180         COMPONENT_DIR="gettext-0.18"
181         download_component "http://ftp.gnu.org/gnu/gettext/gettext-0.18.tar.gz"
182         if [ ${CURRENT_OPTION} = "2" ]; then
183                 add_fingerprint 0
184                 echo "ac_cv_func_unsetenv=no" > arm-linux.cache || exit 1
185                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache 2>&1>>${BUILD_LOG_FILE} || exit 1
186                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
187                 make install DESTDIR=${ROOTFS} || exit 1
188                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
189                 add_fingerprint 1
190         fi
191         echo "gettext built successfully"
194 function glib()
196         if  [ $# -eq 1 ]; then
197                 START_MODULE="glib-2.24.1.tar.bz2"
198         fi
199         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
200         libIConv
201         zlib
203         cd ${WORK_SPACE} || exit 1
204         COMPONENT_NAME="glib-2.24.1.tar.bz2"
205         COMPONENT_DIR="glib-2.24.1"
206         download_component "http://ftp.gnome.org/pub/GNOME/sources/glib/2.24/glib-2.24.1.tar.bz2"
207         if [ ${CURRENT_OPTION} = "2" ]; then
208                 add_fingerprint 0
209                 echo "glib_cv_stack_grows=no
210                 glib_cv_uscore=yes
211                 ac_cv_func_posix_getpwuid_r=yes
212                 ac_cv_func_posix_getgrgid_r=yes
213                 ac_cv_func_pipe2=no" > arm-linux.cache || exit 1
214                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache --with-libiconv=gnu 2>&1>>${BUILD_LOG_FILE} || exit 1
215                 sed -i 's/\(^Libs: .*\)/\1 -liconv/g' glib-2.0.pc || exit 1
216                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
217                 make install DESTDIR=${ROOTFS} || exit 1
218                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
219                 add_fingerprint 1
220         fi
221         echo "glib built successfully"
224 function dbus-glib()
226         if  [ $# -eq 1 ]; then
227                 START_MODULE="dbus-glib-0.84.tar.gz"
228         fi
229         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
230         dbus
231         glib
233         cd ${WORK_SPACE} || exit 1
234         COMPONENT_NAME="dbus-glib-0.84.tar.gz"
235         COMPONENT_DIR="dbus-glib-0.84"
236         download_component "http://dbus.freedesktop.org/releases/dbus-glib/dbus-glib-0.84.tar.gz"
237         if [ ${CURRENT_OPTION} = "2" ]; then
238                 add_fingerprint 0
239                 echo "ac_cv_have_abstract_sockets=yes" > arm-linux.cache || exit 1
240                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache 2>&1>>${BUILD_LOG_FILE} || exit 1
241                 sed -i 's/examples//g' dbus/Makefile || exit 1
242                 sed -i 's/tools test/test/g' Makefile || exit 1
243                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
244                 make install DESTDIR=${ROOTFS} || exit 1
245                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
246                 add_fingerprint 1
247         fi
248         echo "dbus-glib built successfully"
252 function check()
254         cd ${WORK_SPACE} || exit 1
255         COMPONENT_NAME="check-0.9.6.tar.gz"
256         COMPONENT_DIR="check-0.9.6"
257         download_component "http://downloads.sourceforge.net/check/check-0.9.6.tar.gz"
258         if [ ${CURRENT_OPTION} = "2" ]; then
259                 add_fingerprint 0
260                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
261                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
262                 make install DESTDIR=${ROOTFS} || exit 1
263                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
264                 add_fingerprint 1
265         fi
266         echo "check built successfully"
269 function bluez()
271         if  [ $# -eq 1 ]; then
272                 START_MODULE="bluez-4.98.tar.gz"
273         fi
274         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
275         check
276         dbus
277         glib
279         cd ${WORK_SPACE} || exit 1
280         COMPONENT_NAME="bluez-4.98.tar.gz"
281         COMPONENT_DIR="bluez-4.98"
282         download_component "http://kernel.org/pub/linux/bluetooth/bluez-4.98.tar.gz"
283         if [ ${CURRENT_OPTION} = "2" ]; then
284                 add_fingerprint 0
285                 [ ! -e BlueZ_patches-v2.zip ] && { wget http://processors.wiki.ti.com/images/7/7e/BlueZ_patches-v2.zip || exit 1; }
286                 unzip -o BlueZ_patches-v2.zip || exit 1
287                 apply_patches
289                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --enable-tools --enable-dund --enable-alsa --enable-test --enable-audio --enable-serial --enable-service --enable-hidd --enable-gstreamer --enable-usb --enable-tools --enable-bccmd --enable-hid2hci --enable-dfutool --enable-pand --disable-cups 2>&1>>${BUILD_LOG_FILE}
290                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
291                 make install DESTDIR=${ROOTFS} || exit 1
292                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
293                 cp audio/audio.conf tools/rfcomm.conf input/input.conf ${ROOTFS}${MY_SYSCONFDIR}/bluetooth/ || exit 1
294                 cp test/agent ${ROOTFS}${MY_PREFIX}/bin/agent || exit 1
295                 add_fingerprint 1
296         fi
297         echo "bluez built successfully"
300 function hcidump
302         cd ${WORK_SPACE} || exit 1
303         COMPONENT_NAME="bluez-hcidump-2.2.tar.gz"
304         COMPONENT_DIR="bluez-hcidump-2.2"
305         download_component "http://pkgs.fedoraproject.org/repo/pkgs/bluez-hcidump/bluez-hcidump-2.2.tar.gz/3c298a8be67099fe227f3e4d9de539d5/bluez-hcidump-2.2.tar.gz"
306         if [ ${CURRENT_OPTION} = "2" ]; then
307                 add_fingerprint 0
308                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
309                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
310                 make install DESTDIR=${ROOTFS} || exit 1
311                 add_fingerprint 1
312         fi
313         echo "hcidump built successfully"
316 function ncurses
318         cd ${WORK_SPACE} || exit 1
319         COMPONENT_NAME="ncurses-5.9.tar.gz"
320         COMPONENT_DIR="ncurses-5.9"
321         download_component "http://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz"
322         if [ ${CURRENT_OPTION} = "2" ]; then
323                 add_fingerprint 0
324                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR}  -with-shared --without-debug --without-normal 2>&1>>${BUILD_LOG_FILE} || exit 1
325                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
326                 make install DESTDIR=${ROOTFS} || exit 1
327                 add_fingerprint 1
328         fi
329         echo "ncurses built successfully"
332 function readline
334         cd ${WORK_SPACE} || exit 1
335         COMPONENT_NAME="readline-6.2.tar.gz"
336         COMPONENT_DIR="readline-6.2"
337         download_component " http://ftp.gnu.org/gnu/readline/readline-6.2.tar.gz"
338         if [ ${CURRENT_OPTION} = "2" ]; then
339                 add_fingerprint 0
340                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
341                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
342                 make install DESTDIR=${ROOTFS} || exit 1
343                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
344                 add_fingerprint 1
345         fi
346         echo "readline built successfully"
350 function alsa-lib
352         cd ${WORK_SPACE} || exit 1
353         COMPONENT_NAME="alsa-lib-1.0.24.1.tar.gz"
354         COMPONENT_DIR="alsa-lib-1.0.26"
355         download_component "http://fossies.org/linux/misc/alsa-lib-1.0.24.1.tar.gz"
356         if [ ${CURRENT_OPTION} = "2" ]; then
357                 add_fingerprint 0
358                 ./configure --prefix=${MY_PREFIX} --host=${BUILD_HOST} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
359                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
360                 make install DESTDIR=${ROOTFS} || exit 1
361                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
362                 add_fingerprint 1
363         fi
364         echo "alsa-lib built successfully"
367 function openobex
369         cd ${WORK_SPACE} || exit 1
370         COMPONENT_NAME="openobex-1.5.tar.gz"
371         COMPONENT_DIR="openobex-1.5"
372         download_component "http://ftp.osuosl.org/pub/linux/bluetooth/openobex-1.5.tar.gz"
373         if [ ${CURRENT_OPTION} = "2" ]; then
374         #       wget 'http://mirror.anl.gov/pub/linux/bluetooth/openobex-1.5.tar.gz' || exit 1
375                 add_fingerprint 0
376                 sed -i '11227 i *)\n;;' configure 2>&1>>${BUILD_LOG_FILE} || exit 1
377                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --enable-apps --disable-usb 2>&1>>${BUILD_LOG_FILE} || exit 1
378                 sed -i 's/^\(libdir=\).*/\1\$\{prefix\}\/lib/g' openobex.pc || exit 1
379                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
380                 make install DESTDIR=${ROOTFS} || exit 1
381                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
382                 add_fingerprint 1
383         fi
384         echo "openobex built successfully"
387 function libical
389         cd ${WORK_SPACE} || exit 1
390         COMPONENT_NAME="libical-0.44.tar.gz"
391         COMPONENT_DIR="libical-0.44"
392         download_component "http://downloads.sourceforge.net/project/freeassociation/libical/libical-0.44/libical-0.44.tar.gz"
393         if [ ${CURRENT_OPTION} = "2" ]; then
394                 add_fingerprint 0
395                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
396                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
397                 make install DESTDIR=${ROOTFS} || exit 1
398                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
399                 add_fingerprint 1
400         fi
401         echo "libical built successfully"
404 function obexd
406         if  [ $# -eq 1 ]; then
407                 START_MODULE="obexd-0.34.tar.gz"
408         fi
409         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
410         bluez
411         openobex
412         libical
414         cd ${WORK_SPACE} || exit 1
415         COMPONENT_NAME="obexd-0.34.tar.gz"
416         COMPONENT_DIR="obexd-0.34"
417         download_component "http://www.kernel.org/pub/linux/bluetooth/obexd-0.34.tar.gz"
418         if [ ${CURRENT_OPTION} = "2" ]; then
419                 add_fingerprint 0
420                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
421                 wget http://processors.wiki.ti.com/images/4/43/Obexd-patches_v1.tar.gz || exit 1
422                 echo "Openning archive: Obexd-patches_v1.tar.gz" && tar -xzf Obexd-patches_v1.tar.gz || exit 1
423                 apply_patches
424                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
425                 make install DESTDIR=${ROOTFS} || exit 1
426                 add_fingerprint 1
427         fi
428         echo "obexd built successfully"
431 function bt-obex
433         if  [ $# -eq 1 ]; then
434                 START_MODULE="171181b6ef6c94aefc828dc7fd8de136b9f97532"
435         fi
436         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
437         dbus-glib
438         readline
439         ncurses
441         cd ${WORK_SPACE} || exit 1
442         COMPONENT_NAME="171181b6ef6c94aefc828dc7fd8de136b9f97532"
443         COMPONENT_DIR="bluez-tools"
444         download_component "git://gitorious.org/bluez-tools/bluez-tools.git"
445         if [ ${CURRENT_OPTION} = "2" ]; then
446                 add_fingerprint 0
447                 [ ! -e Bt-obex-patches.zip ] && { wget 'http://processors.wiki.ti.com/images/f/f5/Bt-obex-patches.zip' || exit 1; }
448                 unzip -o Bt-obex-patches.zip || exit 1
449                 apply_patches
451                 /usr/bin/libtoolize || exit 1
452                 /usr/bin/aclocal || exit 1
453                 /usr/bin/autoheader || exit 1
454                 /usr/bin/automake --add-missing || exit 1
455                 /usr/bin/autoconf || exit 1
456                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} 2>&1>>${BUILD_LOG_FILE} || exit 1
457                 make 2>&1>>${BUILD_LOG_FILE} || exit 1
458                 make install DESTDIR=${ROOTFS} || exit 1
459                 add_fingerprint 1
460         fi
461         echo "bt-obex built successfully"
464 function firmware
466         cd ${WORK_SPACE} || exit 1
467         COMPONENT_NAME="db43d1f05efda9777d7ac1ac366637e29e21f77f"
468         COMPONENT_DIR="bt-firmware"
469         download_component "git://github.com/TI-ECS/bt-firmware.git"
470         if [ ${CURRENT_OPTION} = "2" ]; then
471                 add_fingerprint 0
472                 mkdir -p ${ROOTFS}/lib/firmware || exit 1
474                 if [ x"$MACHINE_TYPE" = "x" ]; then
475                         get_machine_used
476                 fi
478                 PRINT_STR="Invoking: cp ${MACHINE_TYPE}/TIInit_7.2.31.bts ${ROOTFS}/lib/firmware/"
479                 echo ${PRINT_STR}
480                 cp ./${MACHINE_TYPE}/TIInit_7.2.31.bts ${ROOTFS}/lib/firmware/ || exit 1
481                 add_fingerprint 1
482         fi
483         echo "firmware built successfully"
486 function wl1271-demo
488         cd ${WORK_SPACE} || exit 1
489         COMPONENT_NAME="wl1271-bluetooth-2012-03-26.tar.gz"
490         COMPONENT_DIR="wl1271-bluetooth"
491         download_component "https://gforge.ti.com/gf/download/frsrelease/827/5494/wl1271-bluetooth-2012-03-26.tar.gz"
492         if [ ${CURRENT_OPTION} = "2" ]; then
493                 add_fingerprint 0
494                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/gallery || exit 1
495                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
496                 mkdir -p ${ROOTFS}/usr/share/wl1271-demos/bluetooth/ftp_folder || exit 1
498                 if [ x"$MACHINE_TYPE" = "x" ]; then
499                         get_machine_used
500                 fi
502                 cp ./gallery/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/gallery || exit 1
503                 cp ./script/common/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
504                 cp ./script/${MACHINE_TYPE}/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/scripts || exit 1
505                 cp ./ftp_folder/* ${ROOTFS}/usr/share/wl1271-demos/bluetooth/ftp_folder || exit 1
506                 add_fingerprint 1
507         fi
508         echo "wl1271-demo built successfully"
511 function bt-enable
513         cd ${WORK_SPACE} || exit 1
514         if [ x"$KLIB_BUILD" = "x" ]; then
515                 echo "Please set KLIB_BUILD variable to point to your Linux kernel"
516                 exit 1
517         fi
518         COMPONENT_NAME="dd75971705ada8fb0e88a0fb3f68833086c5bba4"
519         COMPONENT_DIR="bt_enable"
520         download_component "git://github.com/TI-ECS/bt_enable.git"
521         if [ ${CURRENT_OPTION} = "2" ]; then
522                 [ ! -e Bt-enable-standalone-makefile.zip ] && { wget 'http://processors.wiki.ti.com/images/8/8f/Bt-enable-standalone-makefile.zip' || exit 1; }
523           unzip -o Bt-enable-standalone-makefile.zip || exit 1
524           apply_patches
526           if [ x"$MACHINE_TYPE" = "x" ]; then
527                   get_machine_used
528           fi
529           cp ./gpio_en_${MACHINE_TYPE}.c ./gpio_en.c
530           make DEST_DIR=${ROOTFS} KERNEL_DIR=${KLIB_BUILD} || exit 1
531           make DEST_DIR=${ROOTFS} KERNEL_DIR=${KLIB_BUILD} install || exit 1
532           add_fingerprint 1
533         fi
534         echo "bt-enable built successfully"
537 function add_fingerprint()
539         if [ x"$1" = "x" ]; then
540           echo "Function add_fingerprint() called with no parameters!!!"
541           exit 1
542         fi
543         local FILENAME="${FINGURE_PRINT_DIR}/${COMPONENT_NAME##*/}"
544         touch  ${FILENAME} || exit 1
545         echo $1 > ${FILENAME} || exit
548 function fingerprint()
550         local FILENAME="${FINGURE_PRINT_DIR}/${COMPONENT_NAME##*/}"
551         # if no file exists
552         if [ ! -e ${FILENAME} ]; then
553                 return 0
554         fi
555         read MAX < ${FILENAME}
556         return ${MAX}
559 function download_component()
561         if [ x"$1" = "x" ]; then
562                 echo "Function called with no parameters!!!"
563                 exit 1
564         fi
566         if [ ! x"${START_MODULE}" = "x" ]; then                                                 # if the START_MODULE is not empty
567                 if [ ${START_MODULE} = ${COMPONENT_NAME} ]; then                        # if we are building the start module
568                         CURRENT_OPTION=${USER_OPTION}                                                   # take the user option as is
569                 else
570                         CURRENT_OPTION="1"                                                                              # else, we are building dependency, so we should only build not rebuild
571                 fi
572         else
573                 CURRENT_OPTION=${USER_OPTION}                                                           # take the user option as is
574         fi
575         # get the extension of the file
576         local EXT=${1/*./}
578         # check the fingerprint value
579         fingerprint
580         case "$?" in
581                 0) # 0 - File not compiled nor installed
582                         CURRENT_OPTION="2" # override to "rebuild" option
583                 ;;
584                 1) # 1 - File was installed properly
585                         # if the option is build and fingerprint OK, nothing to do
586                         if [ ${CURRENT_OPTION} = "1" ]; then 
587                                 return
588                         fi
589                 ;;
590                 *)
591                         echo "Corrupted fingerprint for component ${COMPONENT_NAME}"
592                         exit 1
593                 ;;
594         esac
595 #       echo "Decided to rebuild for ${COMPONENT_NAME}"
596 #       read
597         # I get here in one situation : USER_OPTION = 2
598         case "${EXT}" in
599                 git)
600                         # if git directory exist, do not clone it again
601                         if [ ! -d ${COMPONENT_DIR} ]; then
602                           git clone $1 || exit 1
603                         fi
604                         cd ${COMPONENT_DIR} || exit 1
605                         git reset --hard ${COMPONENT_NAME} || exit 1
606                 ;;
608                 gz|bz2)
609                         # delete the working directory if exists
610                         if [ ! x"${COMPONENT_DIR}" = "x" ]; then
611                                 rm -rf ${COMPONENT_DIR} || exit 1
612                         fi
614                         local TAR_FLAGS="-xzf"
616                         if [ ${EXT} = "bz2" ]; then
617                                 TAR_FLAGS="-xjf"
618                         fi
619                         # if component doesn't exist, bring it
620                         if [ ! -e ${COMPONENT_NAME} ]; then
621                                 wget $1 || exit 1
622                         fi
623                         echo "Openning archive: ${COMPONENT_NAME}"
624                         tar ${TAR_FLAGS} ${COMPONENT_NAME} || exit 1 
625                         # move to the directory if not empty
626                         if [ ! x"${COMPONENT_DIR}" = "x" ]; then                        
627                                 cd ${COMPONENT_DIR} || exit 1
628                         fi;
629                 ;;
631                 *)
632                         echo "Unknown extension of remote package"
633                         exit 1
634                 ;;
635         esac
638 function get_machine_used()
640         # check if the machine type is already defined
641         if [ ! x"${MACHINE_TYPE}" = "x" ]; then
642                 return;
643         fi
644         echo ""
645         echo "Please select the machine you use:"
646         echo "==================================="
647         echo "1. am180x-evm (am1808)"
648         echo "2. am37x-evm (omap3evm)"
649         echo "3. am335x-evm (am335x)"
650         read choice
651         case $choice in
652                 1) MACHINE_TYPE="am1808" ;;
653                 2) MACHINE_TYPE="omap3evm" ;;
654                 3) MACHINE_TYPE="am335x" ;;
655                 *)
656                 echo "This is not a valid choice... Exitiing script"
657                 exit 1
658                 ;;
659         esac
662 function check_env()
664         [ -e ${WORK_SPACE}/.check_env.stamp ] && return 0
665         which dpkg
666         if [ $? -ne 0 ]
667         then
668                 echo "The following packages should be installed on the system:"
669                 echo "bash bison flex perl bc python python-m2crypto corkscrew"
670                 echo "git autoconf automake libtool gettext patch libglib2.0-dev"
671                 echo "Please check before to continue."
672                 return 0
673         fi
674         err=0
675         ret=0
676         packages="bash bison flex perl bc python python-m2crypto corkscrew git autoconf automake libtool gettext patch libglib2.0-dev"
677         for p in ${packages}
678         do
679                 echo -n "Checking ${p}..."
680                 present=`dpkg-query -W ${p} 2>/dev/null | awk '{print $1}'`
681                 [ x"${present}" != x"${p}" ] && echo "Package ${p} is not found. Please run 'apt-get install ${p}' to install it." && err=1 && ret=1
682                 [ ${err} -ne 1 ] && echo "OK"
683                 err=0
684         done
685         return ${ret}
687 ############################################# MAIN ###############################################
688 old_dir=`pwd`
689 MACHINE_TYPE=""
691 source setup-env || exit 1
692 # if there are no sufficient arguments...
693 if  [ $# -lt 2 ]; then
694         usage
695         exit 0
696 fi
698 if [ x"$CROSS_COMPILE" = "x" ]; then
699         echo "define CROSS_COMPILE variable"
700         exit 1
701 fi
703 which ${CROSS_COMPILE}gcc > /dev/null
705 if [ $? -ne 0 ]; then
706         echo "No toolchain in path"
707         exit 1
708 fi
710 BUILD_HOST=`echo $CROSS_COMPILE | sed s/-$//`
712 if [ x"$ROOTFS" = "x" ]; then
713         echo "Please set ROOTFS variable to point to your root filesystem"
714         exit 1
715 fi
717 if [ x"$WORK_SPACE" = "x" ]; then
718         echo "Please set WORK_SPACE variable to point to your preferred work space"
719         exit 1
720 fi
722 FINGURE_PRINT_DIR="${WORK_SPACE}/.FingurePrint"
723 mkdir -p ${FINGURE_PRINT_DIR} || exit 1
724 check_env || exit 1
725 touch ${WORK_SPACE}/.check_env.stamp
726 BUILD_LOG_FILE=${FINGURE_PRINT_DIR}/build.log
727 USER_OPTION=0
728 CURRENT_OPTION=0
730 case "$2" in
731         build)
732                 USER_OPTION=1
733         ;;
734         rebuild)
735                 USER_OPTION=2
736         ;;
737         *)
738                 echo "Unknown option $2"
739                 exit 1
740         ;;
741 esac
743 CURRENT_OPTION=${USER_OPTION}
745 MODULE_TO_INVOKE=$1
746 $MODULE_TO_INVOKE 1
748 cd ${old_dir}