GDC Cross-Compiler

From OSDev Wiki
Jump to: navigation, search
Difficulty level
Difficulty 1.png
Beginner

This page is under construction! This page or section is a work in progress and may thus be incomplete. Its content may be changed in the near future.

If you reached here, you should have enough knowledge about cross-compilers, how they work. and so on. If you don't, check out GCC Cross-Compiler.

Contents

Requirements

We assume you have a host system with a working GCC installation. If you are not using a bash shell, you might have to modify some of the command lines below. If you have just installed the basic Cygwin package, you have to run the setup.exe again and install the following packages:

  • GCC
  • Make
  • Flex
  • Bison

You will also have to install the following (using your system's package management):

  • GNU GMP (libgmp-devel on Cygwin, libgmp3-dev on apt-based systems, dev-libs/gmp on Gentoo)
  • GNU MPFR (libmpfr-devel on Cygwin, libmpfr-dev on apt-based systems, dev-libs/mpfr on Gentoo)
  • MPC (libmpc-devel on Cygwin, libmpc-dev on apt-based systems, dev-libs/mpc on Gentoo)

Step 1 - Bootstrap

We will build a toolset running on your host that can turn source code into object files for your target system.

We need the binutils and the GCC packages from http://ftp.gnu.org/gnu/. As of 2018-08-17, GCC 8.2.0 works. Download them to /usr/src (or where ever you think appropriate), and unpack them. Also, you need to get the gdc-8-stable branch at https://github.com/D-Programming-GDC/GDC/tree/gdc-8

Preparation

   export PREFIX=/usr/local/cross
   export TARGET=i586-elf
   cd /usr/src
   mkdir build build/binutils build/gcc

binutils

   cd /usr/src/build/binutils
   /usr/src/binutils-x.xx/configure --target=$TARGET --prefix=$PREFIX --disable-nls
   make all
   make install

gcc

First, unpack gcc, and we got /usr/src/gcc-x.x.x Then, from the GDC repo, run this:

   ./setup-gcc.sh /usr/src/gcc-x.x.x

Ensure that you used the gdc-8-stable

Now, you can build GCC.

   cd /usr/src/build-gcc
   export PATH=$PATH:$PREFIX/bin
   ../gcc-x.x.x/configure --target=$TARGET --prefix=$PREFIX --disable-nls \
       --enable-languages=c,d,c++ --without-headers --disable-libphobos
   make all-gcc
   make install-gcc

Step 2 - D runtime

The D frontend version 2.079.0 has complete support for the runtime in a pay-you-go fashion. The current gdc-8 branch uses frontend version 2.068.0 or similar. A pull request has been setup, however.

Till then, you can copy object.d from any `/import` directory from any other installation and remove out the `extern(C)` references, testing as you go. Remove everything that you can. TypeInfo, Throwable, Exception, etc. are required by the compiler (for now). You can also copy the standard library from other D OS projects (search on GitHub).

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox