#! /bin/bash # # Build Debian-style cross compiler packages # # Copyright 2006-2008 Thiemo Seufer # Copyright 2006-2010 Hector Oron # set -e set -x . /etc/buildcross.conf PKG=$1 ARCH=$2 # target architecture #DEBARCH=${DEBARCH:="mips"} #DEBARCH=${DEBARCH:="gnuspe"} #DEBARCH=${DEBARCH:="armel"} #DEBARCH=${DEBARCH:="powerpc"} #DEBARCH=${DEBARCH:="sparc"} # mirror for both binary and source packages MIRROR=${MIRROR:="http://ftp.de.debian.org/debian"} #MIRROR=${MIRROR:="http://hattusa/debian"} #MIRROR=${MIRROR:="http://merkur.tec.linutronix.de/debian/linutronix-lenny-gnuspe-hacked"} SUITE=${SUITE:="lenny"} #SUITE=${SUITE:="linutronix-lenny-gnuspe"} ROOTCMD=sudo #ROOTCMD= CLEANTREE=${CLEANTREE:="yes"} #---------------------------------------------------------------------- # Sanitize environment export LANG=C export LANGUAGE=C export LC_ALL=C export LC_PAPER=C export LC_MONETARY=C # Figure out host architecture HOSTARCH=$(dpkg-architecture -qDEB_HOST_ARCH) case $DEBARCH in armel) PKGARCH=arm; PKGABI=gnueabi ;; gnuspe) PKGARCH=powerpc; PKGABI=gnuspe ;; *) PKGARCH=$DEBARCH; PKGABI=gnu ;; esac # Munge LD_LIBRARY_PATH, workaround for #453267 DEF_LD_LIBRARY_PATH=$LD_LIBRARY_PATH MY_LD_LIBRARY_PATH=/lib:/usr/lib:/lib32:/usr/lib32:/lib64:/usr/lib64 MY_LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH:/$PKGARCH-linux-${PKGABI}/lib MY_LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH:/usr/$PKGARCH-linux-${PKGABI}/lib MY_LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH:/$PKGARCH-linux-${PKGABI}/lib32 MY_LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH:/usr/$PKGARCH-linux-${PKGABI}/lib32 MY_LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH:/$PKGARCH-linux-${PKGABI}/lib64 MY_LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH:/usr/$PKGARCH-linux-${PKGABI}/lib64 #---------------------------------------------------------------------- # Useful shell functions # check build-deps checkinstalled () { while [ -n "$1" ]; do dpkg -l "$1" |grep -q "^ii" || { echo "$1 is not installed." exit 1 } shift done } # get list of packages in main for $DEBARCH get-package-lists () { local _mirror="${MIRROR}/dists/${SUITE}/main" if [ ! -f Sources ] || [ "$CLEANTREE" = "yes" ]; then if [ ! $(wget -nv -nd -N ${_mirror}/source/Sources.bz2) ]; then bzip2 -df Sources.bz2 elif [ ! $(wget -nv -nd -N ${_mirror}/source/Sources.gz) ]; then gzip -df Sources.gz else wget -nv -nd -N ${_mirror}/source/Sources fi fi if [ ! -f Packages ] || [ "$CLEANTREE" = "yes" ]; then # if [ ! $(wget -nv -nd -N ${_mirror}/binary-${PKGARCH}/Packages.bz2) ]; then if [ ! $(wget -nv -nd -N ${_mirror}/binary-${DEBARCH}/Packages.bz2) ]; then bzip2 -df Packages.bz2 # elif [ ! $(wget -nv -nd -N ${_mirror}/binary-${DEBARCH}/Packages.gz) ]; then elif [ ! $(wget -nv -nd -N ${_mirror}/binary-${DEBARCH}/Packages.gz) ]; then gzip -df Packages.gz else # wget -nv -nd -N ${_mirror}/binary-${PKGARCH}/Packages wget -nv -nd -N ${_mirror}/binary-${DEBARCH}/Packages fi fi SOURCELIST=$(pwd)/Sources BINARYLIST=$(pwd)/Packages } # find full version string: version # XXX: What about epochs? version () { grep-aptavail -PX $1 -s Version: -n ${BINARYLIST} |sed 's/[0-9]\+://' } srcver () { local x=$(apt-cache showsrc $1 |grep ^Version: |sed 's/^Version: //' |sort -bru |head -1) echo $(echo $x |sed 's/\(.*\)\(-[0-9]*$\)/\1/') } # find upstream version string: upstreamversion upstreamversion () { echo $(version $1 |sed 's/\(.*\)\(-[0-9]*$\)/\1/') } # find debian revision string: debianrevision debianrevision () { echo $(version $1 |sed 's/\(.*-\)\([0-9]*$\)/\2/') } # find sourcepackage: sourcepackage sourcepackage () { local x=$(grep-status -PX $1 -s Source: -n ${BINARYLIST} |sed 's/\s.*//') local y=$1 echo ${x:=$y} } # find source directory: sourcedir sourcedir () { echo $1-$(srcver $1) } # find source directory: sourcedir_v sourcedir_v () { local _a=`sourcedir $(srcver $1)` local _b=`echo ${_a} | cut -d'-' -f1` echo $1-${_b} } # make cross all package: make-cross-package [force-dummy-package] make-cross-package () { local _version=$(version $1) local _sourcepkg=$(sourcepackage $1) local _hashdir=$(echo ${_sourcepkg} |sed 's/^\(lib.\|.\)\(.*\)/\1/') local _mirror="${MIRROR}/pool/main/${_hashdir}/${_sourcepkg}" local _origfile="${1}_${_version}_all.deb" local _crossfile="${1}-${DEBARCH}-cross_${_version}_all.deb" local _force_dummy=${2:+"-A"} [ -f ${_origfile} ] || wget -nv -nd -N ${_mirror}/${_origfile} [ -f ${_crossfile} ] || dpkg-cross ${_force_dummy} -a ${DEBARCH} -b ${_origfile} $ROOTCMD dpkg -i ${_crossfile} } # make cross $arch package: make-cross-arch-package [force-dummy-package] make-cross-arch-package () { local _version=$(version $1) local _sourcepkg=$(sourcepackage $1) local _hashdir=$(echo ${_sourcepkg} |sed 's/^\(lib.\|.\)\(.*\)/\1/') local _mirror="${MIRROR}/pool/main/${_hashdir}/${_sourcepkg}" local _origfile="${1}_${_version}_${DEBARCH}.deb" local _crossfile="${1}-${DEBARCH}-cross_${_version}_all.deb" local _force_dummy=${2:+"-A"} [ -f ${_origfile} ] || wget -nv -nd -N ${_mirror}/${_origfile} [ -f ${_crossfile} ] || dpkg-cross ${_force_dummy} -a ${DEBARCH} -b ${_origfile} -X gcc-4.3-base $ROOTCMD dpkg --force-depends -i ${_crossfile} } apply-patches () { local _pkg=$1 local _pkgver=$2 if [ -f patches/${_pkg}/series ]; then pushd ${_pkg}/${_pkgver} rm -f patches ln -s ../../patches/${_pkg} patches quilt push -a popd fi } init-repository () { mkdir -p repository/conf pushd repository/conf if [ ! -f distributions ]; then cat > distributions <<-EOF Codename: ths-cross-toolchain Suite: ${SUITE} AlsoAcceptFor: unstable testing testing-proposed-updates testing-security Version: 0.1 Origin: ths Description: Cross toolchains Architectures: i386 source Components: main UDebComponents: main Update: - ${SUITE} DebIndices: Packages Release . .gz UDebIndices: Packages Release . .gz Tracking: all includechanges keepsources Log: reprepro.log EOF fi if [ ! -f incoming ]; then cat > incoming <<-EOF Name: ths-cross-toolchain IncomingDir: ../incoming TempDir: ../incoming-tmp Allow: unstable>ths-cross-toolchain EOF fi popd mkdir -p incoming incoming-tmp } add-to-repository () { # cp $1/*.{deb,changes,dsc,gz} incoming/ cp $1/*.{deb,dsc,gz} incoming/ pushd repository reprepro processincoming ths-cross-toolchain popd } # build and install libraries needed to build the cross toolchain build-libs () { mkdir -p cross-libs pushd cross-libs # make-cross-arch-package linux-kernel-headers make-cross-arch-package linux-libc-dev make-cross-package tzdata yes make-cross-arch-package libc6 case $DEBARCH in mips | mipsel) make-cross-arch-package libc6-mips64 yes make-cross-arch-package libc6-mipsn32 yes ;; powerpc) make-cross-arch-package libc6-ppc64 yes ;; sparc) make-cross-arch-package libc6-sparc64 yes ;; esac make-cross-arch-package libc6-dev case $DEBARCH in mips | mipsel) make-cross-arch-package libc6-dev-mips64 yes make-cross-arch-package libc6-dev-mipsn32 yes ;; powerpc) make-cross-arch-package libc6-dev-ppc64 yes ;; sparc) make-cross-arch-package libc6-dev-sparc64 yes ;; esac make-cross-arch-package libgcc1 make-cross-arch-package libstdc++6 popd } # build and install cross binutils build-binutils () { local _upver=$(upstreamversion binutils) local _version=$(version binutils) local _dir=$(sourcedir binutils) mkdir -p binutils pushd binutils $ROOTCMD apt-get -y build-dep binutils if [ ! -d binutils-${_version} ] || [ "$CLEANTREE" = "yes" ]; then rm -rf $_dir binutils-${_version} apt-get source binutils pushd $_dir echo "${DEBARCH}" > debian/target popd mv $_dir binutils-${_version} fi popd apply-patches binutils binutils-${_version} pushd binutils/binutils-${_version} # dpkg-buildpackage -us -uc -B -rfakeroot TARGET=${DEBARCH} fakeroot debian/rules binary-cross popd add-to-repository binutils # install pushd binutils $ROOTCMD dpkg -i \ binutils-${PKGARCH}-linux-${PKGABI}_${_version}_${HOSTARCH}.deb popd } install-gcc-build-deps () { $ROOTCMD apt-get -y build-dep gcc-$1 } # build cross gcc versions: build-gcc build-gcc () { local _upver=$(upstreamversion gcc-$1) local _version=$(version gcc-$1) local _dir=$(sourcedir gcc-$1) local _vers=$(sourcedir_v gcc-$1) mkdir -p gcc-$1 pushd gcc-$1 if [ ! -d gcc-$1-${_version} ] || [ "$CLEANTREE" = "yes" ]; then rm -rf $_dir gcc-$1-${_version} apt-get source gcc-$1 # @FIXME: fixed #pushd $_dir pushd $_vers echo "${DEBARCH}" > debian/target GCC_TARGET=${DEBARCH} DEB_CROSS=yes fakeroot debian/rules control popd # mv $_dir gcc-$1-${_version} mv $_vers gcc-$1-${_version} fi popd apply-patches gcc-$1 gcc-$1-${_version} pushd gcc-$1/gcc-$1-${_version} export LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH GCC_TARGET=${DEBARCH} DEB_CROSS=yes dpkg-buildpackage -us -uc -B -rfakeroot export LD_LIBRARY_PATH=$DEF_LD_LIBRARY_PATH popd add-to-repository gcc-$1 } # install cross gcc versions: install-gcc install-gcc () { local _version=$(version gcc-$1) local _filelist="cpp-$1-${PKGARCH}-linux-${PKGABI}_${_version}_${HOSTARCH}.deb \ g++-$1-${PKGARCH}-linux-${PKGABI}_${_version}_${HOSTARCH}.deb \ gcc-$1-${PKGARCH}-linux-${PKGABI}_${_version}_${HOSTARCH}.deb \ libstdc++6-$1-dev-${DEBARCH}-cross_${_version}_all.deb \ libstdc++6-$1-pic-${DEBARCH}-cross_${_version}_all.deb \ libstdc++6-${DEBARCH}-cross_${_version}_all.deb" mkdir -p gcc-$1 pushd gcc-$1 if [ -f libgcc1-${DEBARCH}-cross_${_version}_all.deb ]; then _filelist="$_filelist libgcc1-${DEBARCH}-cross_${_version}_all.deb" fi if [ -f gcc-$1-${PKGARCH}-linux-${PKGABI}-base_${_version}_${HOSTARCH}.deb ]; then _filelist="$_filelist gcc-$1-${PKGARCH}-linux-${PKGABI}-base_${_version}_${HOSTARCH}.deb" fi $ROOTCMD dpkg -i $_filelist popd } # build and install cross gcc-4.0 build-gcc-4.0 () { install-gcc-build-deps 4.0 build-gcc 4.0 # install-gcc 4.0 } # build cross gcc-4.1 build-gcc-4.1 () { install-gcc-build-deps 4.1 build-gcc 4.1 # install-gcc 4.1 } # build cross gcc-4.2 build-gcc-4.2 () { install-gcc-build-deps 4.2 build-gcc 4.2 # install-gcc 4.2 } # build cross gcc-4.3 build-gcc-4.3 () { install-gcc-build-deps 4.3 build-gcc 4.3 install-gcc 4.3 } # build cross gcc-snapshot build-gcc-snapshot () { # Hack, hack. pushd /usr/lib $ROOTCMD ln -sf /usr gcc-snapshot popd install-gcc-build-deps snapshot build-gcc snapshot # install-gcc snapshot } #---------------------------------------------------------------------- # Finally, do the work. # sanity check build environment checkinstalled build-essential dpkg-cross devscripts fakeroot sudo quilt reprepro # dpkg-cross version check if [[ "1.17" > $(dpkg-cross --help 2>&1 |awk '{print $3; exit;}') ]]; then echo "dpkg-cross is too old." exit 1 fi # get package lists get-package-lists init-repository # make everything build-libs build-binutils ##build-gcc-4.0 #build-gcc-4.1 #build-gcc-4.2 build-gcc-4.3 #build-gcc-snapshot