经过一个周末的折腾,在""上面script的帮助下,终于制作出了自己的tool chain :)
有了与kernel匹配的glibc库,之前open的问题就消失了。
下面是我的编译脚本:
点击(此处)折叠或打开
-
#!/bin/bash
-
-
# author: fireaxe.hq
-
# description: The script for building crosstool automatically
-
# usage: chmod +x crosstool-4.8.2.sh && ./crosstool-4.8.2.sh
-
# linux-3.12.17
-
# binutils-2.24 glibc-2.18 glibc-ports-2.16.0 gcc-4.8.2
-
-
function set_sys
-
{
-
apt-get update && apt-get install build-essential libncurses5-dev gawk libmpfr-dev -y
-
}
-
-
function set_env
-
{
-
export USRROOT=/home/hao1404/Desktop
-
export KRNROOT=${USRROOT}/kernel/linux-3.12.17
-
export SRCROOT=${USRROOT}/toolchain
-
-
export TARGET=arm-qhao-linux-gnueabi
-
-
export PREFIX=/opt/mytoolchain
-
export BUILD=${SRCROOT}/build-tools
-
export TARGET_PREFIX=${PREFIX}/${TARGET}
-
export PATH=${PREFIX}/bin:${PATH}
-
}
-
-
function create_dir
-
{
-
mkdir -p ${BUILD}/build-binutils ${BUILD}/build-boot-gcc ${BUILD}/build-gcc ${BUILD}/build-glibc ${BUILD}/build-glibc-headers
-
mkdir -p ${TARGET_PREFIX}
-
}
-
-
function install_gmp_mpc_mpfr
-
{
-
cd ${SRCROOT}
-
-
cd gmp-6.0.0
-
./configure --prefix=/usr/local/gmp-6.0.0
-
make
-
make install
-
make distclean
-
-
cd ../mpc-1.0.2
-
./configure --prefix=/usr/local/mpc-1.0.2
-
make
-
make install
-
make distclean
-
-
cd ../mpfr-3.1.2
-
./configure --prefix=/usr/local/mpfr-3.1.2
-
make
-
make install
-
make distclean
-
}
-
-
function install_cross_binutils
-
{
-
cd ${BUILD}
-
cd build-binutils
-
../../binutils-2.24/configure --target=${TARGET} --prefix=${PREFIX} --with-sysroot=${TARGET_PREFIX}
-
make
-
make install
-
}
-
-
function install_cross_gcc
-
{
-
cd ${BUILD}
-
rm -rf ../gcc-4.8.2/gmp
-
rm -rf ../gcc-4.8.2/mpc
-
rm -rf ../gcc-4.8.2/mpfr
-
cp -r ../gmp-6.0.0 ../gcc-4.8.2/gmp
-
cp -r ../mpc-1.0.2 ../gcc-4.8.2/mpc
-
cp -r ../mpfr-3.1.2 ../gcc-4.8.2/mpfr
-
cd build-boot-gcc
-
../../gcc-4.8.2/configure --target=${TARGET} --prefix=${PREFIX} --with-sysroot=${TARGET_PREFIX} --with-arch=armv7-a --disable-shared --disable-threads --disable-multilib --without-headers --with-newlib --enable-languages=c,c++ -with-gmp=/usr/local/gmp-6.0.0 -with-mpfr=/usr/local/mpfr-3.1.2 -with-mpc=/usr/local/mpc-1.0.2
-
make all-gcc
-
make install-gcc
-
make all-target-libgcc
-
make install-target-libgcc
-
}
-
-
function install_linux_headers
-
{
-
cd ${KRNROOT}
-
make headers_install
-
cp -r ../obj/linux/tmparm/usr/include ${TARGET_PREFIX}
-
}
-
-
function install_glibc_headers
-
{
-
cd ${BUILD}
-
cp -r ../glibc-ports-2.16.0 ../glibc-2.18/ports
-
cd build-glibc-headers
-
echo "libc_cv_forced_unwind=yes" > config.cache
-
echo "libc_cv_c_cleanup=yes" >> config.cache
-
echo "libc_cv_arm_tls=yes" >> config.cache
-
../../glibc-2.18/configure --host=${TARGET} --prefix="/usr" --with-sysroot=${TARGET_PREFIX} --enable-add-ons --with-headers=${TARGET_PREFIX}/include --cache-file=config.cache
-
make cross-compiling=yes install_root=${TARGET_PREFIX} prefix="" install-headers
-
}
-
-
function install_glibc
-
{
-
cd ${BUILD}/build-glibc
-
echo "libc_cv_forced_unwind=yes" > config.cache
-
echo "libc_cv_c_cleanup=yes" >> config.cache
-
CC=${TARGET}-gcc ../../glibc-2.18/configure --host=${TARGET} --prefix="/usr" --with-sysroot=${TARGET_PREFIX} --enable-add-ons --with-headers=${TARGET_PREFIX}/include --cache-file=config.cache
-
ln -s ${PREFIX}/lib/gcc/arm-qhao-linux-gnueabi/4.8.2/libgcc.a ${PREFIX}/lib/gcc/arm-qhao-linux-gnueabi/4.8.2/libgcc_s.a
-
ln -s ${PREFIX}/lib/gcc/arm-qhao-linux-gnueabi/4.8.2/libgcc.a ${PREFIX}/lib/gcc/arm-qhao-linux-gnueabi/4.8.2/libgcc_eh.a
-
make
-
make install_root=${TARGET_PREFIX} prefix="" install
-
}
-
-
function install_gcc
-
{
-
cd ${BUILD}/build-gcc
-
mkdir ${TARGET_PREFIX}/usr
-
ln -s ${TARGET_PREFIX}/include ${TARGET_PREFIX}/usr/include
-
../../gcc-4.8.2/configure --target=${TARGET} --prefix=${PREFIX} --with-sysroot=${TARGET_PREFIX} --with-arch=armv7-a --enable-shared --enable-__cxa_atexit --disable-nls --enable-c99 --enable-long-long --enable-threads=posix --enable-languages=c,c++ -with-gmp=/usr/local/gmp-6.0.0 -with-mpfr=/usr/local/mpfr-3.1.2 -with-mpc=/usr/local/mpc-1.0.2
-
sed -i 's/\/lib\///g' ${TARGET_PREFIX}/lib/libc.so
-
sed -i 's/\/lib\///g' ${TARGET_PREFIX}/lib/libpthread.so
-
make all
-
make install
-
}
-
-
function clean_tempfiles
-
{
-
cd ${SRCROOT}
-
rm -rf build-tools
-
rm -rf gcc-4.8.2/gmp
-
rm -rf gcc-4.8.2/mpc
-
rm -rf gcc-4.8.2/mpfr
-
}
-
-
echo =============== set_sys
-
# set_sys
-
echo =============== set_env
-
set_env
-
echo =============== start create_dir
-
# create_dir
-
echo =============== start install_gmp_mpc_mpfr
-
# install_gmp_mpc_mpfr
-
echo =============== start install_cross_binutils
-
# install_cross_binutils
-
echo =============== install_cross_gcc
-
# install_cross_gcc
-
echo =============== start install_glibc
-
# install_linux_headers
-
echo =============== start install_glibc_headers
-
# install_glibc_headers
-
echo =============== start install_gcc
-
# install_glibc
-
echo =============== start install_linux_headers
-
install_gcc
-
echo =============== start test
-
# clean temp files
-
echo =============== start cleaning
- clean_tempfiles
特别感谢:
其他参考链接: