GDC/Installation/Generic

From D Wiki
Jump to: navigation, search


Introduction

This page describes the generic installation process which should be valid for every system but does not include system specific details and tweaks. Please use the system specific installation guides for your system if available.


Prerequesites

The minimum system requirements you need to obtain and build GDC are:

  • gcc and g++
  • libmpc-dev
  • libmpfr-dev
  • libgmp3-dev
  • autoconf and automake
  • flex and bison
  • patch
  • git

For cross-compiling/multilib builds, you should also have installed:

  • gcc-multilib
  • (maybe g++-multilib)

Building

Run these commands in a terminal:

mkdir -p gdc/dev
git clone https://github.com/D-Programming-GDC/GDC.git gdc/dev


NOTE: Master branch contains GDC compatible with GCC 6. In order to build GDC against a previous version, pick the relevant branch e.g. GCC 4.9.x pick gdc-4.9:

git checkout gdc-4.9


To build the D1 Compiler:

cd gdc/dev
git checkout gdc-1.x
cd ../


Grab GCC sources from a mirror. You will need the full gcc archives. Unpack the archives in the gdc dir. This creates something like gdc/gcc-4.9.0. Run these commands:

cd gdc/dev
./setup-gcc.sh ../gcc-4.9.0
mkdir ../objdir
cd ../objdir
../gcc-4.9.0/configure --enable-languages=d --disable-bootstrap \
    --prefix=/opt/gdc \
    --with-bugurl="http://bugzilla.gdcproject.org" \
    --enable-checking=yes
make -j2 2>&1 | tee build.log                            # insert your number of cores in the -j argument
make install
export PATH=$PATH:/opt/gdc/bin


If you want to compile a release version drop --disable-bootstrap and use --enable-checking=release. Other configure arguments you might want to use:

--[enable|disable]-nls          # Native language support (NLS).  Lets GDC output diagnostics in languages other than English.
--[enable|disable]-libgomp      # Build GCC with OMP support.  This is not used by GDC.
--[enable|disable]-libmudflap   # Build GCC with Mudflap pointer debugging support.  This is not used by GDC.
--[enable|disable]-libquadmath  # Build GCC with 128-bit floating point support.  This is not used by GDC.
--[enable|disable|-libssp       # Build GCC with stack smashing protection.
--[enable|disable]-lto          # Support link-time optimization.
--[enable|disable]-ld           # Build the ld linker.
--[enable|disable]-gold         # Build the gold linker.
--[enable|disable]-multilib     # Allow building both 32-bit and 64-bit apps/libs.
--[enable|disable]-shared       # Build shared libraries.
--with-multilib-list=mXX,mYY    # Select multilibs, eg: --with-multilib-list=m32,m64,mx32 (AArch64 and x86-64 only)


If you get compile errors in Ubuntu (at least x64 version) configure it with multilib (and install gcc-multilib of course).

The make command will perform the build. make install will install the compiled GDC. Use make install-strip to automatically strip symbols from the huge executables.

Since prefix is set to /opt/gdc you will install GDC there so it will not mess up with the installed GCC. Go in /opt/gdc/bin to find the gdc executable. With this source structure it will be easy to do modifications of the sources. To do changes, just modify files in gdc/d directory, it will be visible by the GCC sources. The objdir directory is used for configuration so that the GCC sources remains unmodified.


After following the instructions you can do a quick test:

goshawk@jupiter:/$ gdc -v
Using built-in specs.
COLLECT_GCC=/opt/gdc/bin/gdc
COLLECT_LTO_WRAPPER=/opt/gdc/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.8.1/configure --enable-languages=d --disable-bootstrap --prefix=/opt/gdc --with-bugurl=http://gdcproject.org/bugzilla --enable-checking=yes
Thread model: posix
gcc version 4.8.1 (GCC)

As you can see your current shell session will start using the newly compiled GCC and GDC, overriding but not overwriting the system default.

Updating an existing build

If you have a setup as described above and want to build a newer gdc version you don't have to do all steps again:

cd gdc/dev
./setup-gcc.sh --update ../gcc-4.9.0
cd ../objdir
make -j2 2>&1 | tee build.log                            # insert your number of cores in the -j argument
make install

Building GDC without building Druntime/Phobos

The gdc compiler will build for most (hopefully all) configurations supported by GCC. Druntime and Phobos on the other hand only build for very few systems. If you want to use a custom runtime or you are porting druntime and phobos and will built these later on, it might be useful to disable Druntime/Phobos:

Simply pass --disable-libphobos when configuring GCC. This will disable both libphobos and libdruntime.

../gcc-4.9.0/configure --enable-languages=d --disable-bootstrap \
    --prefix=/opt/gdc \
    --with-bugurl="http://bugzilla.gdcproject.org" \
    --enable-checking=yes \
    --disable-libphobos

Building only Druntime/Phobos

It is possible to build only a new libdruntime/libphobos with an existing GCC compiler. You still need the full GCC sources and you'll have to setup the GCC sources as explained in the GDC compile instructions. After you've executed ./setup-gcc.sh, execute these commands:

mkdir -p ../objdir-phobos/main
cd ../objdir-phobos/main
../../gcc-4.9.0/libphobos/configure --prefix=/opt/gdc
make
sudo make install

Note: We created a two-level build directory objdir-phobos/main. For multilib builds configure will setup more variants such as objdir-phobos/32 in the parent folder and you don't want these outside of your objdir directory.

You can also use cross compilers:

mkdir -p ../objdir-phobos/main
cd ../objdir-phobos/main
../../gcc-4.9.0/libphobos/configure --prefix=/opt/gdc --host=arm-linux-gnueabi
make
sudo make install

To build druntime with libbacktrace support:

mkdir objdir-bt && cd objdir-bt
../gcc-4.9.0/libbacktrace/configure --host=arm-linux-gnueabi
make

mkdir ../objdir-phobos && cd ../objdir-phobos
../gcc-4.9.0/libphobos/configure --host=arm-linux-gnueabi --with-libbacktrace=/mnt/hdd/GDC/objdir-bt
make && make install