toolchain-build.sh

toolchain-build.sh
#!/bin/bash
#Cross-toolchain builder.
#Copyright 2010-2011 Marcin Bis <marcin@at@bis.org.pl>
#
#<Configuration>
#Directory to install cross-toolchain in. (do not use any spaces in path)
 
CEL=/opt/tools
 
#The following directory structure will be created:
#CEL/
#  lib/         #target system's libraries
#  usr/         #target system's include files and developtment libraries
#  cross-tools/ #cross-toolchain executables, libraries and include files
#For Eglibc some more standard directories and tools are created.
 
#Choose standard C library version. Uncomment either uClibc or eglibc.
#TARGET_LIBC=uClibc
TARGET_LIBC=eglibc
 
#Tools prefix (Without ending -). Choose one. Depends on libc version.
#For uClibc:
#TARGET=arm-none-linux-uclibcgnueabi
#For eglibc:
TARGET=arm-none-linux-gnueabi
 
#Number of jobs to run simultanously (saves a lot of time on multi-cpu/core systems)
JOBS=4
#</Configuration>
[ -e $CEL ] || mkdir $CEL
 
export CEL TARGET
 
export BUILD="make -j$JOBS || exit 1"
 
export PATH=$CEL/cross-tools/bin:$PATH
set -h
 
#Pathes are defined here
function get_all () {
#wget -c http://www.kernel.org/pub/linux/kernel/v2.65linux-2.6.32.16.tar.bz2
wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.38.5.tar.bz2
wget -c ftp://ftp.gmplib.org/pub/gmp-4.3.2/gmp-4.3.2.tar.bz2
wget -c http://www.mpfr.org/mpfr-current/mpfr-3.0.1.tar.bz2
wget -c http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz
#wget -c http://www.cs.unipr.it/ppl/Download/ftp/releases/0.10.2/ppl-0.10.2.tar.bz2
#wget -c ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-ppl-0.15.9.tar.gz
wget -c http://ftp.gnu.org/gnu/binutils/binutils-2.21.tar.bz2
wget -c http://ftp.gnu.org/gnu/gcc/gcc-4.5.3/gcc-4.5.3.tar.bz2
wget -c http://www.uclibc.org/downloads/uClibc-0.9.31.tar.bz2
wget -c http://zlib.net/zlib-1.2.5.tar.gz
wget -c http://www.mr511.de/software/libelf-0.8.13.tar.gz
wget -c http://ftp.de.debian.org/debian/pool/main/c/chrpath/chrpath_0.13.orig.tar.gz
svn -q co http://www.eglibc.org/svn/branches/eglibc-2_13 eglibc-2.13-current && \
  tar -czf eglibc-2.13-current.tar.gz eglibc-2.13-current
}
 
#Strip all generated libraries & libs
function do_strip () {
	strip --strip-debug \
		$CEL/cross-tools/lib/* \
		$CEL/cross-tools/arm-none-linux-uclibcgnueabi/lib/* \
		$CEL/cross-tools/libexec/*
	strip --strip-unneeded \
		$CEL/cross-tools/bin/* \
		$CEL/cross-tools/arm-none-linux-uclibcgnueabi/bin/*
	$TARGET-strip --strip-debug \
		$CEL/lib/* \
		$CEL/usr/lib/*
}
 
#Do some cleaning
function clean_target() {
	rm -rf $CEL/*
}
 
#This depends on versions of downloaded software.
function clean_sources() {
	rm -rf \
		linux-2.6.38.5/ \
		gmp-4.3.2/ \
		mpfr-3.0.1/ \
		mpc-0.8.2/ \
		binutils-build/ \
		binutils-2.21 \
		gcc-4.5.3 \
		zlib-1.2.5 \
		libelf-0.8.13 \
		gcc-build \
		gcc-interstep-build \
		gcc-final-build \
		uClibc-0.9.31 \
		eglibc-2.13-current \
		eglibc-build \
		eglibc-final-build \
		chrpath-0.13
}
 
case "$1" in
	--clean)
		clean_sources
		exit $?
		;;
	--distclean)
		clean_sources
		clean_target
		exit $?
		;;
	--build)
		#do nothing, just pass to first build command
		true
		;;
	--get)
		get_all
		exit $?
		;;
	--strip)
		do_strip
		exit $?
		;;
	*)
cat << EOF
"Usage: $0 <--get|--build|--clean|--distclean>"
 
$0 --get       #Fetch all the sources to the current directory (from they original locations).
$0 --build     #Build cross-toolchain, aprox. 3-4GB free space is needed.
$0 --clean     #Removes all build directories (safe after successfull build).
$0 --distclean #Same as clean, plus removes toolchain.
$0 --strip     #Strips toolchain and removes unneded data.
 
See script source for more information.
 
Typical use:
        [$0 --distclean] - if doing rebuild.
	$0 --get
	$0 --build 2>&1 | tee build.log
	$0 --strip
	$0 --clean
 
Do not run as root! Execute script from normal user's account, and make sure that
account have rights to write to $CEL directory. 
EOF
exit 1
 
esac
 
#Make bash show every command before execution.
set -x
 
#=========================== Kernel headers ====================================
tar -xf linux-2.6.38.5.tar.bz2
cd linux-2.6.38.5/
make mrproper
make ARCH=arm INSTALL_HDR_PATH=$CEL/usr headers_install
cd ..
#=========================== gmp ===============================================
tar -xf gmp-4.3.2.tar.bz2
cd gmp-4.3.2/
./configure \
        --prefix=$CEL/cross-tools \
        --disable-shared \
        --enable-static
eval $BUILD
make install
cd ..
#=========================== mpfr ==============================================
tar -xf mpfr-3.0.1.tar.bz2
cd mpfr-3.0.1/
./configure \
        --prefix=$CEL/cross-tools \
        --enable-thread-safe \
        --with-gmp=$CEL/cross-tools \
        --disable-shared \
        --enable-static
eval $BUILD
make install
cd ..
#=========================== mpc ===============================================
tar -xf mpc-0.8.2.tar.gz
cd mpc-0.8.2/
./configure \
        --prefix=$CEL/cross-tools \
        --with-gmp=$CEL/cross-tools \
        --with-mpfr=$CEL/cross-tools \
        --disable-shared \
        --enable-static
eval $BUILD
make install
cd ..
#=========================== zlib ==============================================
tar -xf zlib-1.2.5.tar.gz
cd zlib-1.2.5
./configure \
        --prefix=$CEL/cross-tools
eval $BUILD
make install
cd ..
#=========================== binutils ==========================================
tar -xf binutils-2.21.tar.bz2 
mkdir binutils-build
cd binutils-build/
LDFLAGS="-Wl,-rpath -Wl,$CEL/cross-tools/lib" \
../binutils-2.21/configure \
	--build=$MACHTYPE \
	--host=$MACHTYPE \
	--target=$TARGET \
	--prefix=$CEL/cross-tools \
	--disable-nls \
	--disable-multilib \
	--disable-werror \
	--with-float=soft \
        --with-gmp=$CEL/cross-tools \
        --with-mpfr=$CEL/cross-tools \
        --with-mpc=$CEL/cross-tools \
	--with-sysroot=$CEL
make configure-host
eval $BUILD
make install
cd ..
#=========================== gcc first stage ===================================
tar -xf gcc-4.5.3.tar.bz2
mkdir gcc-build
cd gcc-build
../gcc-4.5.3/configure \
	--build=$MACHTYPE \
	--host=$MACHTYPE \
	--target=$TARGET \
	--prefix=$CEL/cross-tools \
	--with-local-prefix=$CEL/cross-tools \
	--disable-multilib \
	--with-sysroot=$CEL \
	--without-headers \
	--with-newlib \
	--enable-threads=no \
	--disable-shared \
	--with-pkgversion="Marcin Bis" \
	--with-float=soft \
	--enable-target-optspace \
	--disable-nls \
	--enable-languages=c \
        --with-gmp=$CEL/cross-tools \
        --with-mpfr=$CEL/cross-tools \
        --with-mpc=$CEL/cross-tools 
 
make -j4 all-gcc all-target-libgcc || exit 1
make install-gcc install-target-libgcc
cd ..
 
#=========================== uClibc (path 1) ===================================
if [ "$TARGET_LIBC" == "uClibc" ]; then
 
tar -xf uClibc-0.9.31.tar.bz2
cd uClibc-0.9.31
sed -e "s%#CEL#%$CEL%" -e "s%#TARGET#%$TARGET%" < ../uClibc-0.9.31.config > .config
make oldconfig || exit 1
make -j$JOBS CROSS=$TARGET- CC=$TARGET-gcc || exit 1
make PREFIX=$CEL install
cd ..
 
#=========================== eglibc first stage (path 2) =======================
elif [ "$TARGET_LIBC" == "eglibc" ]; then
 
tar -xf eglibc-2.13-current.tar.gz
 
ln -s ../ports eglibc-2.13-current/libc/ports
 
mkdir eglibc-build
cd eglibc-build
 
../eglibc-2.13-current/libc/configure \
	--host=$TARGET \
        --prefix=/usr \
        --with-headers=$CEL/usr/include \
        --disable-profile \
        --without-gd \
        --without-cvs \
        --enable-add-ons
 
make install-headers \
	install_root=$CEL \
	install-bootstrap-headers=yes
 
make -j$JOBS csu/subdir_lib || exit 1
 
mkdir -p $CEL/usr/lib/
cp csu/crt1.o csu/crti.o csu/crtn.o $CEL/usr/lib/
 
$TARGET-gcc \
        -nostdlib \
        -nostartfiles \
        -shared \
        -x c \
        -o $CEL/usr/lib/libc.so \
        /dev/null
 
cd ..
 
#=========================== gcc secound stage (path 2) ========================
mkdir gcc-interstep-build
cd gcc-interstep-build
../gcc-4.5.3/configure \
        --build=$MACHTYPE \
        --host=$MACHTYPE \
        --target=$TARGET \
        --prefix=$CEL/cross-tools \
        --with-local-prefix=$CEL/cross-tools \
        --with-sysroot=$CEL \
        --enable-languages=c \
        --disable-multilib \
        --with-float=soft \
        --with-pkgversion="Marcin Bis" \
        --enable-threads=no \
        --enable-target-optspace \
        --disable-nls \
        --enable-c99 \
        --enable-long-long \
        --with-gmp=$CEL/cross-tools \
        --with-mpfr=$CEL/cross-tools \
        --with-libelf=$CEL/cross-tools \
        --disable-libssp \
        --disable-libgomp \
        --disable-libmudflap \
	--with-system-zlib
 
eval $BUILD
make install
cd ..
 
#=========================== eglibc final step (path 2) ========================
mkdir eglibc-final-build
cd eglibc-final-build
 
../eglibc-2.13-current/libc/configure \
        --host=$TARGET \
        --prefix=/usr \
        --with-headers=$CEL/usr/include \
        --disable-profile \
        --without-gd \
        --without-cvs \
        --enable-add-ons
 
eval $BUILD
make install install_root=$CEL
 
cd ..
 
else
	echo "No known stdlib selected. Exitting."
	exit 1
fi
 
#=========================== libelf ============================================
tar -xf libelf-0.8.13.tar.gz
cd libelf-0.8.13
 
./configure \
        --prefix=$CEL/cross-tools \
	--disable-shared \
        --enable-static
eval $BUILD
make install
cd ..
#=========================== gcc final =========================================
mkdir gcc-final-build
cd gcc-final-build
../gcc-4.5.3/configure \
	--build=$MACHTYPE \
	--host=$MACHTYPE \
	--target=$TARGET \
	--prefix=$CEL/cross-tools \
	--with-sysroot=$CEL \
	--enable-languages=c,c++ \
	--disable-multilib \
	--with-float=soft \
	--with-pkgversion="Marcin Bis" \
	--enable-__cxa_atexit \
	--enable-threads=posix \
	--enable-target-optspace \
	--with-local-prefix=$CEL/cross-tools \
	--disable-nls \
	--enable-symvers=gnu \
	--enable-c99 \
	--enable-long-long \
        --with-gmp=$CEL/cross-tools \
        --with-mpfr=$CEL/cross-tools \
        --with-libelf=$CEL/cross-tools \
	--enable-lto \
	--with-system-zlib
eval $BUILD
make install
cd ..
 
#=========================== chrpath 32bit =====================================
tar -xf chrpath_0.13.orig.tar.gz
cd chrpath-0.13
CFLAGS=-m32 \
./configure \
	--prefix=$CEL/cross-tools \
	--program-prefix=$TARGET-
eval $BUILD
make install
ostatnio zmienione: 2011/09/29 21:08