https://wiki.dlang.org/api.php?action=feedcontributions&user=Andrewbrown&feedformat=atomD Wiki - User contributions [en]2024-03-29T14:40:38ZUser contributionsMediaWiki 1.31.2https://wiki.dlang.org/?title=Building_LDC_from_source&diff=6205Building LDC from source2015-05-26T18:30:25Z<p>Andrewbrown: Added more details on the cmake variables I needed to set because libconfig++ and llvm weren't in the usual places</p>
<hr />
<div>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 [[Building and hacking LDC on Windows using MSVC|the dedicated page]].<br />
<br />
== Prerequisites ==<br />
<br />
* Git (for fetching the source code, if not using a tarball)<br />
* a C++ toolchain (GCC, Clang, …)<br />
* CMake 2.8+<br />
* LLVM 3.2–3.5 (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 [http://llvm.org/bugs/show_bug.cgi?id=15972 regression])<br />
* libconfig++ and its header files (the <tt>-devel</tt> or <tt>-dev</tt> package for some Linux distributions, on OSX: <tt>sudo port install libconfig-hr</tt>)<br />
* libcurl-dev for building the D2 standard library and tests (various versions available, e.g. libcurl4-gnutls-dev on Ubuntu)<br />
<br />
Please check the LLVM page on [http://www.llvm.org/docs/GettingStarted.html#broken-versions-of-gcc-and-other-tools broken versions of GCC and other tools] to make sure your toolchain is not known to be bad.<br />
<br />
=== LLVM ===<br />
<br />
Many Linux distributions already provide recent binary LLVM packages, sometimes in the form of user-curated package repositories (PPA, …). If an recent LLVM pacakge is available, you might prefer to use it, as LLVM is a rather big project to build.<br />
<br />
==== Building LLVM manually ====<br />
<br />
Download [http://llvm.org/releases/3.5.0/llvm-3.5.0.src.tar.xz LLVM 3.5.0] with <tt>$ wget http://llvm.org/releases/3.5.0/llvm-3.5.0.src.tar.xz</tt>, extract the archive, and then run:<br />
<br />
<pre>$ ./configure --enable-optimized --disable-assertions --enable-targets=x86<br />
$ make # add -j&lt;n&gt; as appropriate depending on your system<br />
$ sudo make install</pre><br />
If you are planning to work on LDC itself, you might want to install a debug build of LLVM instead by using <tt>./configure --enable-assertions</tt>. Warning: This leads to a ''heavy'' slowdown!<br />
<br />
== LDC ==<br />
<br />
Now, your system should be ready to build and install LDC from source.<br />
<br />
First, clone the [https://github.com/ldc-developers/ldc LDC GitHub repository]:<br />
<pre>$ git clone --recursive https://github.com/ldc-developers/ldc.git</pre><br />
<br />
If you're behind a company firewall and cloning of the submodules fail, first configure git to use a different protocol, ex https:<br />
<pre>$ git config --global url."https://github".insteadOf git://github</pre><br />
<br />
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 <tt>git submodule update --init</tt>.<br />
<br />
Then, just run the following commands as usual (see the list of useful CMake switches below):<br />
<br />
<pre>cd ldc<br />
mkdir build &amp;&amp; cd build # arbitrary working directory<br />
cmake .. <br />
make # -j&lt;n&gt; as appropriate<br />
sudo make install</pre><br />
The last step is optional; instead of installing it to the system, you can also choose to run LDC from the <tt>bin/</tt> directory in your CMake working tree.<br />
<br />
=== Useful CMake variables ===<br />
<br />
* '''LIB_SUFFIX''': Some Linux distributions, such as Fedora, expect 64 bit libraries in <tt>/usr/lib64</tt> instead of <tt>/usr/lib</tt>. In this case, the installation directory can be adjusted using <tt>-DLIB_SUFFIX=64</tt>.<br />
* '''CMAKE_INSTALL_PREFIX''': The installation prefix, <tt>/usr/local</tt> by default (e.g. <tt>-DCMAKE_INSTALL_PREFIX=/opt/ldc</tt>).<br />
* '''INCLUDE_INSTALL_DIR''': The location the D modules for druntime and Phobos are installed to.<br />
* '''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.<br />
* '''LLVM_ROOT_DIR''' and '''LLVM_CONFIG''': Allows you to specify the LLVM instance to use. LLVM_CONFIG specifies the path and name of the <tt>llvm-config</tt> binary to use. By default, it is assumed to be <tt>${LLVM_ROOT_DIR}/bin/llvm-config</tt>, otherwise it is searched for on default system paths.<br />
* '''LIBCONFIG_LIBRARY''' and '''LIBCONFIG_INCLUDE_DIR''': These variables can be used to specify the location of the libconfig++ library files and the path to the corresponding header files.<br />
<br />
== Tips ==<br />
<br />
The Makefiles generated by CMake respect the <tt>DESTDIR</tt> variable for the <tt>install</tt> target. It is prepended to all the file installation targets. This can be useful for building packages: <tt>$ make install DESTDIR=&lt;your root directory&gt;</tt><br />
<br />
<br />
[[Category:LDC]]</div>Andrewbrown