building a crosscompiler drives me mad

Niklaus niklaus@gmail.com
Sun Apr 16 06:43:00 GMT 2006


On 4/15/06, sp4rc <sammyshome@gmx.net> wrote:
> Dear list-members and gcc-gurus,
>
> I am trying to build a crosscompiler on a NetBSD 3.0 (i386) system for a
> Gentoo Linux (i386) system. These are the steps I have performed.
>
> [+] The versions I am using:
> binutils-2.15
> gcc-3.4.5
> glibc-2.3.5
> linux-2.6.8

Binutils should build without a problem.
1) Binutils
2) Copy linux headers  after you do make config. This is important
because certain files are generated i think. Also you have to copy
asm-i386, asm-generic , linux inside include .
I assume that you know the proper directory . It is $prefix/$target/include/

then you have to do make install-headers for glibc. that is copying
the proper headers from glibc.

then build the  gcc stage1.
then build glibc with gcc-stage1.
Then build gcc-stage2.

I find you not copying asm-generic. Also you want to look at
crosstool.sh of Dan kegel's crosstool. It is all automated in it.

I suggest you download crosstool and build you required thing. if not
the below script can give you some idea. I haven't done the error
checks properly.  You should run it with sh script.sh mips.

Also the .config file is the one generated by doing a make ARCH=mips
menuconfig. So you will have to do it for your kernel and copy the
.config. The second file Makeconfig has -lgcc_eh commented . If you
get to that stage of glibc you have to comment -lgcc_egh in Makeconfig
of glibc.

Happy cross compiling.


#!/bin/sh
echo $1
if [ "$1" = "" ]
then
	echo "run the file as sh script.sh mips when target is mips"
	exit
fi

targ=$1
PRE=`pwd`
echo $PRE
mkdir cross build
FPRE=$PRE/cross/
HEAD=$PRE/cross/${targ}-deb-linux/include
mkdir -p $HEAD

mkdir -p $PRE/downloads
cd downloads
wget -c ftp://ftp.gnu.org/pub/gnu/glibc/glibc-2.3.4.tar.bz2
wget -c ftp://ftp.gnu.org/pub/gnu/glibc/glibc-linuxthreads-2.3.4.tar.bz2
tar xvjf glibc-2.3.4.tar.bz2
tar xvjf glibc-linuxthreads-2.3.4.tar.bz2 -C glibc-2.3.4
mv glibc-2.3.4 glibc
wget -c ftp://ftp.gnu.org/pub/gnu/binutils/binutils-2.16.tar.bz2
wget -c ftp://ftp.gnu.org/pub/gnu/gcc/gcc-3.4.6/gcc-3.4.6.tar.bz2
tar xvjf binutils-2.16.tar.bz2
mv binutils-2.16 binu
tar xvjf gcc-3.4.6.tar.bz2
mv gcc-3.4.6 gcc
wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.1.tar.bz2
tar xvjf linux-2.6.16.1.tar.bz2
mv linux-2.6.16.1 linux

cd linux
cp $PRE/.config .
make ARCH=$1 oldconfig
make ARCH=$1 include/asm include/linux/version.h


cp -r include/asm-generic $HEAD/asm-generic
cp -r include/linux $HEAD
cp -r include/asm-${targ} $HEAD/asm


FRES=$PRE/downloads
FTARG=${targ}-deb-linux
SYSR=$FPRE/$FTARG/
cd $PRE
cp $PRE/Makeconfig  $FRES/glibc
cd build
mkdir binbuild gcc-core glibc-headers gcc-comp glibc-comp

cd binbuild
$FRES/binu/configure --target=$FTARG --prefix=$FPRE --disable-nls
--with-sysroot=$SYSR

make all
if [ $? -ne 0 ]
then
	echo "Something went wrong in Make all of binutils. Please check"
	echo "exiting .... "
	exit
fi

make install
if [ $? -ne 0 ]
then
	echo "Something went wrong in make install of binutils. Please check"
	echo "exiting .... "
	exit
fi

cd ..

echo "now building gcc-core boot strap compiler"
OLDPATH=$PATH
export PATH=$FPRE/bin:$PATH
cd gcc-core
$FRES/gcc/configure --target=$FTARG --prefix=$FPRE
--with-local-prefix=$SYSR --disable-multilib \
--with-newlib --disable-nls --without-headers --disable-nls
--enable-threads=no --enable-symvers=gnu \
--enable-__cxa_atexit --enable-languages=c --disable-shared

make all-gcc
if [ $? -ne 0 ]
then
	echo "Something went wrong in Make all of core-gcc. Please check"
	echo "exiting .... "
	exit
fi

make install-gcc
if [ $? -ne 0 ]
then
	echo "Something went wrong in Make install of core-gcc. Please check"
	echo "exiting .... "
	exit
fi

cd ..

cd glibc-headers
libc_cv_ppc_machine=yes \
CC="${targ}-deb-linux-gcc " \
$FRES/glibc/configure --prefix=/usr \
--host=$FTARG --without-cvs --disable-sanity-checks --with-headers=$HEAD \
--enable-hacker-mode

if [ $? -ne 0 ]
then
	echo "Something went wrong in configure of binutils-headers. Please check"
	echo "exiting .... "
	exit
fi


libc_cv_ppc_machine=yes \
make CFLAGS=-DBOOTSTRAP_GCC sysdeps/gnu/errlist.c
mkdir -p stdio-common
touch stdio-common/errlist-compat.c
if [ $? -ne 0 ]
then
	echo "Something went wrong in make errlist of glibc-headers. Please check"
	echo "exiting .... "
	exit
fi

libc_cv_ppc_machine=yes \
make cross-compiling=yes install_root=$SYSR CFLAGS=-DBOOTSTRAP_GCC
install-headers
if [ $? -ne 0 ]
then
	echo "Something went wrong in make install-headers of glibc-headers.
Please check"
	echo "exiting .... "
	exit
fi

mkdir -p $HEAD/gnu
touch $HEAD/gnu/stubs.h
cp $FRES/glibc/include/features.h $HEAD/features.h
mkdir -p $HEAD/bits
cp bits/stdio_lim.h $HEAD/bits/stdio_lim.h

cd ..

echo " now building glibc complete"

cd glibc-comp

BUILD_CC=gcc CC="${FTARG}-gcc " AR=${FTARG}-ar \
RANLIB=${FTARG}-ranlib \
$FRES/glibc/configure  --prefix=/usr \
--host=$FTARG --with-sysroot=$SYSR --without-cvs \
--disable-profile --disable-debug --without-gd --enable-shared \
--enable-add-ons=linuxthreads, --with-headers=$HEAD

make LD=${FTARG}-ld RANLIB=${FTARG}-ranlib all
if [ $? -ne 0 ]
then
	echo "Something went wrong in make  of glibc-make . Please check"
	echo "exiting .... "
	exit
fi
make install_root=$SYSR install
if [ $? -ne 0 ]
then
	echo "Something went wrong in make install of glibc-comp. Please check"
	echo "exiting .... "
	exit
fi

cd ..
cd gcc-comp
$FRES/gcc/configure --target=${FTARG} --prefix=${FPRE}/
--with-sysroot=$SYSR/ --enable-local-prefix=$SYSR/ \
--disable-nls --enable-threads=posix --enable-symvers=gnu
--enable-__cxa_atexit \
--enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long

make all
if [ $? -ne 0 ]
then
	echo "Something went wrong in make  of gcc-comp-make . Please check"
	echo "exiting .... "
	exit
fi
make install
if [ $? -ne 0 ]
then
	echo "Something went wrong in make  of gcc-comp-install . Please check"
	echo "exiting .... "
	exit
fi
cd ..

echo "Your build environment is in cross . Successfully installed.
What a thing."



More information about the Gcc-help mailing list