# HG changeset patch # User Christophe Lincoln # Date 1336594539 -7200 # Node ID e7e7979eb49dca7e4dbbb04629baf5e5319ef894 # Parent c75f13234af0bfbfbe787a12a0eae14629b3b0fc Add cross (let have a cross toolchain builder) diff -r c75f13234af0 -r e7e7979eb49d Makefile --- a/Makefile Wed May 09 19:00:35 2012 +0200 +++ b/Makefile Wed May 09 22:15:39 2012 +0200 @@ -7,12 +7,12 @@ all: install: - install -m 0777 -d $(DESTDIR)/etc/slitaz - install -m 0777 -d $(DESTDIR)$(PREFIX)/bin - install -m 0777 -d $(DESTDIR)/var/www/cooker - install -m 0777 -d $(DESTDIR)$(PREFIX)/share/applications - install -m 0777 -d $(DESTDIR)$(PREFIX)/share/cook - install -m 0777 -d $(DESTDIR)$(PREFIX)/share/doc/cookutils + install -m 0755 -d $(DESTDIR)/etc/slitaz + install -m 0755-d $(DESTDIR)$(PREFIX)/bin + install -m 0755 -d $(DESTDIR)/var/www/cooker + install -m 0755 -d $(DESTDIR)$(PREFIX)/share/applications + install -m 0755 -d $(DESTDIR)$(PREFIX)/share/cook + install -m 0755 -d $(DESTDIR)$(PREFIX)/share/doc/cookutils install -m 0755 cook $(DESTDIR)$(PREFIX)/bin install -m 0755 cooker $(DESTDIR)$(PREFIX)/bin install -m 0755 cookiso $(DESTDIR)$(PREFIX)/bin @@ -32,3 +32,19 @@ $(DESTDIR)$(PREFIX)/bin/cooker \ $(DESTDIR)/etc/slitaz/cook.* \ $(DESTDIR)/var/www/cooker + +# Cross + +install-cross: + install -m 0755 -d $(DESTDIR)/etc/slitaz + install -m 0755 -d $(DESTDIR)$(PREFIX)/bin + install -m 0755 -d $(DESTDIR)$(PREFIX)/share/doc/cookutils + install -m 0755 cross $(DESTDIR)$(PREFIX)/bin + install -m 0644 cross.conf $(DESTDIR)/etc/slitaz + install -m 0644 doc/cross.txt $(DESTDIR)$(PREFIX)/share/doc/cookutils + +uninstall-cross: + rm -rf \ + $(DESTDIR)$(PREFIX)/bin/cross \ + $(DESTDIR)/etc/slitaz/cross.conf \ + $(DESTDIR)$(PREFIX)/share/doc/cookutils/cross.txt diff -r c75f13234af0 -r e7e7979eb49d cross --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross Wed May 09 22:15:39 2012 +0200 @@ -0,0 +1,272 @@ +#!/bin/sh +# +# Cross - Help build a cross toolchain on SliTaz. +# +# Copyright 2012 (C) SliTaz GNU/Linux - BSD License +# Author: Christophe Lincoln +# +. /lib/libtaz.sh +. cross.conf || exit 1 + +# Help and usage. +usage() { + cat << EOT + +Usage: $(basename $0) command --option + +Commands: + howto Man alike and howto + info Dispaly cross-tools info + testsuite Execute a small testsuite + check-env Check build host tools + download Download necessary sources + clean Clean-up environment + show-log Show a compile log + binutils Compile Binutils + gcc-static Compile GCC static + linux-headers Install Kernel headers + glibc Compile GNU Glibc + gcc-final Compile final GCC + busybox Cross compile Busybox + compile Compile everything at once + +EOT +} + +# Make sure we have all directories. +init_compile() { + export LC_ALL=POSIX LANG=POSIX + export PATH=$PATH:$PREFIX/bin + export CROSS_COMPILE=$TARGET- + source=$WORK/source + logdir=$WORK/log + mkdir -p $source $logdir $install + cd $source +} + +# Get source if not yet in $SRC. +download_src() { + mkdir -p $SRC && cd $SRC + [ -f "binutils-$BINUTILS_VERSION.tar.bz2" ] || wget $BINUTILS_WGET + [ -f "linux-$LINUX_VERSION.tar.bz2" ] || wget $LINUX_WGET + [ -f "glibc-$GLIBC_VERSION.tar.bz2" ] || wget $GLIBC_WGET + [ -f "gcc-$GCC_VERSION.tar.bz2" ] || wget $GCC_WGET + [ -f "busybox-$BUSYBOX_VERSION.tar.bz2" ] || wget $BUSYBOX_WGET +} + +# 1. Binutils +binutils() { + echo "Extracting: binutils-$BINUTILS_VERSION.tar.bz2" + tar xjf $SRC/binutils-$BINUTILS_VERSION.tar.bz2 + # Peer arch options --disable-werror + case $ARCH in + arm) archopts="" ;; + x86_64) archopts="" ;; + esac + cd binutils-$BINUTILS_VERSION + ./configure \ + --prefix=$PREFIX \ + --target=$TARGET \ + --enable-targets=$BUILD_SYSTEM \ + --enable-shared $archopts + make || exit 1 + make install +} + +# 2. Kernel headers +linux_headers() { + echo "Extracting: linux-$LINUX_VERSION.tar.bz2" + tar xjf $SRC/linux-$LINUX_VERSION.tar.bz2 + cd linux-$LINUX_VERSION + make mrproper + make ARCH=$ARCH headers_check + make ARCH=$ARCH headers_install \ + INSTALL_HDR_PATH=$PREFIX +} + +# 3. GCC static (first pass) +gcc_static() { + echo "Extracting: gcc-$GCC_VERSION.tar.bz2" + tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2 + # Peer arch options + case $ARCH in + arm) archopts="" ;; + x86_64) archopts="" ;; + esac + rm -rf gcc-static + mkdir gcc-static && cd gcc-static + ../gcc-$GCC_VERSION/configure \ + --prefix=$PREFIX \ + --target=$TARGET \ + --disable-shared \ + --disable-threads \ + --without-headers \ + --with-newlib \ + --enable-languages=c + make all-gcc all-target-libgcc || exit 1 + make install-gcc install-target-libgcc + cd $PREFIX/lib/gcc/$TARGET/$GCC_VERSION + ln -s libgcc.a libgcc_eh.a +} + +# 4. GNU Glibc +glibc() { + echo "Extracting: glibc-$GLIBC_VERSION.tar.bz2" + tar xjf $SRC/glibc-$GLIBC_VERSION.tar.bz2 + [ "$continue" ] || rm -rf glibc-build + # Peer arch options + case $ARCH in + arm) + archopts="" + echo "Extracting: glibc-ports-$GLIBC_VERSION.tar.bz2" + rm -rf glibc-$GLIBC_VERSION/ports + tar xjf $SRC/glibc-ports-$GLIBC_VERSION.tar.bz2 + mv glibc-ports-$GLIBC_VERSION glibc-$GLIBC_VERSION/ports ;; + x86_64) + archopts="" ;; + esac + mkdir -p glibc-build && cd glibc-build + BUILD_CC="gcc" + CC="$PREFIX/bin/$TARGET-gcc" \ + libc_cv_forced_unwind=yes \ + libc_cv_c_cleanup=yes \ + ../glibc-$GLIBC_VERSION/configure \ + --prefix=$PREFIX \ + --host=$TARGET \ + --with-headers=$PREFIX/include \ + --with-binutils=$PREFIX/bin \ + --enable-add-ons + make || exit 1 + make install + cd $PREFIX/$TARGET + rm -rf lib include + ln -s ../lib lib + ln -s ../include include +} + +# 5. GCC final +gcc_final() { + if [ ! -d "gcc-$GCC_VERSION" ]; then + echo "Extracting: gcc-$GCC_VERSION.tar.bz2" + tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2 + fi + # Peer arch options + case $ARCH in + arm) archopts="" ;; + x86_64) archopts="" ;; + esac + rm -rf gcc-build + mkdir gcc-build && cd gcc-build + ../gcc-$GCC_VERSION/configure \ + --prefix=$PREFIX \ + --target=$TARGET \ + --enable-shared \ + --enable-languages=c,c++ \ + --enable-c99 \ + --enable-long-long \ + --enable-__cxa_atexit \ + --with-pkgversion="SliTaz" + make || exit 1 + make install +} + +# Build Busybox to we can create prebuild tiny rootfs image and boot +# from NFS ? +cross_busybox() { + echo "Extracting: busybox-$BUSYBOX_VERSION.tar.bz2" + tar xjf $SRC/busybox-$BUSYBOX_VERSION.tar.bz2 + cd busybox-$BUSYBOX_VERSION + # CROSS_COMPILE is exported via init_compile, but be sure. + make CROSS_COMPILE=$TARGET- defconfig + make CROSS_COMPILE=$TARGET- || exit 1 + make CROSS_COMPILE=$TARGET- install + chmod 4755 _install/bin/busybox + readelf -h _install/bin/busybox +} + +# +# Commands +# + +case "$1" in + howto|man) + doc=/usr/share/doc/cookutils/cross.txt + [ -f "$doc" ] && less -E $doc ;; + info) + init_compile + CC=${TARGET}-gcc + echo -e "\nCross Toolchain iformation" && separator + cat << EOT +Target arch : $ARCH +C Compiler : $CC +Additonal path: /usr/cross/$ARCH/bin +EOT + separator && echo "" + echo "GCC version" && separator + $CC -v + separator && echo "" ;; + testsuite) + init_compile + echo "[COMPILING] $TARGET-gcc -v -Wall -o test.out test.c" \ + | tee $logdir/testsuite.log + echo 'int main() { return 0; }' > test.c + $TARGET-gcc -v -Wall -o test.out test.c 2>&1 | tee -a $logdir/testsuite.log + if [ -x /usr/bin/file ]; then + echo -e "\n[CHECKING] file test.out" | tee -a $logdir/testsuite.log + file test.out | tee -a $logdir/testsuite.log + fi + echo -e "\n[CHECKING] readelf -h test.out" | tee -a $logdir/testsuite.log + readelf -h test.out | tee -a $logdir/testsuite.log ;; + check-host) + for pkg in mpfr mpfr-dev gmp gmp-dev mpc-library gawk autoconf + do + if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then + echo "Missing packages: $pkg" + [ "$install" ] && tazpkg -gi $pkg + fi + done ;; + download) + download_src ;; + clean) + echo -n "Remove all source files..." + rm -rf $WORK/source/* && status + [ "$log" ] && rm -f $WORK/log/*.log + echo "To clean chroot: rm -rf $PREFIX" ;; + show-log) + pkg=$2 + less -E $logdir/$pkg.log ;; + binutils) + init_compile + rm -f $logdir/binutils.log + binutils 2>&1 | tee $logdir/binutils.log ;; + linux-headers) + init_compile + linux_headers 2>&1 | tee $logdir/$logdir/linux-headers.log ;; + gcc-static) + init_compile + gcc_static 2>&1 | tee $logdir/gcc-static.log ;; + glibc) + init_compile + glibc 2>&1 | tee $logdir/glibc.log ;; + gcc-final) + init_compile + gcc_final 2>&1 | tee $logdir/gcc-final.log ;; + busybox) + init_compile + cross_busybox 2>&1 | tee $logdir/busybox.log ;; + compile) + init_compile + echo "Compile start: $(date)" | tee $logdir/compile.log + download_src + binutils 2>&1 | tee $logdir/binutils.log + linux_headers 2>&1 | tee $logdir/linux-headers.log + gcc_static 2>&1 | tee $logdir/gcc-static.log + glibc 2>&1 | tee $logdir/glibc.log + gcc_final 2>&1 | tee $logdir/gcc-final.log + echo "" + echo "Compile end: $(date)" | tee -a $logdir/compile.log + echo "" ;; + *) + usage ;; +esac + diff -r c75f13234af0 -r e7e7979eb49d cross.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross.conf Wed May 09 22:15:39 2012 +0200 @@ -0,0 +1,24 @@ +# SliTaz Cross Toolchain configuration file +# + +# Main settings +ARCH=arm +BUILD_SYSTEM=i486-slitaz-linux +TARGET=$ARCH-slitaz-linux-gnueabi +WORK=$(pwd) +SRC=/home/slitaz/src +PREFIX=/usr/cross/$ARCH + +# Cross-tools versions +BINUTILS_VERSION="2.22" +LINUX_VERSION="2.6.35.13" +GLIBC_VERSION="2.13" +GCC_VERSION="4.6.3" +BUSYBOX_VERSION="1.20.0" + +# Cross tools urls +BINUTILS_WGET="http://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.bz2" +LINUX_WGET="http://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.35/linux-$LINUX_VERSION.tar.bz2" +GLIBC_WGET="http://ftp.gnu.org/gnu/libc/glibc-$GLIBC_VERSION.tar.bz2" +GCC_WGET="http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2" +BUSYBOX_WGET="http://busybox.net/downloads/busybox-$BUSYBOX_VERSION.tar.bz2" diff -r c75f13234af0 -r e7e7979eb49d doc/cross.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/cross.txt Wed May 09 22:15:39 2012 +0200 @@ -0,0 +1,48 @@ + +SYNOPSIS + cross [command|package] package + +DESCRIPTION + Cross is a tool to build a cross toolchain on SliTaz GNU/Linux. The + ARM platform is actually supported and x86_64 toolchain is on the + stove + +COMMANDS + Run: cross usage + +OPTIONS + --log clean: Will also clean log files + --install check-env: Install needed packages + +HOWTO: + When building a cross toolchain it's better to understand what is a + linker or or C compiler such as GCC. The configure option --target is + used by 'cross' to build cross-tools. When the toolchain is build on + your machine you can then build packages with cook and the wok. Here + is commands used to create a chroot (use last tazdev): + + # tazdev gen-chroot --arch=arm + # tazdev chroot + + --> Clone cookutils to get last cook and cross + # tazpkg -gi mercurial + # tazpkg -gi make + # cd && hg clone http://hg.slitaz.org/cookutils + # cd cookutils + # make install-cross + + --> Now setup the build environment and compile a cross toolchain: + # cook setup + # cook arm-setup + # mkdir -p /home/slitaz/cross + # cd /home/slitaz/cross + # cp /etc/slitaz/cross.conf . + (vi/nano config) + # cross check-env --install + # cross compile + + --> Test the cross tools + # cross testsuite + +AUTHOR + Written by Christophe Lincoln