Added BlueZ build scripts
[ti-bt/build-utils.git] / functions / common-functions_for_SDK7
1 BUILD_HOST=`echo $CROSS_COMPILE | sed s/-$//`
2 function check()
3 {
4         cd ${WORK_SPACE} || exit 1
5         COMPONENT_NAME="check-0.9.8.tar.gz"
6         COMPONENT_DIR="check-0.9.8"
7         download_component "http://downloads.sourceforge.net/check/check-0.9.8.tar.gz"
8         if [ ${CURRENT_OPTION} = "2" ]; then
9                 add_fingerprint 0
10                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || exit 1
11                 make || exit 1
12                 make install DESTDIR=${ROOTFS} || exit 1
13                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
14                 add_fingerprint 1
15         fi
16         echo "check built successfully"
17 }
19 function expat()
20 {
21         cd ${WORK_SPACE} || exit 1
22         COMPONENT_NAME="expat-2.1.0.tar.gz"
23         COMPONENT_DIR="expat-2.1.0"
24         
25         download_component "http://downloads.sourceforge.net/project/expat/expat/2.1.0/expat-2.1.0.tar.gz"
26         if [ ${CURRENT_OPTION} = "2" ]; then
27                 add_fingerprint 0
28                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || exit 1
29                 make || exit 1
30                 make install DESTDIR=${ROOTFS} || exit 1
31                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
32                 add_fingerprint 1
33         fi
34         echo "expat built successfully"
35 }
37 function libIConv()
38 {
39         cd ${WORK_SPACE} || exit 1
40         COMPONENT_NAME="libiconv-1.14.tar.gz"
41         COMPONENT_DIR="libiconv-1.14"
42         download_component "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz"
43         if [ ${CURRENT_OPTION} = "2" ]; then
44                 add_fingerprint 0
45                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || exit 1
46                 make || exit 1
47                 make install DESTDIR=${ROOTFS} || exit 1
48                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
49                 add_fingerprint 1
50         fi
51         echo "libIConv built successfully"
52 }
55 function zlib()
56 {
57         cd ${WORK_SPACE} || exit 1
58         COMPONENT_NAME="zlib-1.2.8.tar.gz"
59         COMPONENT_DIR="zlib-1.2.8"
60         download_component "http://zlib.net/zlib-1.2.8.tar.gz"
61         if [ ${CURRENT_OPTION} = "2" ]; then
62                 add_fingerprint 0
63                 ./configure --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || exit 1
64                 make || exit 1
65                 make install DESTDIR=${ROOTFS} || exit 1
66                 add_fingerprint 1
67         fi
68         echo "zlib built successfully"
69 }
71 function gettext()
72 {
73         cd ${WORK_SPACE} || exit 1
74         COMPONENT_NAME="gettext-0.18.tar.gz"
75         COMPONENT_DIR="gettext-0.18"
76         download_component "http://ftp.gnu.org/gnu/gettext/gettext-0.18.tar.gz"
77         if [ ${CURRENT_OPTION} = "2" ]; then
78                 add_fingerprint 0
79                 echo "ac_cv_func_unsetenv=no" > arm-linux.cache || exit 1
80                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache || exit 1
81                 make || exit 1
82                 make install DESTDIR=${ROOTFS} || exit 1
83                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
84                 add_fingerprint 1
85         fi
86         echo "gettext built successfully"
87 }
89 function glib()
90 {
91         if  [ $# -eq 1 ]; then
92                 START_MODULE="glib-2.34.0.tar.xz"
93         fi
94         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
95         libIConv
96         zlib
98         cd ${WORK_SPACE} || exit 1
99         COMPONENT_NAME="glib-2.41.0.tar.xz"
100         COMPONENT_DIR="glib-2.41.0"
101         download_component "http://ftp.gnome.org/pub/GNOME/sources/glib/2.41/glib-2.41.0.tar.xz"
102         if [ ${CURRENT_OPTION} = "2" ]; then
103                 add_fingerprint 0
104                 echo "glib_cv_stack_grows=no
105                 glib_cv_have_qsort_r=no
106                 glib_cv_uscore=yes
107                 ac_cv_func_posix_getpwuid_r=yes
108                 ac_cv_func_posix_getgrgid_r=yes
109                 ac_cv_func_pipe2=no" > arm-linux.cache || exit 1
110                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache --with-libiconv=gnu || exit 1
111                 sed -i 's/\(^Libs: .*\)/\1 -liconv/g' glib-2.0.pc || exit 1
112                 sed -i 's/\(^Libs: .*\)/\1 -lgmodule-2.0/g' gio-2.0.pc || exit 1
113                 make || exit 1
114                 make install DESTDIR=${ROOTFS} || exit 1
115                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
116                 add_fingerprint 1
117         fi
118         echo "glib built successfully"
121 function dbus()
123         if  [ $# -eq 1 ]; then
124                 START_MODULE="dbus-1.6.8.tar.gz"
125         fi
126         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
127         expat
128         libffi
129         glib
131         cd ${WORK_SPACE} || exit 1
132         COMPONENT_NAME="dbus-1.6.8.tar.gz"
133         COMPONENT_DIR="dbus-1.6.8"
134         download_component "http://dbus.freedesktop.org/releases/dbus/dbus-1.6.8.tar.gz"
135         if [ ${CURRENT_OPTION} = "2" ]; then
136                 add_fingerprint 0
137                 echo "ac_cv_func_pipe2=no" > arm-linux.cache || exit 1
138                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache --disable-inotify --without-x || exit 1
139                 make LIBS="-lgio-2.0 -lgmodule-2.0 -lgobject-2.0 -lglib-2.0 -liconv -lffi -lz" || exit 1
140                 make install DESTDIR=${ROOTFS} || exit 1
141                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
142                 echo "messagebus:x:102:105::${MY_LOCALSTATEDIR}/run/dbus:/bin/false" >> ${ROOTFS}${MY_SYSCONFDIR}/passwd || exit 1
143                 add_fingerprint 1
144         fi
145         echo "dbus built successfully"
148 function dbus-glib()
150         if  [ $# -eq 1 ]; then
151                 START_MODULE="dbus-glib-0.86.tar.gz"
152         fi
153         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
154         dbus
155         glib
157         cd ${WORK_SPACE} || exit 1
158         COMPONENT_NAME="dbus-glib-0.86.tar.gz"
159         COMPONENT_DIR="dbus-glib-0.86"
160         download_component "http://dbus.freedesktop.org/releases/dbus-glib/dbus-glib-0.86.tar.gz"
161         if [ ${CURRENT_OPTION} = "2" ]; then
162                 add_fingerprint 0
163                 echo "ac_cv_have_abstract_sockets=yes" > arm-linux.cache || exit 1
164                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache || exit 1
165                 sed -i 's/examples//g' dbus/Makefile || exit 1
166                 sed -i 's/tools test/test/g' Makefile || exit 1
167                 make LIBS="-lffi -lgthread-2.0 -lgobject-2.0 -lglib-2.0 -liconv" || exit 1
168                 make install DESTDIR=${ROOTFS} || exit 1
169                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
170                 add_fingerprint 1
171         fi
172         echo "dbus-glib built successfully"
175 function python()
177         cd ${WORK_SPACE} || exit 1
178         #dependency section
179         glib
180         
181         COMPONENT_NAME="Python-2.7.3.tgz"
182         COMPONENT_DIR="Python-2.7.3"
183         download_component "http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz"
184         echo "CURRENT_OPTION=$CURRENT_OPTION"
185         if [ ${CURRENT_OPTION} = "2" ]; then
186                 add_fingerprint 0
187                 CC=gcc CXX=g++ AR=ar RANLIB=ranlib ./configure || exit 1
188                 make python Parser/pgen || exit 1
189                 mv python hostpython || exit 1
190                 mv Parser/pgen Parser/hostpgen || exit 1
191                 make distclean || exit 1
192                 patch -p1 < ${old_dir}/patches/0001-Python-2.7.3-xcompile.patch || exit 1
193                 ./configure --host=${BUILD_HOST} --build=x86_64-linux-gnu --prefix=${MY_PREFIX} --with-system-expat --enable-unicode=ucs2 --without-wctype-functions || exit 1
194                 make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="${CROSS_COMPILE}gcc -shared" CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=x86_64-linux-gnu || exit 1
195                 make install DESTDIR=${ROOTFS} HOSTPYTHON=./hostpython BLDSHARED="${CROSS_COMPILE}gcc -shared" CROSS_COMPILE_TARGET=y || exit 1
196                 add_fingerprint 1
197         fi
198         echo "python built successfully"
201 function dbus-python()
203         cd ${WORK_SPACE} || exit 1
204         #dependency section
205         glib
206         dbus
207         python
209         COMPONENT_NAME="dbus-python-0.84.0.tar.gz"
210         COMPONENT_DIR="dbus-python-0.84.0"
211         download_component "http://dbus.freedesktop.org/releases/dbus-python/dbus-python-0.84.0.tar.gz"
212         if [ ${CURRENT_OPTION} = "2" ]; then
213                 add_fingerprint 0
214                 echo "am_cv_python_pythondir=${MY_PREFIX}/lib/python2.7/site-packages
215                 am_cv_python_pyexecdir=${MY_PREFIX}/lib/python2.7/site-packages" > arm-linux.cache || exit 1
216                 PYTHON_INCLUDES="-I${ROOTFS}${MY_PREFIX}/include/python2.7/" PYTHON_LIBS="-L${ROOTFS}/${MY_PREFIX}/lib/python2.7" ./configure --host=${BUILD_HOST} --build=x86_64-linux-gnu --prefix=${MY_PREFIX} --cache-file=arm-linux.cache || exit 1
217                 make PYTHON_INCLUDES="-I${ROOTFS}${MY_PREFIX}/include/python2.7/" || 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 "dbus-python built successfully"
225 function pygobject()
227         cd ${WORK_SPACE} || exit 1
228         
229         #dependency section
230         glib
231         python
233         COMPONENT_NAME="pygobject-2.21.1.tar.bz2"
234         COMPONENT_DIR="pygobject-2.21.1"
235         download_component "http://ftp.gnome.org/pub/GNOME/sources/pygobject/2.21/pygobject-2.21.1.tar.bz2"
236         if [ ${CURRENT_OPTION} = "2" ]; then
237                 add_fingerprint 0
238                 echo "am_cv_python_pyexecdir=${MY_PREFIX}/lib/python2.7/site-packages" > arm-linux.cache || exit 1
239                 CC=gcc CXX=g++ AR=ar RANLIB=ranlib ./configure --disable-glibtest --without-ffi  || exit 1
240                 cd ./gobject
241                 make generate-constants || exit 1
242                 cd ..
243                 cp gobject/generate-constants host-generate-constants || exit 1
244                 patch -p1 -i ${old_dir}/patches/0001-pygobject-python-includes.patch
245                 /usr/bin/libtoolize || exit 1
246                 /usr/bin/aclocal -I m4 || exit 1
247                 /usr/bin/autoheader || exit 1
248                 /usr/bin/automake --add-missing || exit 1
249                 /usr/bin/autoconf || exit 1
250                 PYTHON_INCLUDES="-I${ROOTFS}${MY_PREFIX}/include/python2.7/" NM=nm ./configure --host=${BUILD_HOST} --build=x86_64-linux-gnu --prefix=${MY_PREFIX} --cache-file=arm-linux.cache || exit 1
251                 cp host-generate-constants gobject/generate-constants || exit 1
252                 make PYTHON_INCLUDES="-I${ROOTFS}${MY_PREFIX}/include/python2.7/" || exit 1
253                 make || exit 1
254                 make install DESTDIR=${ROOTFS} || exit 1
255                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
256                 add_fingerprint 1
257         fi
258         echo "pygobject built successfully"
262 function firmware
264         cd ${WORK_SPACE} || exit 1
265         COMPONENT_NAME="bt-firmware"
266         COMPONENT_REV="c17a13b64e7b1bfb1d44658b2473bcbff763befd"
267         COMPONENT_DIR="bt-firmware"
268         download_component "git://github.com/TI-ECS/bt-firmware.git"
269         if [ ${CURRENT_OPTION} = "2" ]; then
270                 add_fingerprint 0
271                 mkdir -p ${ROOTFS}/lib/firmware || exit 1
273                 if [ x"$MACHINE_TYPE" = "x" ]; then
274                         get_machine_used
275                 fi
277                 PRINT_STR="Invoking: cp ${MACHINE_TYPE}/TIInit_12.8.32.bts ${ROOTFS}/lib/firmware/"
278                 echo ${PRINT_STR}
279                 cp ./${MACHINE_TYPE}/TIInit_12.8.32.bts ${ROOTFS}/lib/firmware/ || exit 1
280                 add_fingerprint 1
281         fi
282         echo "firmware built successfully"
286 function libffi()
288         cd ${WORK_SPACE} || exit 1
289         COMPONENT_REV="70084e70ddb13b29dd05c751b1904de206bbe790"
290         COMPONENT_NAME="libffi"
291         COMPONENT_DIR="libffi"
292         
293         download_component "https://github.com/atgreen/libffi.git"
294         if [ ${CURRENT_OPTION} = "2" ]; then
295                 add_fingerprint 0
296                 ./configure --prefix=${MY_PREFIX} CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld RANLIB=${CROSS_COMPILE}ranlib --host=${BUILD_HOST} || exit 1
297                 make || exit 1
298                 make install DESTDIR=${ROOTFS} || exit 1
299                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
300                 add_fingerprint 1
301         fi
302         echo "libffi built successfully"
304 function add_fingerprint()
306         if [ x"$1" = "x" ]; then
307           echo "Function add_fingerprint() called with no parameters!!!"
308           exit 1
309         fi
310         local FILENAME="${FINGURE_PRINT_DIR}/${COMPONENT_NAME##*/}"
311         touch  ${FILENAME} || exit 1
312         echo $1 > ${FILENAME} || exit
315 function fingerprint()
317         local FILENAME="${FINGURE_PRINT_DIR}/${COMPONENT_NAME##*/}"
318         # if no file exists
319         if [ ! -e ${FILENAME} ]; then
320                         return 0
321         fi
322         read MAX < ${FILENAME}
323         return ${MAX}
326 function download_component()
328         if [ x"$1" = "x" ]; then
329                 echo "Function called with no parameters!!!"
330                 exit 1
331         fi
333         if [ ! x"${START_MODULE}" = "x" ]; then                         # if the START_MODULE is not empty
334                 if [ ${START_MODULE} = ${COMPONENT_NAME} ]; then        # if we are building the start module
335                         CURRENT_OPTION=${USER_OPTION}                   # take the user option as is
336                 else
337                         CURRENT_OPTION="1"                              # else, we are building dependency, so we should only build not rebuild
338                 fi
339         else
340                 CURRENT_OPTION=${USER_OPTION}                           # take the user option as is
341         fi
342         # get the extension of the file
343         local EXT=${1/*./}
345         # check the fingerprint value
346         fingerprint
347         case "$?" in
348                 0) # 0 - File not compiled nor installed
349                         CURRENT_OPTION="2" # override to "rebuild" option
350                 ;;
351                 1) # 1 - File was installed properly
352                         # if the option is build and fingerprint OK, nothing to do
353                         if [ ${CURRENT_OPTION} = "1" ]; then 
354                                 return
355                         fi
356                 ;;
357                 *)
358                         echo "Corrupted fingerprint for component ${COMPONENT_NAME}"
359                         exit 1
360                 ;;
361         esac
362 #       echo "Decided to rebuild for ${COMPONENT_NAME}"
363 #       read
364         # I get here in one situation : USER_OPTION = 2
365         case "${EXT}" in
366                 git)
367                         # if git directory exist, do not clone it again
368                         if [ ! -d ${COMPONENT_DIR} ]; then
369                           git clone $1 || exit 1
370                         fi
371                         cd ${COMPONENT_DIR} || exit 1
372                         git reset --hard ${COMPONENT_REV} || exit 1
373                 ;;
375                 tgz|gz|bz2|xz|tar)
376                         # delete the working directory if exists
377                         if [ ! x"${COMPONENT_DIR}" = "x" ]; then
378                                 rm -rf ${COMPONENT_DIR} || exit 1
379                         fi
381                         local TAR_FLAGS="-xavf"
383                         # if component doesn't exist, bring it
384                         if [ ! -e ${COMPONENT_NAME} ]; then
385                                 wget $1 || exit 1
386                         fi
387                         tar ${TAR_FLAGS} ${COMPONENT_NAME} || exit 1 
388                         # move to the directory if not empty
389                         if [ ! x"${COMPONENT_DIR}" = "x" ]; then                        
390                                 cd ${COMPONENT_DIR} || exit 1
391                         fi;
392                 ;;
394                 *)
395                         echo "Unknown extension of remote package"
396                         exit 1
397                 ;;
398         esac
401 function get_machine_used()
403         # check if the machine type is already defined
404         if [ ! x"${MACHINE_TYPE}" = "x" ]; then
405                 return;
406         fi
407         echo ""
408         echo "Please select the machine you use:"
409         echo "==================================="
410         echo "3. am335x-evm (am335x)"
411         read choice
412         case $choice in
413                 1) MACHINE_TYPE="am335x" ;;
414                 *)
415                 echo "This is not a valid choice... Exitiing script"
416                 exit 1
417                 ;;
418         esac