Difference between revisions of "Cross Compiling"

From CSCWiki
Jump to navigation Jump to search
 
(32 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
= Builder =
 
= Builder =
  
Builder is a vserver that contains various cross-compilers. The current list of installed cross-compilers includes alpha, arm, hppa (binutils only), i486, ia64, m68k, mips, mipsel, powerpc, sparc and x86_64.
+
Builder is a vserver that is used to build cross-compilers and cross-packages that run on x86_64 machines. The current list of installed cross-compilers includes alpha, arm, hppa (binutils only), i486, ia64, m68k, mips, mipsel, powerpc, sparc and x86_64. www.emdebian.org builds a number of cross-compilers, which can be installed by adding the following lines to /etc/apt/sources.list:
  
Builder contains cross-compilers capable of building packages for all architectures that the CSC currently uses. As such, it should be possible to completely automate building of a specific package for all needed architectures.
+
deb http://mirror.csclub.uwaterloo.ca/emdebian/ stable main
 +
deb-src http://mirror.csclub.uwaterloo.ca/emdebian/ stable main
  
= Compiling a toolchain =
+
= Debian-supported Architectures =
  
* export ARCH=architecture (arm, i386, etc...)
+
Initial setup:
 +
export PREFIX=architecture (target architecture gcc prefix: arm, i486, x86_64, etc...)
 +
export DEB_ARCH=architecture (target architecture debian name: arm, i386, amd64, etc...)
 +
sudo apt-get install apt-cross dpkg-cross autoconf automake gawk flex bison debhelper devscripts cdbs fakeroot
 +
apt-cross -a $DEB_ARCH -i linux-kernel-headers libc6 libc6-dev
 +
Binutils:
 +
apt-get source binutils gcc-4.1
 +
cd binutils and run:
 +
TARGET=$PREFIX-linux-gnu fakeroot debian/rules binary-cross
 +
sudo dpkg -i binutils-$PREFIX-linux-gnu_*.deb
 +
GCC:
 +
cd gcc-4.1 and run:
 +
export GCC_TARGET=$DEB_ARCH
 +
export DEB_CROSS_INDEPENDENT=yes
 +
export WITHOUT_LANG=java,fortran,pascal,obj,obj-c++,ada,treelang
 +
export DEB_CROSS_NO_BIARCH=yes
 +
export USE_NJOBS=$(echo $(cat /proc/cpuinfo | grep ^processor | wc -l)*2 | bc)
 +
export DEBUILD_PRESERVE_ENVVARS=GCC_TARGET,DEB_CROSS_INDEPENDNET,WITHOUT_LANG,DEB_CROSS_NO_BIARCH,USE_NJOBS
 +
debuild -rfakeroot -k$USER
 +
sudo dpkg -i gcc-4.1-*.deb
  
* Install apt-cross, dpkg-cross, autoconf, automake, gawk, flex, bison, debhelper, devscripts, cdbs, fakeroot
+
It's generally useful to upload these built packages to the CSC debian repository. To do this you need to scp the .deb's over to debian.csclub and run 'rrr-includedeb deb-files...'.
* Run 'apt-cross -a $ARCH -i linux-kernel-headers libc6 libc6-dev'
 
* 'apt-get source' binutils and gcc-4.1
 
* cd binutils and run:
 
** TARGET=$ARCH-linux-gnu fakeroot debian/rules binary-cross
 
* Install resulting cross binutils
 
* cd gcc-4.1 and run:
 
** export GCC_TARGET=$ARCH
 
** export DEB_CROSS_INDEPENDENT=yes
 
** export WITHOUT_LANG=java,fortran,pascal,obj,obj-c++,ada,treelang
 
** export DEB_CROSS_NO_BIARCH=yes
 
** debian/rules control
 
** dpkg-buildpackage -b -rfakeroot
 
* Install resulting cross gcc-4.1
 
  
It's generally useful to upload these built packages to the CSC debian repository. To do this you need to scp the .deb's over to natural-flavours and run 'rrr includedeb etch deb-files...'.
+
= Debian Cross-packages =
  
= Emdebian =
+
There are a few tools that are useful for building cross-packages:
  
Emdebian is the Debian project responsible for dpkg-cross, apt-cross, and emdebian-tools.
+
* emdebuild: an architecture aware version of debuild.
 +
* dpkg-cross: a version of dpkg that allows you to install architecture-specific libraries in an isolated way. For example, dpkg-cross will build a package called libc6-mips-cross from the mips libc6 package. This cross package can then be installed alongside the mips cross-compiler.
 +
* apt-cross: a front-end to dpkg-cross. It will automatically fetch and build cross packages.
  
== Dpkg-cross ==
+
= SPARC Solaris 8 (student environment) =  
Dpkg-cross is a version of dpkg that allows you to install architecture-specific libraries in an isolated way. For example, dpkg-cross will build a package called libc6-mips-cross from the mips libc6 package. This cross package can then be installed alongside the mips cross-compiler.
 
  
== Apt-cross ==
+
Initial setup:
Apt-cross is a front-end to dpkg-cross. It will automatically fetch and build cross packages.
+
export TARGET=sparc-sun-solaris2.8
 +
export PREFIX=/opt/$TARGET-toolchain
 +
mkdir $PREFIX
 +
export WORKDIR=/tmp/$TARGET-toolchain
 +
mkdir $WORKDIR
 +
export PATH=$PREFIX/bin:$PATH
  
== Emdebuild ==
+
Fetch Solaris includes/libs:
Emdebuild is an architecture aware version of debuild.
+
cd $WORKDIR
 +
rsync -av --copy-unsafe-links cpu20.student.cs.uwaterloo.ca:/usr/lib/ lib
 +
* lib is ~ 1100 MiB
 +
rsync -av --copy-unsafe-links cpu20.student.cs.uwaterloo.ca:/usr/include/ include
 +
* include is ~ 100 MiB
  
= Sun4u =  
+
Binutils:
 +
cd $WORKDIR
 +
wget http://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2 && tar -xjf binutils-2.18.tar.bz2
 +
mkdir $WORKDIR/build-binutils && cd $WORKDIR/build-binutils
 +
../binutils-2.18/configure --target=$TARGET --prefix=$PREFIX
 +
make -j4 && make install
  
* DEB_TARGET_GNU_TYPE=sparc-sun-solaris2.8
+
GCC-3.4:
* DEB_TARGET_ALIAS=sparc-sun-solaris2.8
+
cd $WORKDIR
* DEB_TARGET_ARCH=sparc-sun-solaris2.8
+
wget http://ftp.gnu.org/gnu/gcc/gcc-3.4.6/gcc-3.4.6.tar.bz2 && tar -xjf gcc-3.4.6.tar.bz2
 +
mkdir $WORKDIR/build-gcc-3.4 && cd $WORKDIR/build-gcc-3.4
 +
../gcc-3.4.6/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++ --with-gnu-ld --with-gnu-as --enable-shared \
 +
  --disable-multilib --enable-threads=posix --enable-long-long --with-headers=$WORKDIR/include --with-libs=$WORKDIR/lib
 +
make -j4 && make install
 +
 
 +
Notes:
 +
* In order to get gcc to compile, I had to modify $WORKDIR/build-gcc-3.4/gcc-3.4.6/gcc/config/sparc/gmon-sol2.c by replacing PATH_MAX with 1024.
 +
* When you compile g++, libstdc++.so.6 gets compiled and installed, which causes libstdc++.so to be symlinked to libstdc++.so.6. However, the student environment doesn't include libstdc++.so.6. You can fix this by changing the symlink to libstdc++.so.5:
 +
rm $PREFIX/$TARGET/lib/libstdc++.so && ln -s libstdc++.so.5 $PREFIX/$TARGET/lib/libstdc++.so

Latest revision as of 23:18, 25 March 2008

Builder

Builder is a vserver that is used to build cross-compilers and cross-packages that run on x86_64 machines. The current list of installed cross-compilers includes alpha, arm, hppa (binutils only), i486, ia64, m68k, mips, mipsel, powerpc, sparc and x86_64. www.emdebian.org builds a number of cross-compilers, which can be installed by adding the following lines to /etc/apt/sources.list:

deb http://mirror.csclub.uwaterloo.ca/emdebian/ stable main
deb-src http://mirror.csclub.uwaterloo.ca/emdebian/ stable main

Debian-supported Architectures

Initial setup:

export PREFIX=architecture (target architecture gcc prefix: arm, i486, x86_64, etc...)
export DEB_ARCH=architecture (target architecture debian name: arm, i386, amd64, etc...)
sudo apt-get install apt-cross dpkg-cross autoconf automake gawk flex bison debhelper devscripts cdbs fakeroot
apt-cross -a $DEB_ARCH -i linux-kernel-headers libc6 libc6-dev

Binutils:

apt-get source binutils gcc-4.1
cd binutils and run:
TARGET=$PREFIX-linux-gnu fakeroot debian/rules binary-cross
sudo dpkg -i binutils-$PREFIX-linux-gnu_*.deb

GCC:

cd gcc-4.1 and run:
export GCC_TARGET=$DEB_ARCH
export DEB_CROSS_INDEPENDENT=yes
export WITHOUT_LANG=java,fortran,pascal,obj,obj-c++,ada,treelang
export DEB_CROSS_NO_BIARCH=yes
export USE_NJOBS=$(echo $(cat /proc/cpuinfo | grep ^processor | wc -l)*2 | bc)
export DEBUILD_PRESERVE_ENVVARS=GCC_TARGET,DEB_CROSS_INDEPENDNET,WITHOUT_LANG,DEB_CROSS_NO_BIARCH,USE_NJOBS
debuild -rfakeroot -k$USER
sudo dpkg -i gcc-4.1-*.deb

It's generally useful to upload these built packages to the CSC debian repository. To do this you need to scp the .deb's over to debian.csclub and run 'rrr-includedeb deb-files...'.

Debian Cross-packages

There are a few tools that are useful for building cross-packages:

  • emdebuild: an architecture aware version of debuild.
  • dpkg-cross: a version of dpkg that allows you to install architecture-specific libraries in an isolated way. For example, dpkg-cross will build a package called libc6-mips-cross from the mips libc6 package. This cross package can then be installed alongside the mips cross-compiler.
  • apt-cross: a front-end to dpkg-cross. It will automatically fetch and build cross packages.

SPARC Solaris 8 (student environment)

Initial setup:

export TARGET=sparc-sun-solaris2.8
export PREFIX=/opt/$TARGET-toolchain
mkdir $PREFIX
export WORKDIR=/tmp/$TARGET-toolchain
mkdir $WORKDIR
export PATH=$PREFIX/bin:$PATH

Fetch Solaris includes/libs:

cd $WORKDIR
rsync -av --copy-unsafe-links cpu20.student.cs.uwaterloo.ca:/usr/lib/ lib
* lib is ~ 1100 MiB
rsync -av --copy-unsafe-links cpu20.student.cs.uwaterloo.ca:/usr/include/ include
* include is ~ 100 MiB

Binutils:

cd $WORKDIR
wget http://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2 && tar -xjf binutils-2.18.tar.bz2
mkdir $WORKDIR/build-binutils && cd $WORKDIR/build-binutils
../binutils-2.18/configure --target=$TARGET --prefix=$PREFIX
make -j4 && make install

GCC-3.4:

cd $WORKDIR
wget http://ftp.gnu.org/gnu/gcc/gcc-3.4.6/gcc-3.4.6.tar.bz2 && tar -xjf gcc-3.4.6.tar.bz2
mkdir $WORKDIR/build-gcc-3.4 && cd $WORKDIR/build-gcc-3.4
../gcc-3.4.6/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++ --with-gnu-ld --with-gnu-as --enable-shared \
  --disable-multilib --enable-threads=posix --enable-long-long --with-headers=$WORKDIR/include --with-libs=$WORKDIR/lib
make -j4 && make install

Notes:

  • In order to get gcc to compile, I had to modify $WORKDIR/build-gcc-3.4/gcc-3.4.6/gcc/config/sparc/gmon-sol2.c by replacing PATH_MAX with 1024.
  • When you compile g++, libstdc++.so.6 gets compiled and installed, which causes libstdc++.so to be symlinked to libstdc++.so.6. However, the student environment doesn't include libstdc++.so.6. You can fix this by changing the symlink to libstdc++.so.5:
rm $PREFIX/$TARGET/lib/libstdc++.so && ln -s libstdc++.so.5 $PREFIX/$TARGET/lib/libstdc++.so