############################################################
#!/bin/bash -e
## set vars
export TOOLDIR=/work/tools/stesen/tools
export SRCDIR=/work/build/armsrc
cd $SRCDIR
export MAKE_FLAG="-j3"
export BUILD_TARGET="arm-stesen-linux-gnueabi"
export TARGET_CFLAGS="-mabi=aapcs-linux -mfloat-abi=soft -mcpu=arm920t -mtune=arm920t -O3"
export LC_ALL=POSIX
unset AR AS BUILD64 CC CFLAGS CLFS CLFS_HOST CLFS_TARGET CXX CXXFLAGS LD RANLIB STRIP
export CFLAGS="-march=i486 -mtune=i486 -O3 -Wl,-rpath,${TOOLDIR}/lib"
export CXXFLAGS="-march=i486 -mtune=i486 -O3 -Wl,-rpath,${TOOLDIR}/lib"
export TARGET_SYSROOT="${TOOLDIR}/target-sysroot"
export BUILD_HOST="$(echo ${MACHTYPE} | sed "s/$(echo ${MACHTYPE} | cut -d- -f2)/cross/")"
echo $BUILD_HOST
export PATH=${TOOLDIR}/bin:/bin:/usr/bin
export MABI=aapcs-linux
export LD_LIBRARY_PATH=${CROSSTOOLS_DIR}/lib:$LD_LIBRARY_PATH
## get tarballs && patchs
wget -c
wget -c
wget -c
wget -c
wget -c
wget -c
wget -c ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-ppl-0.15.7.tar.gz
wget -c
wget -c
wget -c
wget -c
## gmp
tar xf gmp-4.3.1.tar.bz2
cd gmp-4.3.1/
ac_cv_host=i486-pc-linux-gnu \
CPPFLAGS="$CXXFLAGS -fexceptions" \
./configure --prefix=${TOOLDIR} --enable-cxx
make $MAKE_FLAG
make install
cd ..
rm -fr gmp-4.3.1
echo "gmp" > done
## mpfr
tar xf mpfr-2.4.2.tar.bz2
cd mpfr-2.4.2/
ac_cv_host=i486-pc-linux-gnu \
LDFLAGS="-Wl,-rpath,${TOOLDIR}/lib" \
./configure \
--prefix=${TOOLDIR} \
--enable-shared \
--with-gmp=${TOOLDIR}
make $MAKE_FLAG
make install
cd ..
rm -fr mpfr-2.4.2
echo "mpfr" >> done
## mpc
tar xf mpc-0.8.1.tar.gz
cd mpc-0.8.1/
ac_cv_host=i486-pc-linux-gnu \
LDFLAGS="-Wl,-rpath,${TOOLDIR}/lib" \
./configure \
--prefix=${TOOLDIR} \
--enable-shared \
--with-mpfr=/tools \
--with-gmp=/tools
make
make install
cd ..
rm -fr mpc-0.8.1
echo "mpc" >> done
## ppl
tar xf ppl-0.10.2.tar.bz2
cd ppl-0.10.2/
LDFLAGS="-Wl,-rpath,${TOOLDIR}/lib" \
./configure \
--prefix=${TOOLDIR} \
--enable-shared \
--enable-interfaces="c,cxx" \
--disable-optimization \
--with-libgmp-prefix=${TOOLDIR} \
--with-libgmpxx-prefix=${TOOLDIR}
make $MAKE_FLAG
make install
cd ..
rm -fr ppl-0.10.2
echo "ppl" >> done
## cloog-ppl
tar xf cloog-ppl-0.15.7.tar.gz
cd cloog-ppl-0.15.7/
cp -v configure{,.orig}
sed "/LD_LIBRARY_PATH=/d" configure.orig > configure
LDFLAGS="-Wl,-rpath,${TOOLDIR}/lib" \
./configure \
--prefix=${TOOLDIR} \
--enable-shared \
--with-bits=gmp \
--with-gmp=${TOOLDIR} \
--with-ppl=${TOOLDIR}
make $MAKE_FLAG
make install
cd ..
rm -fr cloog-ppl-0.15.7
echo "cloog-ppl" >> done
## linux headers
tar xf linux-2.6.33.3.tar.bz2
cd linux-2.6.33.3/
install -dv $TARGET_SYSROOT/usr/include
make mrproper
make ARCH=arm headers_check
make ARCH=arm INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* ${TARGET_SYSROOT}/usr/include &&
find ${TARGET_SYSROOT}/usr/include -name .install -or -name ..install.cmd | xargs rm -fv
cd ..
rm -rf linux-2.6.32.3
echo "headers" >> done
## binutils
tar xf binutils-2.20.1.tar.bz2
cd binutils-2.20.1/
mkdir -v ../binutils-build &&
cd ../binutils-build
AR=ar AS=as \
../binutils-2.20.1/configure \
--prefix=${TOOLDIR} \
--host=$BUILD_HOST \
--target=$BUILD_TARGET \
--with-sysroot=$TARGET_SYSROOT \
--disable-nls \
--enable-shared \
--disable-multilib \
--disable-werror
make configure-host &&
make $MAKE_FLAG
make install
cp -v ../binutils-2.20.1/include/libiberty.h $TARGET_SYSROOT/usr/include
cd ..
rm -fr binutils-build binutils-2.20.1
echo "binutils" >> done
## gcc static
tar xf gcc-4.5.0.tar.bz2
cd gcc-4.5.0/
mkdir -v ../gcc-build && cd ../gcc-build
AR=ar LDFLAGS="-Wl,-rpath,${TOOLDIR}/lib" \
../gcc-4.5.0/configure \
--prefix=${TOOLDIR} \
--build=$BUILD_HOST \
--host=$BUILD_HOST \
--target=$BUILD_TARGET \
--with-sysroot=$TARGET_SYSROOT \
--disable-nls \
--disable-shared \
--with-mpfr=${TOOLDIR} \
--with-gmp=${TOOLDIR} \
--with-ppl=${TOOLDIR} \
--with-cloog=${TOOLDIR} \
--with-mpc=${TOOLDIR} \
--without-headers \
--with-newlib \
--disable-decimal-float \
--disable-libgomp \
--disable-libmudflap \
--disable-libssp \
--disable-threads \
--enable-languages=c \
--with-abi=$MABI \
--disable-multilib
make $MAKE_FLAG \
AS_FOR_TARGET=${BUILD_TARGET}-as \
LD_FOR_TARGET="${BUILD_TARGET}-ld" \
CFLAGS_FOR_TARGET="${TARGET_CFLAGS}" \
CXXFLAGS_FOR_TARGET="${TARGET_CFLAGS}" \
LIBCFLAGS_FOR_TARGET="${TARGET_CFLAGS}" \
LIBCXXFLAGS_FOR_TARGET="${TARGET_CFLAGS}" \
all-gcc all-target-libgcc
make install-gcc install-target-libgcc
cd ..
rm -fr gcc-build gcc-4.5.0
echo "gcc pass 1" >> done
## eglibc
tar xf eglibc-2.10.1-20090825-r8873.tar.bz2
cd eglibc-2.10.1/
patch -Np1 -i ../eglibc-2.10.1-20090825-r8873-fixes-1.patch
tar xf ../eglibc-ports-2.10.1-20090726-r8632.tar.bz2
cp -v Makeconfig{,.orig}
sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig
mkdir ../eglibc-build && cd ../eglibc-build
echo libc_cv_forced_unwind=yes > config.cache
echo libc_cv_c_cleanup=yes >> config.cache
echo libc_cv_gnu89_inline=yes >> config.cache
echo ac_cv_path_GREP=/bin/grep >> config.cache
echo "slibdir=/lib" >> configparms
echo "install_root=$TARGET_SYSROOT" >> configparms
CFLAGS_ORG=$CFLAGS
CXXFLAGS_ORG=$CXXFLAGS
CFLAGS="$TARGET_CFLAGS"
CXXFLAGS="$TARGET_CFLAGS"
BUILD_CC="gcc" \
CC="${BUILD_TARGET}-gcc ${TARGET_CFLAGS}" \
AR="${BUILD_TARGET}-ar" \
RANLIB="${BUILD_TARGET}-ranlib" \
../eglibc-2.10.1/configure \
--host=${BUILD_TARGET} \
--build=${BUILD_HOST} \
--prefix=/usr \
--disable-profile \
config--enable-add-ons \
--with-tls \
--enable-kernel=2.6.0 \
--libexecdir=/usr/lib/eglibc \
--libdir=/usr/lib \
--with-__thread \
--with-binutils=${TOOLDIR}/bin \
--with-headers=${TARGET_SYSROOT}/usr/include \
--cache-file=config.cache
make
make install
export CFLAGS=$CFLAGS_ORG
export CXXFLAGS=CXXFLAGS_ORG
cd ..
rm -fr eglibc-build eglibc-2.10.1
echo "eglibc" >> done
## gcc filnal
tar xf gcc-4.5.0.tar.bz2
cd gcc-4.5.0/
mkdir -v ../gcc-build && cd ../gcc-build
AR=ar LDFLAGS="-Wl,-rpath,${TOOLDIR}/lib" \
../gcc-4.5.0/configure --prefix=${TOOLDIR} \
--build=${BUILD_HOST} --target=${BUILD_TARGET} \
--host=${BUILD_HOST} --with-sysroot=${TARGET_SYSROOT} \
--disable-nls --enable-shared --enable-languages=c,c++ \
--enable-__cxa_atexit --with-mpfr=${TOOLDIR} \
--with-gmp=${TOOLDIR} --with-mpc=${BUILD_HOST} \
--enable-c99 --with-ppl=${TOOLDIR} \
--with-cloog=${TOOLDIR} --enable-long-long \
--enable-threads=posix --with-abi=$MABI --disable-multilib \
--with-float=soft --with-arch=armv4t --with-tune=arm920t
make $MAKE_FLAG \
AS_FOR_TARGET=${BUILD_TARGET}-as \
LD_FOR_TARGET="${BUILD_TARGET}-ld" \
CFLAGS_FOR_TARGET="${TARGET_CFLAGS}" \
CXXFLAGS_FOR_TARGET="${TARGET_CFLAGS}" \
LIBCFLAGS_FOR_TARGET="${TARGET_CFLAGS}" \
LIBCXXFLAGS_FOR_TARGET="${TARGET_CFLAGS}"
make install
cd ..
rm -fr gcc-build gcc-4.5
echo "gcc pass 2" >> done
## strip && clean
strip --strip-debug $TOOLDIR/lib/*
strip --strip-unneeded $TOOLDIR/bin/*
rm -rf $TOOLDIR/{,share}/{info,man}
#######################################
现在如果顺利的话
cat > hello.c << EOF
#include
int main(void)
{
printf("hello sb\n");
return 0;
}
EOF
${BUILD_TARGET}-gcc -static hello.c -o hello
file hello
sudo qemu-arm hello
就能看到文件属性和运行结果了.