root/current/emdebian/trunk/buildcross/branch/em_cross.sh

Revision 3212, 11.4 kB (checked in by zumbi, 10 months ago)

added changes

  • Property svn:executable set to *
Line 
1#!/bin/bash -x
2# Distributed under the terms of the GNU General Public License v2
3#
4# Latest version of this file can be downloaded from:
5#  http://www.emdebian.org/repos/current/emdebian/trunk/buildcross/trunk/
6# but it might need some fix for you to work.
7# ----------------------------------------------------------------------
8# Copyright 1999-2007 Emdebian
9
10source conf_vars.sh
11
12PKG=$1
13ARCH=$2
14
15if [ ${ARCH} == "armel" ]; then
16        MIRROR=${MIRROR:="http://ftp.gnuab.org/debian/"}
17
18fi
19
20if [ ! -d $LOGPATH ]; then
21        mkdir -p $LOGPATH
22fi
23
24# Sets build as failed
25echo 1 > $LOGPATH/$HOST-$ARCH-$PKG.log
26
27
28#----------------------------------------------------------------------
29# Useful shell functions
30
31#----------------------------------------------------------------------
32# check build-deps
33checkinstalled () {
34        while [ -n "$1" ]; do
35                dpkg -l "$1" |grep -q "^ii" || {
36                        echo "$1 is not installed."
37                        apt-get -y --force-yes install $1
38                }
39                shift
40        done
41}
42
43sanitycheck () {
44        # sanity check build environment
45        echo "Sanity check..."
46        checkinstalled dpkg-cross
47#       checkinstalled wget
48        #checkinstalled dctrl-tools
49        checkinstalled grep-dctrl
50        checkinstalled sudo
51        checkinstalled fakeroot
52        checkinstalled dpatch
53        checkinstalled patchutils
54        checkinstalled tar
55        checkinstalled bzip2
56        checkinstalled lsb-release
57        checkinstalled autoconf
58        checkinstalled autoconf2.13
59        checkinstalled automake1.9
60        checkinstalled libtool
61        checkinstalled autogen
62        checkinstalled gawk
63        checkinstalled bison
64        checkinstalled flex
65        checkinstalled realpath
66        checkinstalled texinfo
67        checkinstalled devscripts
68        checkinstalled reprepro
69        checkinstalled less
70        checkinstalled coreutils
71        checkinstalled automake1.4
72        checkinstalled automake1.7
73        checkinstalled dh-make
74        checkinstalled debhelper
75        checkinstalled apt-cross
76        checkinstalled emdebian-tools
77       
78        # Following lines are gdb dependencies
79        checkinstalled tetex-bin
80        checkinstalled libncurses5-dev
81        checkinstalled libreadline5-dev
82        #checkinstalled gcj
83        checkinstalled gobjc
84        checkinstalled cdbs 
85        checkinstalled quilt
86        checkinstalled type-handling
87        echo "Sanity check passed."
88}
89
90#----------------------------------------------------------------------
91# find full version string: version <binarypackage>
92# XXX: What about epochs?
93version () {
94        rmadison -a ${ARCH} ${1} | grep ${SUITE} | cut -d'|' -f2 | tr -d ' ' | cut -d'+' -f1 |sed 's/1://'|tail -n 1
95}
96
97srcver () {
98        local x=$(apt-cache showsrc $1 |grep ^Version: |sed 's/^Version: //' |sort -bru |head -1)
99        echo $(echo $x |sed 's/\(.*\)\(-[0-9]*$\)/\1/' |sed 's/1://')
100}
101
102# find upstream version string: upstreamversion <binarypackage>
103upstreamversion () {
104        echo $(version $1 |sed 's/\(.*\)\(-[0-9]*$\)/\1/')
105}
106
107# find debian revision string: debianrevision <binarypackage>
108debianrevision () {
109        echo $(version $1 |sed 's/\(.*-\)\([0-9]*$\)/\2/')
110}
111
112# find sourcepackage: sourcepackage <binarypackage>
113sourcepackage () {
114        local x=$(grep-status -PX $1 -s Source: -n)
115        local y=$1
116        echo ${x:=$y}
117}
118
119# find source directory: sourcedir <sourcepackage>
120sourcedir () {
121        echo $1-$(srcver $1)
122}
123
124
125# make cross ${ARCH} package: make-cross-package <binarypackage>
126make-cross-package () {
127        local _version=$(version $1)
128#       apt-cross -v -v -a ${ARCH} -S ${SUITE} -m ${MIRROR} -i $1
129        apt-cross -v -v -a ${ARCH} -S ${SUITE} -m ${MIRROR} -i $1
130        apt-cross -v -v -a ${ARCH} -S ${SUITE} -m ${MIRROR} -f -b $1
131        apt-cross -v -v -a ${ARCH} -S ${SUITE} -m ${MIRROR} -f -b $1
132        # apt-cross -v -v --force -a ${ARCH} -S ${SUITE} -m ${MIRROR} -i $1
133        # apt-cross -v -v --force -a ${ARCH} -S ${SUITE} -m ${MIRROR} -b $1
134        # rm -rf ${1}_${_version}_${ARCH}.deb
135               
136}
137
138
139# build and install libraries needed to build the cross toolchain
140build-libs () {
141       
142        # Lets get kernel info; linux kernel headers
143        make-cross-package linux-libc-dev
144       
145        # Lets get glibc
146        if [ ${ARCH} = "alpha" ] || [ ${ARCH} = "ia64" ] ; then
147                make-cross-package libc6.1
148                make-cross-package libc6.1-dev
149        else
150                make-cross-package libc6
151                make-cross-package libc6-dev
152        fi
153       
154        # Build dependencies
155        if [ ${ARCH} = "ia64" ] ; then
156                make-cross-package libatomic-ops-dev
157                make-cross-package libunwind7
158                make-cross-package libunwind7-dev
159        fi
160       
161        if [ ${ARCH} = "powerpc" ]; then
162                make-cross-package libc6-ppc64
163                make-cross-package libc6-dev-ppc64
164        fi
165
166        if [ ${ARCH} = "i386" ]; then
167                make-cross-package libc6-amd64
168                make-cross-package lib64gcc1
169                make-cross-package libc6-dev-amd64
170        fi
171               
172        if [ ${ARCH} = "sparc" ]; then
173                make-cross-package libc6-sparc64
174                make-cross-package libc6-dev-sparc64
175        fi
176       
177        if [ ${ARCH} = "s390" ]; then
178                make-cross-package libc6-s390x
179                make-cross-package libc6-dev-s390x
180        fi
181
182        if [ ${ARCH} = "hppa" ]; then
183                make-cross-package libgcc4
184        fi
185       
186        if [ ${ARCH} = "m68k" ] ; then
187                make-cross-package libgcc2
188        else
189                make-cross-package libgcc1
190        fi
191
192        # Added lib32gcc1 for testing - not sure if this is needed
193        if [ ${ARCH} = "amd64" ] ; then
194                make-cross-package lib32gcc1
195        fi
196       
197        if [ ${ARCH} = "ia64" ] ; then
198                make-cross-package lib32gcc1
199        fi
200       
201
202#       make-cross-package uclibc-toolchain
203#       make-cross-package libuclibc0
204#       make-cross-package libuclibc-dev
205        make-cross-package gcc-4.3-base
206#       make-cross-arch-package gdb
207
208        # Final work: Install libraries and do clean up
209#       dpkg -i *all.deb
210        rm -rf *${ARCH}.deb
211
212}
213
214# applies patches
215apply_patch () {
216        patch -p1 < ../../patches/$1
217}
218
219# build and install cross gdb
220# Actually not used
221build-gdb () {
222        local _upver=$(upstreamversion gdb)
223        local _version=$(version gdb)
224        local _dir=$(sourcedir gdb)
225        local _debarch=${ARCH}
226
227        if [ ! -d gdb-${_version} ]; then
228                rm -rf $_dir
229                apt-get source gdb
230                # pushd $_dir
231                # echo "${ARCH}" > debian/target
232                #// Workarround patches
233                # apply_patch binutils-cross-2.17.patch
234                # popd
235                mv $_dir gdb-${_version}
236        fi
237        pushd gdb-${_version}
238#       dpkg-buildpackage -us -uc -B -rfakeroot
239        TARGET=${ARCH} dpkg-buildpackage -rfakeroot -uc -us
240        popd
241
242#       $ROOTCMD dpkg -i gdb-${_debarch}-linux-gnu_${_version}_${HOSTARCH}.deb >> dpkg.log
243
244        #// Do clean up
245        rm -rf *.gz *.bz2 *.dsc *.changes *.tgz *.tar gdb-${_version}/
246
247}
248
249# build and install cross binutils
250build-binutils () {
251        local _upver=$(upstreamversion binutils)
252        local _version=$(version binutils)
253        local _dir=$(sourcedir binutils)
254        local _debarch=${ARCH}
255
256        if [ ! -d binutils-${_version} ]; then
257                rm -rf $_dir
258                apt-get source binutils
259                pushd $_dir
260                echo "${ARCH}" > debian/target
261                #// Workarround patches
262                # apply_patch binutils-cross-2.17.patch
263                apply_patch binutils-cross-2.18.patch
264                # apply_patch binutils-cross-2.18.1cvs20071027.patch
265                popd
266                mv $_dir binutils-${_version}
267        fi
268        pushd binutils-${_version}
269#       dpkg-buildpackage -us -uc -B -rfakeroot
270        TARGET=${ARCH} fakeroot debian/rules binary-cross
271        popd
272
273        $ROOTCMD dpkg -i binutils-*-linux-gnu*.deb >> dpkg.log
274
275        #// Do clean up
276        rm -rf *.gz *.bz2 *.tgz *.dsc *.changes *.tar binutils-${_version}/
277
278}
279
280
281# build cross gcc versions: build-gcc <majorversion>
282build-gcc () {
283        local _upver=$(upstreamversion gcc-$1)
284        local _version=$(version gcc-$1)
285        local _dir=$(sourcedir gcc-$1)
286
287        if [ ! -d gcc-$1-${_version} ]; then
288                rm -rf $_dir
289                apt-get source gcc-$1
290                pushd $_dir
291                echo "${ARCH}" > debian/target
292
293                # Workaround for GCC4.2
294                if [ ${1} = "4.2" ]; then
295                #       apply_patch reverse_cross_fix.patch
296                #       apply_patch gcc42-amd64-i386.patch
297                        apply_patch gcc-4.2-4.2.2-cross.patch
298                fi
299                # Patch gcc-3.3
300                if [ ${GCCVER} = "3.3" ]; then
301                        # cp ../../patches/gcc-3.3.6-emdebian-cross.dpatch debian/patches
302                        # apply_patch gcc-3.3.patch
303
304                        # Disables multi-arch
305                        apply_patch gcc-3.3.6.patch
306                fi
307               
308                DEB_CROSS=yes fakeroot debian/rules control
309                popd
310                mv $_dir gcc-$1-${_version}
311        fi
312        pushd gcc-$1-${_version}
313        if [ ${ARCH} = "armel"  ]; then
314        LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/arm-linux-gnueabi/lib/:/arm-linux-gnueabi/lib:/usr/arm-linux-gnueabi/lib32/:/usr/arm-linux-gnueabi/lib64/:/arm-linux-gnueabi/lib32/:/arm-linux-gnueabi/lib64/:/emul/ia32-linux/lib/:/emul/ia32-linux/usr/lib/ DEB_CROSS=yes dpkg-buildpackage -us -uc -B -rfakeroot
315        else
316        LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/${ARCH}-linux-gnu/lib/:/${ARCH}-linux-gnu/lib:/usr/${ARCH}-linux-gnu/lib32/:/usr/${ARCH}-linux-gnu/lib64/:/${ARCH}-linux-gnu/lib32/:/${ARCH}-linux-gnu/lib64/:/emul/ia32-linux/lib/:/emul/ia32-linux/usr/lib/ DEB_CROSS=yes dpkg-buildpackage -us -uc -B -rfakeroot
317        fi
318        popd
319}
320
321# install cross gcc versions: install-gcc <majorversion>
322install-gcc () {
323        local _version=$(version gcc-$1)
324        local _versionrepo=$(echo gcc-$1 | sed -e 's/-//' | sed -e 's/\.//')
325       
326        #// Do clean up
327        rm -rf *.gz *.bz2 *.tgz *.tar gcc-$1-${_version}/ *.changes *.dsc
328
329}
330
331
332# build and install cross gcc-3.3
333build-gcc-3.3 () {
334        checkinstalled gcc-3.3
335        GCCVER=${GCCVER:="3.3"}
336        build-gcc 3.3
337        install-gcc 3.3
338}
339
340# build and install cross gcc-3.4
341build-gcc-3.4 () {
342        checkinstalled gcc-3.4
343        GCCVER=${GCCVER:="3.4"}
344        build-gcc 3.4
345        install-gcc 3.4
346}
347
348# build and install cross gcc-4.0
349build-gcc-4.0 () {
350        checkinstalled gcc-4.0
351        GCCVER=${GCCVER:="4.0"}
352        build-gcc 4.0
353        install-gcc 4.0
354}
355
356# build cross gcc-4.1
357build-gcc-4.1 () {
358        checkinstalled gcc-4.1
359        GCCVER=${GCCVER:="4.1"}
360        #// Please check this url before trying to build gcc-4.1
361        #// http://people.debian.org/~terpstra/thread/20061015.114041.d049319b.en.html
362        #// FIXME: Need to workarround that bug.
363        build-gcc 4.1
364        install-gcc 4.1
365}
366
367# build cross gcc-4.2
368build-gcc-4.2 () {
369        checkinstalled gcc-4.2
370        GCCVER=${GCCVER:="4.2"}
371        build-gcc 4.2
372        install-gcc 4.2
373}
374
375build-gcc-4.3 () {
376        checkinstalled gcc-4.3
377        GCCVER=${GCCVER:="4.3"}
378        build-gcc 4.3
379        install-gcc 4.3
380}
381
382# build cross gcc-snapshot
383build-gcc-snapshot () {
384        # Hack, hack.
385        pushd /usr/lib
386        $ROOTCMD ln -sf /usr gcc-snapshot
387        popd
388
389        build-gcc snapshot
390#       install-gcc snapshot
391}
392
393#----------------------------------------------------------------------
394# Finally, do the work.
395
396sanitycheck
397
398# dpkg-cross version check
399if [[ "1.39" > $(dpkg-cross --help 2>&1 |awk '{print $3; exit;}') ]]; then
400        echo "dpkg-cross is too old."
401        exit 1
402fi
403
404# do we need to check more version from some packages ?
405
406# for ARCH in ${ARCHLIST}; do
407
408        # Clean dir ?
409        #./cleandir.sh
410        [ -d ${ARCH} ] || mkdir ${ARCH}
411        pushd ${ARCH}
412        echo "Updating apt-cross cache"
413        apt-cross -a ${ARCH} -S ${SUITE} -m ${MIRROR} -u
414        echo "Building for ARCH::${ARCH}" 
415        #// make libs
416        if [ ${1} = "libs" ]; then
417                build-libs &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
418        #// make binutils
419        elif [ ${1} = "binutils" ]; then
420                build-binutils  &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
421        #// make gdb
422        elif [ ${1} = "gdb" ]; then
423                build-gdb  &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
424        #// make gcc
425        #elif [ ${1} = "snapshot" ]; then
426        #       build-gcc-snapshot  &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
427        elif [ ${1} = "3.3" ]; then
428                GCCVER=${1}
429                echo $GCCVER
430                echo Runs
431                echo gcc-3.3
432#               build-gcc-${GCCVER} &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
433        elif [ ${1} = "3.4" ]; then
434                GCCVER=${1}
435                build-gcc-${GCCVER} &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
436        elif [ ${1} = "4.1" ]; then
437                GCCVER=${1}
438                build-gcc-${GCCVER} &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
439        elif [ ${1} = "4.2" ]; then
440                GCCVER=${1}
441                build-gcc-${GCCVER} &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
442        elif [ ${1} = "4.3" ]; then
443                GCCVER=${1}
444                build-gcc-${GCCVER} &> ../$LOGPATH/$HOST-$ARCH-$PKG.log
445        else
446                echo " Unknown option"
447                exit 1
448        fi
449        popd
450
451        # REPLACE: This quite does not work
452        # echo 0 >> $LOGPATH/$HOST-$ARCH-$PKG.log
453        TEST=`cat $LOGPATH/$HOST-$ARCH-$PKG.log | grep $HOST.deb`
454        if [ -n ${TEST} ]; then
455                echo 1 >> $LOGPATH/$HOST-$ARCH-$PKG.log
456        else
457                echo 0 >> $LOGPATH/$HOST-$ARCH-$PKG.log
458        fi
459       
460# done
Note: See TracBrowser for help on using the browser.