Difference between revisions of "GDC/Cross Compiler/Existing Sysroot"

From D Wiki
Jump to: navigation, search
(Created page with "{{ParentArticle|GDC > Cross Compiler}} This describes how to build a cross compiler if you have access to an existing system root (short sysroot)....")
 
(GNU Binutils)
Line 78: Line 78:
 
If you're target sysroot is a recent debian distribution (>= wheezy) you'll have to apply one of the debian patches to
 
If you're target sysroot is a recent debian distribution (>= wheezy) you'll have to apply one of the debian patches to
 
binutils. Download it from here: http://bazaar.launchpad.net/~doko/binutils/pkg-2.24-debian/view/head:/patches/129_multiarch_libpath.patch
 
binutils. Download it from here: http://bazaar.launchpad.net/~doko/binutils/pkg-2.24-debian/view/head:/patches/129_multiarch_libpath.patch
 +
 +
You then have to set '''DEB_TARGET_MULTIARCH''' before building binutils:
 +
<syntaxhighlight lang="bash">
 +
export DEB_TARGET_MULTIARCH=arm-linux-gnueabi
 +
</syntaxhighlight>
 +
The correct value can be obtained by executing this on the target:
 +
<syntaxhighlight lang="bash">
 +
dpkg-architecture -qDEB_HOST_MULTIARCH
 +
</syntaxhighlight>
  
 
== Download GDC ==
 
== Download GDC ==

Revision as of 20:40, 21 March 2014


This describes how to build a cross compiler if you have access to an existing system root (short sysroot). A sysroot is a folder which contains a minimal filesystem (especially libraries, the C library and header files). An example sysroot could look like this: 'sysroot/usr', 'sysroot/usr/lib', 'sysroot/usr/include'.

The sysroot

We assume that a sysroot is available at $SYSROOT. If the sysroot directory is inside the prefix where we'll install the compiler, the complete prefix directory can be moved to different locations. If it's not in the prefix directory GCC always uses the absolute path for the sysroot and if you move the sysroot the compiler will not work anymore.

Sysroot over SSH

If your target machine offers a fast SSH access it's possible to use the file system of the remote machine directly. This way the crosscompiler has full access to all libraries of the remote system. If a library is missing simply install it on the remote machine using the standard package manager.

You can mount a remote sysroot by using SSHFS:

sshfs -o idmap=user,follow_symlinks user@targethost:/ $SYSROOT

user@targethost is an SSH user / hostname account. $SYSROOT is the location where the sysroot will be mounted.

The follow_symlinks option is important. The remote filesystem will have absolute symlinks (/usr/lib/libdl.so --> /usr/lib/libdl.so.2) .follow_symlinks makes sure we really get access to the remote /usr/lib/libdl.so.2 and not to the local one.

Specifying a target and installation folder

export TARGET=arm-linux-gnueabi
export PREFIX={installation folder}
export SYSROOT={sysroot folder}

Replace {installation folder} with the absolute path to the folder the toolchain should be installed in.

GNU Binutils

# Delete existing binutils source archive and download a new one
#-------------------------------------------------------------------
export BINUTILS_NAME=binutils-2.24
export BINUTILS_SOURCE_ARCHIVE=$BINUTILS_NAME.tar.bz2
rm -f $BINUTILS_SOURCE_ARCHIVE
rm -rf $BINUTILS_NAME
wget http://ftpmirror.gnu.org/binutils/$BINUTILS_SOURCE_ARCHIVE

# Extract binutils
#-------------------------------------------------------------------
tar xjfv $BINUTILS_SOURCE_ARCHIVE

# Create binutils build directory
#-------------------------------------------------------------------
export BINUTILS_BUILD_DIR=binutils-build
rm -rf $BINUTILS_BUILD_DIR
mkdir $BINUTILS_BUILD_DIR

# Configure and build binutils
#-------------------------------------------------------------------
cd $BINUTILS_BUILD_DIR
../$BINUTILS_NAME/configure \
  --with-sysroot=$SYSROOT \
  --target=$TARGET   \
  --prefix=$PREFIX   \
  --disable-nls      \
  --disable-multilib \
  --with-gnu-as      \
  --with-gnu-ld      \
  --disable-libssp   
make -j4 all
make install
cd ..

Note: Debian targets

If you're target sysroot is a recent debian distribution (>= wheezy) you'll have to apply one of the debian patches to binutils. Download it from here: http://bazaar.launchpad.net/~doko/binutils/pkg-2.24-debian/view/head:/patches/129_multiarch_libpath.patch

You then have to set DEB_TARGET_MULTIARCH before building binutils:

export DEB_TARGET_MULTIARCH=arm-linux-gnueabi

The correct value can be obtained by executing this on the target:

dpkg-architecture -qDEB_HOST_MULTIARCH

Download GDC

# Download GDC
#-------------------------------------------------------------------
rm -rf gdc
mkdir gdc
git clone https://github.com/D-Programming-GDC/GDC.git gdc
cd gdc
git checkout gdc-4.8
cd ..

Download GCC

# Delete existing GCC source archive and download a new one
#-------------------------------------------------------------------
export GCC_NAME=gcc-4.8.2
export GCC_SOURCE_ARCHIVE=$GCC_NAME.tar.bz2
rm -f $GCC_SOURCE_ARCHIVE
rm -rf $GCC_NAME
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/$GCC_NAME/$GCC_SOURCE_ARCHIVE

# Extract GCC
#-------------------------------------------------------------------
tar xjfv $GCC_SOURCE_ARCHIVE

Add GDC to GCC

# Add GDC to GCC
#-------------------------------------------------------------------
cd gdc
./setup-gcc.sh ../$GCC_NAME
cd ..

Build GCC

# Create GCC build directory
#-------------------------------------------------------------------
export GCC_BUILD_DIR=gcc-build
rm -rf $GCC_BUILD_DIR
mkdir $GCC_BUILD_DIR

# Configure and build GCC
#-------------------------------------------------------------------
cd $GCC_BUILD_DIR
../$GCC_NAME/configure --target=$TARGET --prefix=$PREFIX \
  --enable-languages=d     \
  --disable-bootstrap      \
  --disable-libssp         \
  --disable-libgomp        \
  --disable-libmudflap     \
  --disable-multilib       \
  --disable-decimal-float  \
  --disable-libffi         \
  --disable-libmudflap     \
  --disable-libquadmath    \
  --disable-libssp         \
  --disable-nls            \
  --with-gnu-as            \
  --with-gnu-ld            \
  --with-sysroot=$SYSROOT
make -j4
make install

Compiler GDC