cookutils rev 361
Add cross (let have a cross toolchain builder)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed May 09 22:15:39 2012 +0200 (2012-05-09) |
parents | c75f13234af0 |
children | e60f4a6df297 |
files | Makefile cross cross.conf doc/cross.txt |
line diff
1.1 --- a/Makefile Wed May 09 19:00:35 2012 +0200 1.2 +++ b/Makefile Wed May 09 22:15:39 2012 +0200 1.3 @@ -7,12 +7,12 @@ 1.4 all: 1.5 1.6 install: 1.7 - install -m 0777 -d $(DESTDIR)/etc/slitaz 1.8 - install -m 0777 -d $(DESTDIR)$(PREFIX)/bin 1.9 - install -m 0777 -d $(DESTDIR)/var/www/cooker 1.10 - install -m 0777 -d $(DESTDIR)$(PREFIX)/share/applications 1.11 - install -m 0777 -d $(DESTDIR)$(PREFIX)/share/cook 1.12 - install -m 0777 -d $(DESTDIR)$(PREFIX)/share/doc/cookutils 1.13 + install -m 0755 -d $(DESTDIR)/etc/slitaz 1.14 + install -m 0755-d $(DESTDIR)$(PREFIX)/bin 1.15 + install -m 0755 -d $(DESTDIR)/var/www/cooker 1.16 + install -m 0755 -d $(DESTDIR)$(PREFIX)/share/applications 1.17 + install -m 0755 -d $(DESTDIR)$(PREFIX)/share/cook 1.18 + install -m 0755 -d $(DESTDIR)$(PREFIX)/share/doc/cookutils 1.19 install -m 0755 cook $(DESTDIR)$(PREFIX)/bin 1.20 install -m 0755 cooker $(DESTDIR)$(PREFIX)/bin 1.21 install -m 0755 cookiso $(DESTDIR)$(PREFIX)/bin 1.22 @@ -32,3 +32,19 @@ 1.23 $(DESTDIR)$(PREFIX)/bin/cooker \ 1.24 $(DESTDIR)/etc/slitaz/cook.* \ 1.25 $(DESTDIR)/var/www/cooker 1.26 + 1.27 +# Cross 1.28 + 1.29 +install-cross: 1.30 + install -m 0755 -d $(DESTDIR)/etc/slitaz 1.31 + install -m 0755 -d $(DESTDIR)$(PREFIX)/bin 1.32 + install -m 0755 -d $(DESTDIR)$(PREFIX)/share/doc/cookutils 1.33 + install -m 0755 cross $(DESTDIR)$(PREFIX)/bin 1.34 + install -m 0644 cross.conf $(DESTDIR)/etc/slitaz 1.35 + install -m 0644 doc/cross.txt $(DESTDIR)$(PREFIX)/share/doc/cookutils 1.36 + 1.37 +uninstall-cross: 1.38 + rm -rf \ 1.39 + $(DESTDIR)$(PREFIX)/bin/cross \ 1.40 + $(DESTDIR)/etc/slitaz/cross.conf \ 1.41 + $(DESTDIR)$(PREFIX)/share/doc/cookutils/cross.txt
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/cross Wed May 09 22:15:39 2012 +0200 2.3 @@ -0,0 +1,272 @@ 2.4 +#!/bin/sh 2.5 +# 2.6 +# Cross - Help build a cross toolchain on SliTaz. 2.7 +# 2.8 +# Copyright 2012 (C) SliTaz GNU/Linux - BSD License 2.9 +# Author: Christophe Lincoln <pankso@slitaz.org> 2.10 +# 2.11 +. /lib/libtaz.sh 2.12 +. cross.conf || exit 1 2.13 + 2.14 +# Help and usage. 2.15 +usage() { 2.16 + cat << EOT 2.17 + 2.18 +Usage: $(basename $0) command --option 2.19 + 2.20 +Commands: 2.21 + howto Man alike and howto 2.22 + info Dispaly cross-tools info 2.23 + testsuite Execute a small testsuite 2.24 + check-env Check build host tools 2.25 + download Download necessary sources 2.26 + clean Clean-up environment 2.27 + show-log Show a compile log 2.28 + binutils Compile Binutils 2.29 + gcc-static Compile GCC static 2.30 + linux-headers Install Kernel headers 2.31 + glibc Compile GNU Glibc 2.32 + gcc-final Compile final GCC 2.33 + busybox Cross compile Busybox 2.34 + compile Compile everything at once 2.35 + 2.36 +EOT 2.37 +} 2.38 + 2.39 +# Make sure we have all directories. 2.40 +init_compile() { 2.41 + export LC_ALL=POSIX LANG=POSIX 2.42 + export PATH=$PATH:$PREFIX/bin 2.43 + export CROSS_COMPILE=$TARGET- 2.44 + source=$WORK/source 2.45 + logdir=$WORK/log 2.46 + mkdir -p $source $logdir $install 2.47 + cd $source 2.48 +} 2.49 + 2.50 +# Get source if not yet in $SRC. 2.51 +download_src() { 2.52 + mkdir -p $SRC && cd $SRC 2.53 + [ -f "binutils-$BINUTILS_VERSION.tar.bz2" ] || wget $BINUTILS_WGET 2.54 + [ -f "linux-$LINUX_VERSION.tar.bz2" ] || wget $LINUX_WGET 2.55 + [ -f "glibc-$GLIBC_VERSION.tar.bz2" ] || wget $GLIBC_WGET 2.56 + [ -f "gcc-$GCC_VERSION.tar.bz2" ] || wget $GCC_WGET 2.57 + [ -f "busybox-$BUSYBOX_VERSION.tar.bz2" ] || wget $BUSYBOX_WGET 2.58 +} 2.59 + 2.60 +# 1. Binutils 2.61 +binutils() { 2.62 + echo "Extracting: binutils-$BINUTILS_VERSION.tar.bz2" 2.63 + tar xjf $SRC/binutils-$BINUTILS_VERSION.tar.bz2 2.64 + # Peer arch options --disable-werror 2.65 + case $ARCH in 2.66 + arm) archopts="" ;; 2.67 + x86_64) archopts="" ;; 2.68 + esac 2.69 + cd binutils-$BINUTILS_VERSION 2.70 + ./configure \ 2.71 + --prefix=$PREFIX \ 2.72 + --target=$TARGET \ 2.73 + --enable-targets=$BUILD_SYSTEM \ 2.74 + --enable-shared $archopts 2.75 + make || exit 1 2.76 + make install 2.77 +} 2.78 + 2.79 +# 2. Kernel headers 2.80 +linux_headers() { 2.81 + echo "Extracting: linux-$LINUX_VERSION.tar.bz2" 2.82 + tar xjf $SRC/linux-$LINUX_VERSION.tar.bz2 2.83 + cd linux-$LINUX_VERSION 2.84 + make mrproper 2.85 + make ARCH=$ARCH headers_check 2.86 + make ARCH=$ARCH headers_install \ 2.87 + INSTALL_HDR_PATH=$PREFIX 2.88 +} 2.89 + 2.90 +# 3. GCC static (first pass) 2.91 +gcc_static() { 2.92 + echo "Extracting: gcc-$GCC_VERSION.tar.bz2" 2.93 + tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2 2.94 + # Peer arch options 2.95 + case $ARCH in 2.96 + arm) archopts="" ;; 2.97 + x86_64) archopts="" ;; 2.98 + esac 2.99 + rm -rf gcc-static 2.100 + mkdir gcc-static && cd gcc-static 2.101 + ../gcc-$GCC_VERSION/configure \ 2.102 + --prefix=$PREFIX \ 2.103 + --target=$TARGET \ 2.104 + --disable-shared \ 2.105 + --disable-threads \ 2.106 + --without-headers \ 2.107 + --with-newlib \ 2.108 + --enable-languages=c 2.109 + make all-gcc all-target-libgcc || exit 1 2.110 + make install-gcc install-target-libgcc 2.111 + cd $PREFIX/lib/gcc/$TARGET/$GCC_VERSION 2.112 + ln -s libgcc.a libgcc_eh.a 2.113 +} 2.114 + 2.115 +# 4. GNU Glibc 2.116 +glibc() { 2.117 + echo "Extracting: glibc-$GLIBC_VERSION.tar.bz2" 2.118 + tar xjf $SRC/glibc-$GLIBC_VERSION.tar.bz2 2.119 + [ "$continue" ] || rm -rf glibc-build 2.120 + # Peer arch options 2.121 + case $ARCH in 2.122 + arm) 2.123 + archopts="" 2.124 + echo "Extracting: glibc-ports-$GLIBC_VERSION.tar.bz2" 2.125 + rm -rf glibc-$GLIBC_VERSION/ports 2.126 + tar xjf $SRC/glibc-ports-$GLIBC_VERSION.tar.bz2 2.127 + mv glibc-ports-$GLIBC_VERSION glibc-$GLIBC_VERSION/ports ;; 2.128 + x86_64) 2.129 + archopts="" ;; 2.130 + esac 2.131 + mkdir -p glibc-build && cd glibc-build 2.132 + BUILD_CC="gcc" 2.133 + CC="$PREFIX/bin/$TARGET-gcc" \ 2.134 + libc_cv_forced_unwind=yes \ 2.135 + libc_cv_c_cleanup=yes \ 2.136 + ../glibc-$GLIBC_VERSION/configure \ 2.137 + --prefix=$PREFIX \ 2.138 + --host=$TARGET \ 2.139 + --with-headers=$PREFIX/include \ 2.140 + --with-binutils=$PREFIX/bin \ 2.141 + --enable-add-ons 2.142 + make || exit 1 2.143 + make install 2.144 + cd $PREFIX/$TARGET 2.145 + rm -rf lib include 2.146 + ln -s ../lib lib 2.147 + ln -s ../include include 2.148 +} 2.149 + 2.150 +# 5. GCC final 2.151 +gcc_final() { 2.152 + if [ ! -d "gcc-$GCC_VERSION" ]; then 2.153 + echo "Extracting: gcc-$GCC_VERSION.tar.bz2" 2.154 + tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2 2.155 + fi 2.156 + # Peer arch options 2.157 + case $ARCH in 2.158 + arm) archopts="" ;; 2.159 + x86_64) archopts="" ;; 2.160 + esac 2.161 + rm -rf gcc-build 2.162 + mkdir gcc-build && cd gcc-build 2.163 + ../gcc-$GCC_VERSION/configure \ 2.164 + --prefix=$PREFIX \ 2.165 + --target=$TARGET \ 2.166 + --enable-shared \ 2.167 + --enable-languages=c,c++ \ 2.168 + --enable-c99 \ 2.169 + --enable-long-long \ 2.170 + --enable-__cxa_atexit \ 2.171 + --with-pkgversion="SliTaz" 2.172 + make || exit 1 2.173 + make install 2.174 +} 2.175 + 2.176 +# Build Busybox to we can create prebuild tiny rootfs image and boot 2.177 +# from NFS ? 2.178 +cross_busybox() { 2.179 + echo "Extracting: busybox-$BUSYBOX_VERSION.tar.bz2" 2.180 + tar xjf $SRC/busybox-$BUSYBOX_VERSION.tar.bz2 2.181 + cd busybox-$BUSYBOX_VERSION 2.182 + # CROSS_COMPILE is exported via init_compile, but be sure. 2.183 + make CROSS_COMPILE=$TARGET- defconfig 2.184 + make CROSS_COMPILE=$TARGET- || exit 1 2.185 + make CROSS_COMPILE=$TARGET- install 2.186 + chmod 4755 _install/bin/busybox 2.187 + readelf -h _install/bin/busybox 2.188 +} 2.189 + 2.190 +# 2.191 +# Commands 2.192 +# 2.193 + 2.194 +case "$1" in 2.195 + howto|man) 2.196 + doc=/usr/share/doc/cookutils/cross.txt 2.197 + [ -f "$doc" ] && less -E $doc ;; 2.198 + info) 2.199 + init_compile 2.200 + CC=${TARGET}-gcc 2.201 + echo -e "\nCross Toolchain iformation" && separator 2.202 + cat << EOT 2.203 +Target arch : $ARCH 2.204 +C Compiler : $CC 2.205 +Additonal path: /usr/cross/$ARCH/bin 2.206 +EOT 2.207 + separator && echo "" 2.208 + echo "GCC version" && separator 2.209 + $CC -v 2.210 + separator && echo "" ;; 2.211 + testsuite) 2.212 + init_compile 2.213 + echo "[COMPILING] $TARGET-gcc -v -Wall -o test.out test.c" \ 2.214 + | tee $logdir/testsuite.log 2.215 + echo 'int main() { return 0; }' > test.c 2.216 + $TARGET-gcc -v -Wall -o test.out test.c 2>&1 | tee -a $logdir/testsuite.log 2.217 + if [ -x /usr/bin/file ]; then 2.218 + echo -e "\n[CHECKING] file test.out" | tee -a $logdir/testsuite.log 2.219 + file test.out | tee -a $logdir/testsuite.log 2.220 + fi 2.221 + echo -e "\n[CHECKING] readelf -h test.out" | tee -a $logdir/testsuite.log 2.222 + readelf -h test.out | tee -a $logdir/testsuite.log ;; 2.223 + check-host) 2.224 + for pkg in mpfr mpfr-dev gmp gmp-dev mpc-library gawk autoconf 2.225 + do 2.226 + if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then 2.227 + echo "Missing packages: $pkg" 2.228 + [ "$install" ] && tazpkg -gi $pkg 2.229 + fi 2.230 + done ;; 2.231 + download) 2.232 + download_src ;; 2.233 + clean) 2.234 + echo -n "Remove all source files..." 2.235 + rm -rf $WORK/source/* && status 2.236 + [ "$log" ] && rm -f $WORK/log/*.log 2.237 + echo "To clean chroot: rm -rf $PREFIX" ;; 2.238 + show-log) 2.239 + pkg=$2 2.240 + less -E $logdir/$pkg.log ;; 2.241 + binutils) 2.242 + init_compile 2.243 + rm -f $logdir/binutils.log 2.244 + binutils 2>&1 | tee $logdir/binutils.log ;; 2.245 + linux-headers) 2.246 + init_compile 2.247 + linux_headers 2>&1 | tee $logdir/$logdir/linux-headers.log ;; 2.248 + gcc-static) 2.249 + init_compile 2.250 + gcc_static 2>&1 | tee $logdir/gcc-static.log ;; 2.251 + glibc) 2.252 + init_compile 2.253 + glibc 2>&1 | tee $logdir/glibc.log ;; 2.254 + gcc-final) 2.255 + init_compile 2.256 + gcc_final 2>&1 | tee $logdir/gcc-final.log ;; 2.257 + busybox) 2.258 + init_compile 2.259 + cross_busybox 2>&1 | tee $logdir/busybox.log ;; 2.260 + compile) 2.261 + init_compile 2.262 + echo "Compile start: $(date)" | tee $logdir/compile.log 2.263 + download_src 2.264 + binutils 2>&1 | tee $logdir/binutils.log 2.265 + linux_headers 2>&1 | tee $logdir/linux-headers.log 2.266 + gcc_static 2>&1 | tee $logdir/gcc-static.log 2.267 + glibc 2>&1 | tee $logdir/glibc.log 2.268 + gcc_final 2>&1 | tee $logdir/gcc-final.log 2.269 + echo "" 2.270 + echo "Compile end: $(date)" | tee -a $logdir/compile.log 2.271 + echo "" ;; 2.272 + *) 2.273 + usage ;; 2.274 +esac 2.275 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/cross.conf Wed May 09 22:15:39 2012 +0200 3.3 @@ -0,0 +1,24 @@ 3.4 +# SliTaz Cross Toolchain configuration file 3.5 +# 3.6 + 3.7 +# Main settings 3.8 +ARCH=arm 3.9 +BUILD_SYSTEM=i486-slitaz-linux 3.10 +TARGET=$ARCH-slitaz-linux-gnueabi 3.11 +WORK=$(pwd) 3.12 +SRC=/home/slitaz/src 3.13 +PREFIX=/usr/cross/$ARCH 3.14 + 3.15 +# Cross-tools versions 3.16 +BINUTILS_VERSION="2.22" 3.17 +LINUX_VERSION="2.6.35.13" 3.18 +GLIBC_VERSION="2.13" 3.19 +GCC_VERSION="4.6.3" 3.20 +BUSYBOX_VERSION="1.20.0" 3.21 + 3.22 +# Cross tools urls 3.23 +BINUTILS_WGET="http://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.bz2" 3.24 +LINUX_WGET="http://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.35/linux-$LINUX_VERSION.tar.bz2" 3.25 +GLIBC_WGET="http://ftp.gnu.org/gnu/libc/glibc-$GLIBC_VERSION.tar.bz2" 3.26 +GCC_WGET="http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2" 3.27 +BUSYBOX_WGET="http://busybox.net/downloads/busybox-$BUSYBOX_VERSION.tar.bz2"
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/doc/cross.txt Wed May 09 22:15:39 2012 +0200 4.3 @@ -0,0 +1,48 @@ 4.4 + 4.5 +SYNOPSIS 4.6 + cross [command|package] package 4.7 + 4.8 +DESCRIPTION 4.9 + Cross is a tool to build a cross toolchain on SliTaz GNU/Linux. The 4.10 + ARM platform is actually supported and x86_64 toolchain is on the 4.11 + stove 4.12 + 4.13 +COMMANDS 4.14 + Run: cross usage 4.15 + 4.16 +OPTIONS 4.17 + --log clean: Will also clean log files 4.18 + --install check-env: Install needed packages 4.19 + 4.20 +HOWTO: 4.21 + When building a cross toolchain it's better to understand what is a 4.22 + linker or or C compiler such as GCC. The configure option --target is 4.23 + used by 'cross' to build cross-tools. When the toolchain is build on 4.24 + your machine you can then build packages with cook and the wok. Here 4.25 + is commands used to create a chroot (use last tazdev): 4.26 + 4.27 + # tazdev gen-chroot --arch=arm 4.28 + # tazdev chroot 4.29 + 4.30 + --> Clone cookutils to get last cook and cross 4.31 + # tazpkg -gi mercurial 4.32 + # tazpkg -gi make 4.33 + # cd && hg clone http://hg.slitaz.org/cookutils 4.34 + # cd cookutils 4.35 + # make install-cross 4.36 + 4.37 + --> Now setup the build environment and compile a cross toolchain: 4.38 + # cook setup 4.39 + # cook arm-setup 4.40 + # mkdir -p /home/slitaz/cross 4.41 + # cd /home/slitaz/cross 4.42 + # cp /etc/slitaz/cross.conf . 4.43 + (vi/nano config) 4.44 + # cross check-env --install 4.45 + # cross compile 4.46 + 4.47 + --> Test the cross tools 4.48 + # cross testsuite 4.49 + 4.50 +AUTHOR 4.51 + Written by Christophe Lincoln