|

楼主 |
发表于 2007-4-20 13:48:10
|
显示全部楼层
我的交叉编译环境是用别人做的build.sh 直接运行的
#!/bin/sh
#******************************************************************************
#
# build.sh - Shell script to build the arm-linux tool chain.
#
# Copyright (c) 2004 Cirrus Logic, Inc.
#
#******************************************************************************
#
# INSTDIR is the path where the tool chain will be installed.
#
INSTDIR=/usr/local/arm/3.3
#
# GNU is the location from which GNU source tarballs are fetched if they do not
# exist.
#
GNU=ftp://ftp.gnu.org
#
# KERNEL is the location from which the Linux source tarball is fetched if it
# does not exist.
#
KERNEL=ftp://ftp.kernel.org/pub/linux/kernel/v2.4
#
# ARMLINUX is the location from which the ARM Linux patch is fetched if it does
# not exist.
#
ARMLINUX=ftp://ftp.arm.linux.org.uk/pub/armlinux/source/kernel-patches/v2.4
#******************************************************************************
#
# Setup the execution environment for building the tool chain.
#
#******************************************************************************
#
# HEADERS is the path where the Linux kernel headers are found.
#
HEADERS=`pwd`/linux-2.4.21/include
#
# DESTDIR is the path where the tool chain will be placed as part of the build
# process. The tool chain must then be copied (manually) to ${INSTDIR} in
# order to run.
#
DESTDIR=`pwd`/install
#
# Add the installed tool chain to the search path. This is required so that
# the gcc and glibc builds can find the target assembler and linker.
#
PATH=${DESTDIR}${INSTDIR}/bin PATH
#
# Redirect stdout and stderr to a file, and make descriptor 3 be stdout. This
# will capture all output into the log file, and allow informational messages
# to be displayed during the build via "echo {blah} >&3".
#
exec 3>&1 1>build.log 2>&1
#******************************************************************************
#
# Bail out because of an error.
#
#******************************************************************************
failure ()
{
#
# Indicate that an error occurred.
#
echo Build step failed! >&3
#
# Exit with a failure return code.
#
exit 1
}
#******************************************************************************
#
# Execute a command with error checking. Note that when using this, if a piped
# command is used, the '|' must be escaped with '\' when calling try (i.e.
# "try ls \| less").
#
#******************************************************************************
try ()
{
#
# Execute the command and fail if it does not return zero.
#
eval ${*} || failure
}
#******************************************************************************
#
# Fetches a tarball with wget if it does not already exist in the local cache.
#
#******************************************************************************
fetch_tarball ()
{
#
# See if the tarball exists.
#
if [ ! -f ${2} ]
then
#
# Fetch the tarball since it does not exist.
#
echo Fetching ${2}... >&3
try wget ${1}/${2}
fi
}
#******************************************************************************
#
# Build binutils. This provides arm-linux-as, arm-linux-ar, arm-linux-ld, etc.
#
#******************************************************************************
#
# Get the binutils tarball.
#
fetch_tarball ${GNU}/gnu/binutils binutils-2.14.tar.bz2
#
# Unpack the binutils tarball.
#
echo Unpacking binutils... >&3
try tar -xjf binutils-2.14.tar.bz2
#
# Patch a few things in the binutils source.
#
try bzcat binutils-2.14.patch.bz2 2\>\&1 \| patch -p1 -E -d binutils-2.14
#
# Create a build directory and switch into it.
#
try mkdir binutils-2.14/build
try pushd binutils-2.14/build
#
# Configure binutils.
#
echo Configuring binutils... >&3
try CFLAGS=-O2 \
CXXFLAGS=-O2 \
../configure --target=arm-linux \
--prefix=${INSTDIR}
#
# Build binutils.
#
echo Building binutils... >&3
try make
#
# Install binutils.
#
echo Installing binutils... >&3
try make DESTDIR=${DESTDIR} install
#
# Remove the binutils source and objects.
#
try popd
try rm -rf binutils-2.14
#******************************************************************************
#
# Build gcc (stage 1). This provides just a basic C compiler that is used to
# build glibc.
#
#******************************************************************************
#
# Get the gcc tarball.
#
fetch_tarball ${GNU}/gnu/gcc/gcc-3.3 gcc-3.3.tar.bz2
#
# Unpack the gcc tarball.
#
echo Unpacking gcc... >&3
try tar -xjf gcc-3.3.tar.bz2
#
# Patch a few things in the gcc source.
#
try bzcat gcc-3.3.patch.bz2 2\>\&1 \| patch -p1 -E -d gcc-3.3
#
# Create a build directory and switch into it.
#
try mkdir gcc-3.3/build
try pushd gcc-3.3/build
#
# Configure gcc.
#
echo Configuring gcc \(stage 1\)... >&3
try CFLAGS=-O2 \
CXXFLAGS=-O2 \
DESTDIR=${DESTDIR} \
../configure --target=arm-linux \
--prefix=${INSTDIR} \
--with-headers=${HEADERS} \
--disable-shared \
--disable-threads \
--disable-debug \
--enable-languages="c"
#
# Build gcc.
#
echo Building gcc \(stage 1\)... >&3
try make DESTDIR=${DESTDIR} build_tooldir=${DESTDIR}${INSTDIR}/arm-linux
#
# Install gcc.
#
echo Installing gcc \(stage 1\)... >&3
try make DESTDIR=${DESTDIR} install
#
# Remove the gcc objects, leaving the source for use a bit later.
#
try popd
try rm -rf gcc-3.3/build
#******************************************************************************
#
# Configure the kernel as necessary. The kernel needs to be configured and the
# dependencies computed in order to properly build the tool chain, but the
# basic C compiler is needed to configure and compute the dependencies!
# The kernel is only configured if it has not been yet, and the dependencies
# are only computed if they have not been yet. A standard kernel configuration
# is used since the specific configuration to be used is not important to the
# tool chain.
#
#******************************************************************************
#
# Check for the Linux source directory.
#
if [ ! -d linux-2.4.21 ]
then
#
# Get the Linux tarball.
#
fetch_tarball ${KERNEL} linux-2.4.21.tar.bz2
#
# Get the ARM Linux patch.
#
fetch_tarball ${ARMLINUX} patch-2.4.21-rmk1.bz2
#
# Extract the Linux tarball.
#
echo Unpacking linux... >&3
try tar -xjf linux-2.4.21.tar.bz2
#
# Patch the linux source.
#
echo Patching linux... >&3
try bzcat patch-2.4.21-rmk1.bz2 2\>\&1 \| patch -p1 -E -d linux-2.4.21
#
# Fix the ARCH and CROSS_COMPILE lines in the linux Makefile.
#
try perl -i -p -e \'s/^ARCH.*/ARCH := arm/\' linux-2.4.21/Makefile
try perl -i -p -e \'s/^CROSS_COMPILE.*/CROSS_COMPILE = arm-linux-/\' \
linux-2.4.21/Makefile
fi
#
# See if the kernel needs to be configured.
#
if [ ! -f linux-2.4.21/.config ]
then
echo Configuring linux... >&3
try cp linux.config linux-2.4.21/.config
try make -C linux-2.4.21 oldconfig
fi
#
# See if the kernel dependencies need to be created.
#
if [ ! -f linux-2.4.21/.depend ]
then
echo Creating linux dependencies... >&3
try make -C linux-2.4.21 dep
fi
#******************************************************************************
#
# Build glibc. This provides the C and associated support libraries.
#
#******************************************************************************
#
# Get the glibc tarball.
#
fetch_tarball ${GNU}/gnu/glibc glibc-2.2.5.tar.gz
#
# Get the glibc-linuxthreads tarball.
#
fetch_tarball ${GNU}/gnu/glibc glibc-linuxthreads-2.2.5.tar.gz
#
# Unpack the glibc tarballs.
#
echo Unpacking glibc... >&3
try tar -xzf glibc-2.2.5.tar.gz
try tar -C glibc-2.2.5 -xzf glibc-linuxthreads-2.2.5.tar.gz
#
# Patch a few things in the glibc source.
#
try bzcat glibc-2.2.5.patch.bz2 2\>\&1 \| patch -p1 -E -d glibc-2.2.5
#
# Create a build directory and switch into it.
#
try mkdir glibc-2.2.5/build
try pushd glibc-2.2.5/build
#
# Configure glibc.
#
echo Configuring glibc... >&3
try CFLAGS=-O2 \
CXXFLAGS=-O2 \
../configure arm-linux \
--build=i686-pc-linux-gnu \
--with-headers=${HEADERS} \
--enable-add-ons \
--enable-shared \
--prefix=${INSTDIR}
#
# Build glibc.
#
echo Building glibc... >&3
try make
#
# Install glibc.
#
echo Installing glibc... >&3
try make install_root=${DESTDIR} install
#
# Fix the symlinks in the arm-linux/lib install directory.
#
try pushd ${DESTDIR}${INSTDIR}/arm-linux/lib
try ln -sf ../../lib/* .
try popd
#
# Remove the glibc source and objects.
#
try popd
try rm -rf glibc-2.2.5
#******************************************************************************
#
# Build gcc (stage 2). This provides a full C and C++ compiler.
#
#******************************************************************************
#
# Remove the system includes from the install directory. This will get
# re-populated when gcc is re-configured.
#
try rm -rf ${DESTDIR}${INSTDIR}/arm-linux/sys-include
#
# Patch a few things in the gcc source.
#
try perl -i -p -e \'s/-Dinhibit_libc//g\' gcc-3.3/gcc/config/arm/t-linux
#
# Create a build directory and switch into it.
#
try mkdir gcc-3.3/build
try pushd gcc-3.3/build
#
# Configure gcc.
#
echo Configuring gcc \(stage 2\)... >&3
try CFLAGS=-O2 \
CXXFLAGS=-O2 \
DESTDIR=${DESTDIR} \
../configure --target=arm-linux \
--prefix=${INSTDIR} \
--with-headers=${HEADERS} \
--disable-debug \
--enable-languages="c,c++"
#
# Temporarily modify the libc.so ld script so that the paths are "correct".
#
try cp ${DESTDIR}${INSTDIR}/lib/libc.so ${DESTDIR}${INSTDIR}/lib/libc.so.orig
try perl -i -p -e \"s,${INSTDIR},${DESTDIR}${INSTDIR},g\" \
${DESTDIR}${INSTDIR}/lib/libc.so
#
# Build gcc.
#
echo Building gcc \(stage 2\)... >&3
try make DESTDIR=${DESTDIR} build_tooldir=${DESTDIR}${INSTDIR}/arm-linux
#
# Install gcc.
#
echo Installing gcc \(stage 2\)... >&3
try make DESTDIR=${DESTDIR} install
#
# Restore the correct libc.so ld script.
#
try cp ${DESTDIR}${INSTDIR}/lib/libc.so.orig ${DESTDIR}${INSTDIR}/lib/libc.so
try rm -f ${DESTDIR}${INSTDIR}/lib/libc.so.orig
#
# Remove the gcc source and objects.
#
try popd
try rm -rf gcc-3.3
#******************************************************************************
#
# Build gdb. This provides a debugger that can connect to the gdbserver on the
# target system.
#
#******************************************************************************
#
# Get the gdb tarball.
#
fetch_tarball ${GNU}/gnu/gdb gdb-5.3.tar.gz
#
# Unpack the gdb tarball.
#
echo Unpacking gdb... >&3
try tar -xzf gdb-5.3.tar.gz
#
# Patch a few things in the gdb source.
#
try bzcat gdb-5.3.patch.bz2 2\>\&1 \| patch -p1 -E -d gdb-5.3
#
# Create a build directory and switch into it.
#
try mkdir gdb-5.3/build
try pushd gdb-5.3/build
#
# Configure gdb.
#
echo Configuring gdb... >&3
try CFLAGS=-O2 \
CXXFLAGS=-O2 \
../configure --target=arm-linux \
--prefix=${INSTDIR} \
--disable-sim
#
# Build gdb.
#
echo Building gdb... >&3
try make
#
# Install gdb.
#
echo Installing gdb... >&3
try make DESTDIR=${DESTDIR} install
#
# Remove the gdb source and objects.
#
try popd
try rm -rf gdb-5.3
#******************************************************************************
#
# Strip the executables in the install directory.
#
#******************************************************************************
for i in addr2line ar as c++ c++filt cpp g++ gcc gcov gdb ld \
nm objcopy objdump ranlib readelf size strings strip
do
try strip ${DESTDIR}${INSTDIR}/bin/arm-linux-${i}
done
for i in gencat getconf getent iconv locale \
localedef pcprofiledump rpcgen sprof
do
try arm-linux-strip ${DESTDIR}${INSTDIR}/bin/${i}
done
for i in iconvconfig ldconfig nscd nscd_nischeck rpcinfo sln zic zdump
do
try arm-linux-strip ${DESTDIR}${INSTDIR}/sbin/${i}
done
try arm-linux-strip ${DESTDIR}${INSTDIR}/libexec/pt_chown
try strip ${DESTDIR}${INSTDIR}/arm-linux/bin/*
for i in cc1 cc1plus collect2
do
try strip ${DESTDIR}${INSTDIR}/lib/gcc-lib/arm-linux/3.3/${i}
done
#******************************************************************************
#
# Success.
#
#******************************************************************************
exit 0 |
|