[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Patches] Update on the Cross-building instructions



Greetings,

Just joined today (apologies if I don't follow the proper etiquette).
There was a requirement at work to build a compiler that runs on an embedded linux ppc chipset. So, after hitting the webs for a few hours, the only tutorial on building a cross compiler that was remotely comprehensible was this one: http://www.eglibc.org/archives/patches/msg00078.html (thanks so much jimb!)

All the automated tools I could find (crosstool and crosstool-ng) were for sources that were woefully out of date. Additionally, I needed to build a "canadian cross" (hehe look it up), no easy task!

So up rolled my selves as I adopted jimb's directions. Here is the final result that seems to work for me (minimal testing so far...). Please let me know if there is any obvious configuration issues that stands out.

The current sources I used are:
binutils-2.23
gcc-4.7.2
linux-3.4.35 (headers)
gperf-3.0.4 (not sure I really need that, but the compiler barfed without it)
and finally:
eglibc-2.14/libc (from svn)

My build computer is:
Linux Mint 14 x86_64
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2

And my directory structure looks like:
~/Build/cross/src
|- binutils-2.23
|- gcc-4.7.2
|- gperf-3.0.4
|- libc -> libc-all/libc
|- libc-all
|- linux-3.4.35 -> /home/aklofas/Build/linux

If I get the green light from you guys/girls, I'll type up a nice article (or copy/paste most of jimb's article :) for the future cross-compilers (good luck futures!)


Thanks,
Andrew Klofas


===============================================
# Source http://www.eglibc.org/archives/patches/msg00078.html

# Configuration
root=$HOME/Build/cross

build=x86_64-unknown-linux-gnu
target=powerpc-turf-linux-gnu
linux_arch=powerpc
languages=c,c++,fortran

binutilsv=binutils-2.23
gccv=gcc-4.7.2
gperfv=gperf-3.0.4
linuxv=linux-3.4.35


# Define some useful vars
top=$root/work
src="">

obj=$top/obj
tools=$top/tools
sysroot=$top/sysroot

# Compile binutils
mkdir -p $obj/binutils1
cd $obj/binutils1
$src/$binutilsv/configure --target=$target --prefix=$tools --with-sysroot=$sysroot
make
make install


# Compile gcc-minimal
mkdir -p $obj/gcc1
cd $obj/gcc1
#$src/$gccv/contrib/download_prerequisites
#$src/$gccv/configure --target=$target --prefix=$tools --with-sysroot=$sysroot --without-headers --with-newlib --disable-shared --disable-threads --disable-libssp --disable-libgomp --disable-libmudflap --disable-decimal-float --disable-libffi --disable-libquadmath --disable-libgcc --disable-zlib --disable-libiberty --enable-languages=c
#$src/$gccv/configure --target=$target --prefix=$tools --with-sysroot=$sysroot --without-headers --with-newlib --disable-shared --disable-threads --enable-languages=c
$src/$gccv/configure --target=$target --prefix=$tools --with-sysroot=$sysroot --without-headers --with-newlib --disable-shared --disable-threads --disable-libgcc --disable-libssp --disable-libmudflap --disable-libgomp --disable-libquadmath --enable-languages=c
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install


# Copy kernel headers
ln -s $src/$linuxv $obj/linux
cd $obj/linux
PATH=$tools/bin:$PATH make headers_install ARCH=$linux_arch CROSS_COMPILE=$target- INSTALL_HDR_PATH=$sysroot/usr


# Build eglibc-minimal for cross gcc-minimal
mkdir -p $obj/eglibc-headers
cd $obj/eglibc-headers
BUILD_CC=gcc CC=$tools/bin/$target-gcc CXX=$tools/bin/$target-g++ AR=$tools/bin/$target-ar RANLIB=$tools/bin/$target-ranlib $src/libc/configure --prefix=/usr --with-headers=$sysroot/usr/include --build=$build --host=$target --disable-profile --without-gd --without-cvs --enable-add-ons
make install-headers install_root=$sysroot install-bootstrap-headers=yes


# Build shared object eglibc files
mkdir -p $sysroot/usr/lib
make csu/subdir_lib
cp csu/crt1.o csu/crti.o csu/crtn.o $sysroot/usr/lib
$tools/bin/$target-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $sysroot/usr/lib/libc.so


# Compile second stage gcc with eglibc-minimal 
mkdir -p $obj/gcc2
cd $obj/gcc2
#$src/$gccv/configure --target=$target --prefix=$tools --with-sysroot=$sysroot --disable-libssp --disable-libgomp --disable-libmudflap --disable-libquadmath --enable-languages=c
$src/$gccv/configure --target=$target --prefix=$tools --with-sysroot=$sysroot --disable-libssp --disable-libmudflap --disable-libgomp --disable-libquadmath --enable-languages=c
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install


# Compile gperf
mkdir -p $obj/gperf
cd $obj/gperf
$src/$gperfv/configure --prefix=$tools
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install


# Compile full eglibc
mkdir -p $obj/eglibc
cd $obj/eglibc
BUILD_CC=gcc CC=$tools/bin/$target-gcc CXX=$tools/bin/$target-g++ AR=$tools/bin/$target-ar RANLIB=$tools/bin/$target-ranlib $src/libc/configure --build=$build --host=$target --prefix=/usr --with-headers=$sysroot/usr/include --without-gd --without-cvs --enable-add-ons
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install install_root=$sysroot


# Compile full gcc
mkdir -p $obj/gcc3
cd $obj/gcc3
$src/$gccv/contrib/download_prerequisites
#$src/$gccv/configure --target=$target --prefix=$tools --with-sysroot=$sysroot --disable-libssp --disable-libgomp --disable-libmudflap --disable-libquadmath --enable-languages=c,c++
$src/$gccv/configure --target=$target --prefix=$tools --with-sysroot=$sysroot --enable-languages=$languages
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install


# Build sysroot tree
cp -d $tools/$target/lib/libgcc_s.so* $sysroot/lib
cp -d $tools/$target/lib/libstdc++.so* $sysroot/usr/lib


# Test the cross compiler
cd $obj
cat > c++-hello.cc <<EOF
#include <iostream>
int
main (int argc, char **argv)
{
  std::cout << "Hello, C++ world!" << std::endl;
  return 0;
}
EOF
$tools/bin/$target-g++ -Wall c++-hello.cc -o c++-hello
$tools/bin/$target-readelf -hl c++-hello >hello-cross-elf.txt
$tools/bin/$target-readelf -d $sysroot/lib/libgcc_s.so.1 >libgcc-cross-elf.txt


# Compile canadian binutils
mkdir -p $obj/binutils2
cd $obj/binutils2
$src/$binutilsv/configure --target=$target --host=$target --prefix=$sysroot/usr --with-sysroot=$sysroot 
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install


# Compile canadian gcc
mkdir -p $obj/gcc4
cd $obj/gcc4
$src/$gccv/contrib/download_prerequisites
cd $obj/gcc4/gmp
./configure --host=$target --prefix=$tools/usr
make
make install
cd $obj/gcc4/mpfr
./configure --host=$target --with-gmp=$tools/usr --prefix=$tools/usr
make
make install
cd $obj/gcc4/mpc
./configure --host=$target --with-gmp=$tools/usr --with-mpfr=$tools/usr --prefix=$tools/usr
make
make install
cd $obj/gcc4
CC=$tools/bin/$target-gcc CXX=$tools/bin/$target-g++ AR=$tools/bin/$target-ar RANLIB=$tools/bin/$target-ranlib $src/$gccv/configure --build=$build --target=$target --host=$target --prefix=$sysroot/usr --with-sysroot=$sysroot --enable-languages=$languages --with-gmp=$tools/usr --with-mpfr=$tools/usr --with-mpc=$tools/usr
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install


_______________________________________________
Patches mailing list
Patches@xxxxxxxxxx
http://eglibc.org/cgi-bin/mailman/listinfo/patches