]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ti-bt/build-utils.git/blob - functions/common-functions
added disclaimer.txt and disclaimer to the scripts
[ti-bt/build-utils.git] / functions / common-functions
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 }
54 function zlib()
55 {
56         cd ${WORK_SPACE} || exit 1
57         COMPONENT_NAME="zlib-1.2.7.tar.gz"
58         COMPONENT_DIR="zlib-1.2.7"
59         download_component "http://zlib.net/zlib-1.2.7.tar.gz"
60         if [ ${CURRENT_OPTION} = "2" ]; then
61                 add_fingerprint 0
62                 ./configure --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} || exit 1
63                 make || exit 1
64                 make install DESTDIR=${ROOTFS} || exit 1
65                 add_fingerprint 1
66         fi
67         echo "zlib built successfully"
68 }
70 function gettext()
71 {
72         cd ${WORK_SPACE} || exit 1
73         COMPONENT_NAME="gettext-0.18.tar.gz"
74         COMPONENT_DIR="gettext-0.18"
75         download_component "http://ftp.gnu.org/gnu/gettext/gettext-0.18.tar.gz"
76         if [ ${CURRENT_OPTION} = "2" ]; then
77                 add_fingerprint 0
78                 echo "ac_cv_func_unsetenv=no" > arm-linux.cache || exit 1
79                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache || exit 1
80                 make || exit 1
81                 make install DESTDIR=${ROOTFS} || exit 1
82                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
83                 add_fingerprint 1
84         fi
85         echo "gettext built successfully"
86 }
88 function glib()
89 {
90         if  [ $# -eq 1 ]; then
91                 START_MODULE="glib-2.34.0.tar.xz"
92         fi
93         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
94         libIConv
95         zlib
97         cd ${WORK_SPACE} || exit 1
98         COMPONENT_NAME="glib-2.34.0.tar.xz"
99         COMPONENT_DIR="glib-2.34.0"
100         download_component "http://ftp.gnome.org/pub/GNOME/sources/glib/2.34/glib-2.34.0.tar.xz"
101         if [ ${CURRENT_OPTION} = "2" ]; then
102                 add_fingerprint 0
103                 echo "glib_cv_stack_grows=no
104                 glib_cv_have_qsort_r=no
105                 glib_cv_uscore=yes
106                 ac_cv_func_posix_getpwuid_r=yes
107                 ac_cv_func_posix_getgrgid_r=yes
108                 ac_cv_func_pipe2=no" > arm-linux.cache || exit 1
109                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache --with-libiconv=gnu || exit 1
110                 sed -i 's/\(^Libs: .*\)/\1 -liconv/g' glib-2.0.pc || exit 1
111                 sed -i 's/\(^Libs: .*\)/\1 -lgmodule-2.0/g' gio-2.0.pc || exit 1
112                 make || exit 1
113                 make install DESTDIR=${ROOTFS} || exit 1
114                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
115                 add_fingerprint 1
116         fi
117         echo "glib built successfully"
120 function dbus()
122         if  [ $# -eq 1 ]; then
123                 START_MODULE="dbus-1.6.8.tar.gz"
124         fi
125         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
126         expat
127         libffi
128         glib
130         cd ${WORK_SPACE} || exit 1
131         COMPONENT_NAME="dbus-1.6.8.tar.gz"
132         COMPONENT_DIR="dbus-1.6.8"
133         download_component "http://dbus.freedesktop.org/releases/dbus/dbus-1.6.8.tar.gz"
134         if [ ${CURRENT_OPTION} = "2" ]; then
135                 add_fingerprint 0
136                 echo "ac_cv_func_pipe2=no" > arm-linux.cache || exit 1
137                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache --disable-inotify --without-x || exit 1
138                 make LIBS="-lgio-2.0 -lgmodule-2.0 -lgobject-2.0 -lglib-2.0 -liconv -lffi -lz" || exit 1
139                 make install DESTDIR=${ROOTFS} || exit 1
140                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
141                 echo "messagebus:x:102:105::${MY_LOCALSTATEDIR}/run/dbus:/bin/false" >> ${ROOTFS}${MY_SYSCONFDIR}/passwd || exit 1
142                 add_fingerprint 1
143         fi
144         echo "dbus built successfully"
147 function dbus-glib()
149         if  [ $# -eq 1 ]; then
150                 START_MODULE="dbus-glib-0.86.tar.gz"
151         fi
152         # dependency section, in here we build the dependencies. We do not want to rebuild them each time
153         dbus
154         glib
156         cd ${WORK_SPACE} || exit 1
157         COMPONENT_NAME="dbus-glib-0.86.tar.gz"
158         COMPONENT_DIR="dbus-glib-0.86"
159         download_component "http://dbus.freedesktop.org/releases/dbus-glib/dbus-glib-0.86.tar.gz"
160         if [ ${CURRENT_OPTION} = "2" ]; then
161                 add_fingerprint 0
162                 echo "ac_cv_have_abstract_sockets=yes" > arm-linux.cache || exit 1
163                 ./configure --host=${BUILD_HOST} --prefix=${MY_PREFIX} --sysconfdir=${MY_SYSCONFDIR} --localstatedir=${MY_LOCALSTATEDIR} --cache-file=arm-linux.cache || exit 1
164                 sed -i 's/examples//g' dbus/Makefile || exit 1
165                 sed -i 's/tools test/test/g' Makefile || exit 1
166                 make LIBS="-lffi -lgthread-2.0 -lgobject-2.0 -lglib-2.0 -liconv" || exit 1
167                 make install DESTDIR=${ROOTFS} || exit 1
168                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
169                 add_fingerprint 1
170         fi
171         echo "dbus-glib built successfully"
174 function python()
176         cd ${WORK_SPACE} || exit 1
177         #dependency section
178         glib
179         
180         COMPONENT_NAME="Python-2.7.3.tgz"
181         COMPONENT_DIR="Python-2.7.3"
182         download_component "http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz"
183         echo "CURRENT_OPTION=$CURRENT_OPTION"
184         if [ ${CURRENT_OPTION} = "2" ]; then
185                 add_fingerprint 0
186                 CC=gcc CXX=g++ AR=ar RANLIB=ranlib ./configure || exit 1
187                 make python Parser/pgen || exit 1
188                 mv python hostpython || exit 1
189                 mv Parser/pgen Parser/hostpgen || exit 1
190                 make distclean || exit 1
191                 patch -p1 < ${old_dir}/patches/0001-Python-2.7.3-xcompile.patch || exit 1
192                 ./configure --host=${BUILD_HOST} --build=x86_64-linux-gnu --prefix=${MY_PREFIX} --with-system-expat --enable-unicode=ucs2 --without-wctype-functions || exit 1
193                 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
194                 make install DESTDIR=${ROOTFS} HOSTPYTHON=./hostpython BLDSHARED="${CROSS_COMPILE}gcc -shared" CROSS_COMPILE_TARGET=y || exit 1
195                 add_fingerprint 1
196         fi
197         echo "python built successfully"
200 function dbus-python()
202         cd ${WORK_SPACE} || exit 1
203         #dependency section
204         glib
205         dbus
206         python
208         COMPONENT_NAME="dbus-python-0.84.0.tar.gz"
209         COMPONENT_DIR="dbus-python-0.84.0"
210         download_component "http://dbus.freedesktop.org/releases/dbus-python/dbus-python-0.84.0.tar.gz"
211         if [ ${CURRENT_OPTION} = "2" ]; then
212                 add_fingerprint 0
213                 echo "am_cv_python_pythondir=${MY_PREFIX}/lib/python2.7/site-packages
214                 am_cv_python_pyexecdir=${MY_PREFIX}/lib/python2.7/site-packages" > arm-linux.cache || exit 1
215                 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
216                 make PYTHON_INCLUDES="-I${ROOTFS}${MY_PREFIX}/include/python2.7/" || 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 "dbus-python built successfully"
224 function pygobject()
226         cd ${WORK_SPACE} || exit 1
227         
228         #dependency section
229         glib
230         python
232         COMPONENT_NAME="pygobject-2.21.1.tar.bz2"
233         COMPONENT_DIR="pygobject-2.21.1"
234         download_component "http://ftp.gnome.org/pub/GNOME/sources/pygobject/2.21/pygobject-2.21.1.tar.bz2"
235         if [ ${CURRENT_OPTION} = "2" ]; then
236                 add_fingerprint 0
237                 echo "am_cv_python_pyexecdir=${MY_PREFIX}/lib/python2.7/site-packages" > arm-linux.cache || exit 1
238                 CC=gcc CXX=g++ AR=ar RANLIB=ranlib ./configure --disable-glibtest --without-ffi  || exit 1
239                 cd ./gobject
240                 make generate-constants || exit 1
241                 cd ..
242                 cp gobject/generate-constants host-generate-constants || exit 1
243                 patch -p1 -i ${old_dir}/patches/0001-pygobject-python-includes.patch
244                 /usr/bin/libtoolize || exit 1
245                 /usr/bin/aclocal -I m4 || exit 1
246                 /usr/bin/autoheader || exit 1
247                 /usr/bin/automake --add-missing || exit 1
248                 /usr/bin/autoconf || exit 1
249                 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
250                 cp host-generate-constants gobject/generate-constants || exit 1
251                 make PYTHON_INCLUDES="-I${ROOTFS}${MY_PREFIX}/include/python2.7/" || exit 1
252                 make || exit 1
253                 make install DESTDIR=${ROOTFS} || exit 1
254                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
255                 add_fingerprint 1
256         fi
257         echo "pygobject built successfully"
261 function firmware
263         cd ${WORK_SPACE} || exit 1
264         COMPONENT_NAME="bt-firmware"
265         COMPONENT_REV="c17a13b64e7b1bfb1d44658b2473bcbff763befd"
266         COMPONENT_DIR="bt-firmware"
267         download_component "git://github.com/TI-ECS/bt-firmware.git"
268         if [ ${CURRENT_OPTION} = "2" ]; then
269                 add_fingerprint 0
270                 mkdir -p ${ROOTFS}/lib/firmware || exit 1
272                 if [ x"$MACHINE_TYPE" = "x" ]; then
273                         get_machine_used
274                 fi
276                 PRINT_STR="Invoking: cp ${MACHINE_TYPE}/TIInit_12.8.32.bts ${ROOTFS}/lib/firmware/"
277                 echo ${PRINT_STR}
278                 cp ./${MACHINE_TYPE}/TIInit_12.8.32.bts ${ROOTFS}/lib/firmware/ || exit 1
279                 add_fingerprint 1
280         fi
281         echo "firmware built successfully"
284 function uim
286         cd ${WORK_SPACE} || exit 1
287         COMPONENT_NAME="uim"
288         COMPONENT_REV="c73894456df5def97111cb33d2106b684b8b7959"
289         COMPONENT_DIR="uim"
290         download_component "git://gitorious.org/uim/uim.git"
291         if [ ${CURRENT_OPTION} = "2" ]; then
292                 add_fingerprint 0
293                 if [ x"$MACHINE_TYPE" = "x" ]; then
294                         get_machine_used
295                 fi
296                 install -d ${ROOTFS}${MY_PREFIX}/sbin ${ROOTFS}/etc/init.d
297                 install -d ${ROOTFS}/etc/rcS.d
298                 make DESTDIR=${ROOTFS} install
299                 install -c -m 755 ${old_dir}/scripts/uim/uim-sysfs.sh ${ROOTFS}/etc/init.d/ || exit 1
300                 cd ${ROOTFS}/etc/init.d/ || exit 1
301                 ln -s -f ../init.d/uim-sysfs.sh ../rcS.d/S04uim-sysfs || exit 1
302                 add_fingerprint 1
303         fi
304         echo "uim built successfully"
307 function libffi()
309         cd ${WORK_SPACE} || exit 1
310         COMPONENT_REV="70084e70ddb13b29dd05c751b1904de206bbe790"
311         COMPONENT_NAME="libffi"
312         COMPONENT_DIR="libffi"
313         
314         download_component "https://github.com/atgreen/libffi.git"
315         if [ ${CURRENT_OPTION} = "2" ]; then
316                 add_fingerprint 0
317                 ./configure --prefix=${MY_PREFIX} CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld RANLIB=${CROSS_COMPILE}ranlib --host=${BUILD_HOST} || exit 1
318                 make || exit 1
319                 make install DESTDIR=${ROOTFS} || exit 1
320                 rm `find ${ROOTFS}${MY_PREFIX}/lib/ -name '*.la'` >& /dev/null
321                 add_fingerprint 1
322         fi
323         echo "libffi built successfully"
325 function add_fingerprint()
327         if [ x"$1" = "x" ]; then
328           echo "Function add_fingerprint() called with no parameters!!!"
329           exit 1
330         fi
331         local FILENAME="${FINGURE_PRINT_DIR}/${COMPONENT_NAME##*/}"
332         touch  ${FILENAME} || exit 1
333         echo $1 > ${FILENAME} || exit
336 function fingerprint()
338         local FILENAME="${FINGURE_PRINT_DIR}/${COMPONENT_NAME##*/}"
339         # if no file exists
340         if [ ! -e ${FILENAME} ]; then
341                         return 0
342         fi
343         read MAX < ${FILENAME}
344         return ${MAX}
347 function download_component()
349         if [ x"$1" = "x" ]; then
350                 echo "Function called with no parameters!!!"
351                 exit 1
352         fi
354         if [ ! x"${START_MODULE}" = "x" ]; then                         # if the START_MODULE is not empty
355                 if [ ${START_MODULE} = ${COMPONENT_NAME} ]; then        # if we are building the start module
356                         CURRENT_OPTION=${USER_OPTION}                   # take the user option as is
357                 else
358                         CURRENT_OPTION="1"                              # else, we are building dependency, so we should only build not rebuild
359                 fi
360         else
361                 CURRENT_OPTION=${USER_OPTION}                           # take the user option as is
362         fi
363         # get the extension of the file
364         local EXT=${1/*./}
366         # check the fingerprint value
367         fingerprint
368         case "$?" in
369                 0) # 0 - File not compiled nor installed
370                         CURRENT_OPTION="2" # override to "rebuild" option
371                 ;;
372                 1) # 1 - File was installed properly
373                         # if the option is build and fingerprint OK, nothing to do
374                         if [ ${CURRENT_OPTION} = "1" ]; then 
375                                 return
376                         fi
377                 ;;
378                 *)
379                         echo "Corrupted fingerprint for component ${COMPONENT_NAME}"
380                         exit 1
381                 ;;
382         esac
383 #       echo "Decided to rebuild for ${COMPONENT_NAME}"
384 #       read
385         # I get here in one situation : USER_OPTION = 2
386         case "${EXT}" in
387                 git)
388                         # if git directory exist, do not clone it again
389                         if [ ! -d ${COMPONENT_DIR} ]; then
390                           git clone $1 || exit 1
391                         fi
392                         cd ${COMPONENT_DIR} || exit 1
393                         git reset --hard ${COMPONENT_REV} || exit 1
394                 ;;
396                 tgz|gz|bz2|xz|tar)
397                         # delete the working directory if exists
398                         if [ ! x"${COMPONENT_DIR}" = "x" ]; then
399                                 rm -rf ${COMPONENT_DIR} || exit 1
400                         fi
402                         local TAR_FLAGS="-xavf"
404                         # if component doesn't exist, bring it
405                         if [ ! -e ${COMPONENT_NAME} ]; then
406                                 wget $1 || exit 1
407                         fi
408                         tar ${TAR_FLAGS} ${COMPONENT_NAME} || exit 1 
409                         # move to the directory if not empty
410                         if [ ! x"${COMPONENT_DIR}" = "x" ]; then                        
411                                 cd ${COMPONENT_DIR} || exit 1
412                         fi;
413                 ;;
415                 *)
416                         echo "Unknown extension of remote package"
417                         exit 1
418                 ;;
419         esac
422 function get_machine_used()
424         # check if the machine type is already defined
425         if [ ! x"${MACHINE_TYPE}" = "x" ]; then
426                 return;
427         fi
428         echo ""
429         echo "Please select the machine you use:"
430         echo "==================================="
431         echo "3. am335x-evm (am335x)"
432         read choice
433         case $choice in
434                 1) MACHINE_TYPE="am335x" ;;
435                 *)
436                 echo "This is not a valid choice... Exitiing script"
437                 exit 1
438                 ;;
439         esac