Difference between revisions of "Building LDC from source"

From D Wiki
Jump to: navigation, search
(Useful CMake variables: BUILD_SHARED_LIBS is certainly not useful now)
(Useful CMake variables: Added info about LLVM config variables.)
Line 47: Line 47:
 
* '''INCLUDE_INSTALL_DIR''': The location the D modules for druntime and Phobos are installed to.
 
* '''INCLUDE_INSTALL_DIR''': The location the D modules for druntime and Phobos are installed to.
 
* '''RUNTIME_DIR''', '''PHOBOS2_DIR''': By default, druntime and Phobos are expected in <tt>runtime/</tt> as Git submodules. Should circumstances require it, these paths can be changed by setting the variables accordingly.
 
* '''RUNTIME_DIR''', '''PHOBOS2_DIR''': By default, druntime and Phobos are expected in <tt>runtime/</tt> as Git submodules. Should circumstances require it, these paths can be changed by setting the variables accordingly.
 +
* '''LLVM_ROOT_DIR''' and '''LLVM_CONFIG''': Allows you to specify the LLVM instance to use. LLVM_CONFIG specifies the path of the <tt>llvm-config</tt> binary to use. By default, it is searched in <tt>${LLVM_ROOT_DIR}/bin</tt>, and then the default system paths.
  
 
== Tips ==
 
== Tips ==

Revision as of 22:04, 13 September 2013

This page gives an overview of what is required to build and install LDC on most Posix-like systems such as Linux or OS X. For building LDC on Windows, please see the dedicated page.

Prerequesites

  • Git (for fetching the source code, if not using a tarball)
  • a C++ toolchain (GCC, Clang, …)
  • CMake 2.8+
  • LLVM 3.2–3.3 (3.1 or 3.0 work, but are not recommended, see LLVM issues affecting LDC; LLVM 3.3 does not work on OS X because of a regression)
  • libconfig++ and its header files (the -devel or -dev package for some Linux distributions, on OSX: sudo port install libconfig-hr)
  • libcurl-dev for building the D2 standard library and tests (various versions available, e.g. libcurl4-gnutls-dev on Ubuntu)

Please check the LLVM page on broken versions of GCC and other tools to make sure your toolchain is not known to be bad.

LLVM

Many Linux distributions already provide recent binary LLVM packages, sometimes in the form of user-curated package repositories (PPA, …). If an LLVM 3.2 pacakge is available, you might prefer to use it, as LLVM is a rather big project to build.

Building LLVM manually

Download LLVM 3.2 with $ wget http://www.llvm.org/releases/3.2/llvm-3.2.src.tar.gz, extract the archive, and then run:

$ ./configure --enable-optimized --disable-assertions --enable-targets=x86
$ make   # add -j<n> as appropriate depending on your system
$ sudo make install

If you are planning to work on LDC itself, you might want to install a debug build of LLVM instead by using ./configure --enable-assertions. Warning: This leads to a heavy slowdown!

LDC

Now, your system should be ready to build and install LDC from source. First, clone the LDC GitHub repository:

$ git clone --recursive http://github.com/ldc-developers/ldc.git

If you already have a local copy of the source tree, don’t forget to make sure your submodules are up to date by running git submodule update --init.

Then, just run the following commands as usual (see the list of useful CMake switches below):

cd ldc
mkdir build && cd build   # arbitrary working directory
cmake .. 
make   # -j<n> as appropriate
sudo make install

The last step is optional; instead of installing it to the system, you can also choose to run LDC from the bin/ directory in your CMake working tree.

Useful CMake variables

  • LIB_SUFFIX: Some Linux distributions, such as Fedora, expect 64 bit libraries in /usr/lib64 instead of /usr/lib. In this case, the installation directory can be adjusted using -DLIB_SUFFIX=64.
  • CMAKE_INSTALL_PREFIX: The installation prefix, /usr/local by default (e.g. -DCMAKE_INSTALL_PREFIX=/opt/ldc).
  • INCLUDE_INSTALL_DIR: The location the D modules for druntime and Phobos are installed to.
  • RUNTIME_DIR, PHOBOS2_DIR: By default, druntime and Phobos are expected in runtime/ as Git submodules. Should circumstances require it, these paths can be changed by setting the variables accordingly.
  • LLVM_ROOT_DIR and LLVM_CONFIG: Allows you to specify the LLVM instance to use. LLVM_CONFIG specifies the path of the llvm-config binary to use. By default, it is searched in ${LLVM_ROOT_DIR}/bin, and then the default system paths.

Tips

The Makefiles generated by CMake respect the DESTDIR variable for the install target. It is prepended to all the file installation targets. This can be useful for building packages: $ make install DESTDIR=<your root directory>