blob: 6f9a13410555c81db372d8ee7066e0d8befa0380 [file] [log] [blame]
Chris Bieneman9f611e32015-03-13 01:58:14 +00001====================================
2Building LLVM With Autotools
3====================================
4
5.. contents::
6 :local:
7
8Overview
9========
10
Chris Bieneman3bec07a2015-03-14 21:20:32 +000011This document details how to use the LLVM autotools based build system to
12configure and build LLVM from source. The normal developer process using CMake
13is detailed `here <GettingStarted.html#check-here>`_.
14
15A Quick Summary
16---------------
17
18#. Configure and build LLVM and Clang:
19
20 * ``cd where-you-want-to-build-llvm``
21 * ``mkdir build`` (for building without polluting the source dir)
22 * ``cd build``
23 * ``../llvm/configure [options]``
24 Some common options:
25
26 * ``--prefix=directory`` --- Specify for *directory* the full pathname of
27 where you want the LLVM tools and libraries to be installed (default
28 ``/usr/local``).
29
30 * ``--enable-optimized`` --- Compile with optimizations enabled (default
31 is NO).
32
33 * ``--enable-assertions`` --- Compile with assertion checks enabled
34 (default is YES).
35
36 * ``make [-j]`` --- The ``-j`` specifies the number of jobs (commands) to run
37 simultaneously. This builds both LLVM and Clang for Debug+Asserts mode.
38 The ``--enable-optimized`` configure option is used to specify a Release
39 build.
40
41 * ``make check-all`` --- This run the regression tests to ensure everything
42 is in working order.
43
44 * If you get an "internal compiler error (ICE)" or test failures, see
45 `here <GettingStarted.html#check-here>`_.
Chris Bieneman9f611e32015-03-13 01:58:14 +000046
47Local LLVM Configuration
48------------------------
49
50Once checked out from the Subversion repository, the LLVM suite source code must
51be configured via the ``configure`` script. This script sets variables in the
52various ``*.in`` files, most notably ``llvm/Makefile.config`` and
53``llvm/include/Config/config.h``. It also populates *OBJ_ROOT* with the
54Makefiles needed to begin building LLVM.
55
56The following environment variables are used by the ``configure`` script to
57configure the build system:
58
59+------------+-----------------------------------------------------------+
60| Variable | Purpose |
61+============+===========================================================+
62| CC | Tells ``configure`` which C compiler to use. By default, |
63| | ``configure`` will check ``PATH`` for ``clang`` and GCC C |
64| | compilers (in this order). Use this variable to override |
65| | ``configure``\'s default behavior. |
66+------------+-----------------------------------------------------------+
67| CXX | Tells ``configure`` which C++ compiler to use. By |
68| | default, ``configure`` will check ``PATH`` for |
69| | ``clang++`` and GCC C++ compilers (in this order). Use |
70| | this variable to override ``configure``'s default |
71| | behavior. |
72+------------+-----------------------------------------------------------+
73
74The following options can be used to set or enable LLVM specific options:
75
76``--enable-optimized``
77
78 Enables optimized compilation (debugging symbols are removed and GCC
79 optimization flags are enabled). Note that this is the default setting if you
80 are using the LLVM distribution. The default behavior of a Subversion
81 checkout is to use an unoptimized build (also known as a debug build).
82
83``--enable-debug-runtime``
84
85 Enables debug symbols in the runtime libraries. The default is to strip debug
86 symbols from the runtime libraries.
87
88``--enable-jit``
89
90 Compile the Just In Time (JIT) compiler functionality. This is not available
91 on all platforms. The default is dependent on platform, so it is best to
92 explicitly enable it if you want it.
93
94``--enable-targets=target-option``
95
96 Controls which targets will be built and linked into llc. The default value
97 for ``target_options`` is "all" which builds and links all available targets.
98 The "host" target is selected as the target of the build host. You can also
99 specify a comma separated list of target names that you want available in llc.
100 The target names use all lower case. The current set of targets is:
101
102 ``aarch64, arm, arm64, cpp, hexagon, mips, mipsel, mips64, mips64el, msp430,
103 powerpc, nvptx, r600, sparc, systemz, x86, x86_64, xcore``.
104
105``--enable-doxygen``
106
107 Look for the doxygen program and enable construction of doxygen based
108 documentation from the source code. This is disabled by default because
109 generating the documentation can take a long time and producess 100s of
110 megabytes of output.
111
112To configure LLVM, follow these steps:
113
114#. Change directory into the object root directory:
115
116 .. code-block:: console
117
118 % cd OBJ_ROOT
119
120#. Run the ``configure`` script located in the LLVM source tree:
121
122 .. code-block:: console
123
Jonathan Roelofscf1ba1d2015-04-29 20:06:41 +0000124 % $LLVM_SRC_DIR/configure --prefix=/install/path [other options]
Chris Bieneman9f611e32015-03-13 01:58:14 +0000125
126Compiling the LLVM Suite Source Code
127------------------------------------
128
129Once you have configured LLVM, you can build it. There are three types of
130builds:
131
132Debug Builds
133
134 These builds are the default when one is using a Subversion checkout and
135 types ``gmake`` (unless the ``--enable-optimized`` option was used during
136 configuration). The build system will compile the tools and libraries with
137 debugging information. To get a Debug Build using the LLVM distribution the
138 ``--disable-optimized`` option must be passed to ``configure``.
139
140Release (Optimized) Builds
141
142 These builds are enabled with the ``--enable-optimized`` option to
143 ``configure`` or by specifying ``ENABLE_OPTIMIZED=1`` on the ``gmake`` command
144 line. For these builds, the build system will compile the tools and libraries
145 with GCC optimizations enabled and strip debugging information from the
146 libraries and executables it generates. Note that Release Builds are default
147 when using an LLVM distribution.
148
149Profile Builds
150
151 These builds are for use with profiling. They compile profiling information
152 into the code for use with programs like ``gprof``. Profile builds must be
153 started by specifying ``ENABLE_PROFILING=1`` on the ``gmake`` command line.
154
155Once you have LLVM configured, you can build it by entering the *OBJ_ROOT*
156directory and issuing the following command:
157
158.. code-block:: console
159
160 % gmake
161
162If the build fails, please `check here <GettingStarted.html#check-here>`_
163to see if you are using a version of GCC that is known not to compile LLVM.
164
165If you have multiple processors in your machine, you may wish to use some of the
166parallel build options provided by GNU Make. For example, you could use the
167command:
168
169.. code-block:: console
170
171 % gmake -j2
172
173There are several special targets which are useful when working with the LLVM
174source code:
175
176``gmake clean``
177
178 Removes all files generated by the build. This includes object files,
179 generated C/C++ files, libraries, and executables.
180
181``gmake dist-clean``
182
183 Removes everything that ``gmake clean`` does, but also removes files generated
184 by ``configure``. It attempts to return the source tree to the original state
185 in which it was shipped.
186
187``gmake install``
188
189 Installs LLVM header files, libraries, tools, and documentation in a hierarchy
Jonathan Roelofscf1ba1d2015-04-29 20:06:41 +0000190 under ``$PREFIX``, specified with ``$LLVM_SRC_DIR/configure --prefix=[dir]``, which
Chris Bieneman9f611e32015-03-13 01:58:14 +0000191 defaults to ``/usr/local``.
192
193``gmake -C runtime install-bytecode``
194
195 Assuming you built LLVM into $OBJDIR, when this command is run, it will
196 install bitcode libraries into the GCC front end's bitcode library directory.
197 If you need to update your bitcode libraries, this is the target to use once
198 you've built them.
199
200Please see the `Makefile Guide <MakefileGuide.html>`_ for further details on
201these ``make`` targets and descriptions of other targets available.
202
203It is also possible to override default values from ``configure`` by declaring
204variables on the command line. The following are some examples:
205
206``gmake ENABLE_OPTIMIZED=1``
207
208 Perform a Release (Optimized) build.
209
210``gmake ENABLE_OPTIMIZED=1 DISABLE_ASSERTIONS=1``
211
212 Perform a Release (Optimized) build without assertions enabled.
213
214``gmake ENABLE_OPTIMIZED=0``
215
216 Perform a Debug build.
217
218``gmake ENABLE_PROFILING=1``
219
220 Perform a Profiling build.
221
222``gmake VERBOSE=1``
223
224 Print what ``gmake`` is doing on standard output.
225
226``gmake TOOL_VERBOSE=1``
227
228 Ask each tool invoked by the makefiles to print out what it is doing on
229 the standard output. This also implies ``VERBOSE=1``.
230
231Every directory in the LLVM object tree includes a ``Makefile`` to build it and
232any subdirectories that it contains. Entering any directory inside the LLVM
233object tree and typing ``gmake`` should rebuild anything in or below that
234directory that is out of date.
235
236This does not apply to building the documentation.
237LLVM's (non-Doxygen) documentation is produced with the
238`Sphinx <http://sphinx-doc.org/>`_ documentation generation system.
239There are some HTML documents that have not yet been converted to the new
240system (which uses the easy-to-read and easy-to-write
241`reStructuredText <http://sphinx-doc.org/rest.html>`_ plaintext markup
242language).
Jonathan Roelofscf1ba1d2015-04-29 20:06:41 +0000243The generated documentation is built in the ``$LLVM_SRC_DIR/docs`` directory using
Chris Bieneman9f611e32015-03-13 01:58:14 +0000244a special makefile.
245For instructions on how to install Sphinx, see
246`Sphinx Introduction for LLVM Developers
247<http://lld.llvm.org/sphinx_intro.html>`_.
248After following the instructions there for installing Sphinx, build the LLVM
249HTML documentation by doing the following:
250
251.. code-block:: console
252
Jonathan Roelofscf1ba1d2015-04-29 20:06:41 +0000253 $ cd $LLVM_SRC_DIR/docs
Chris Bieneman9f611e32015-03-13 01:58:14 +0000254 $ make -f Makefile.sphinx
255
256This creates a ``_build/html`` sub-directory with all of the HTML files, not
257just the generated ones.
258This directory corresponds to ``llvm.org/docs``.
259For example, ``_build/html/SphinxQuickstartTemplate.html`` corresponds to
260``llvm.org/docs/SphinxQuickstartTemplate.html``.
261The :doc:`SphinxQuickstartTemplate` is useful when creating a new document.
262
263Cross-Compiling LLVM
264--------------------
265
266It is possible to cross-compile LLVM itself. That is, you can create LLVM
267executables and libraries to be hosted on a platform different from the platform
268where they are built (a Canadian Cross build). To configure a cross-compile,
269supply the configure script with ``--build`` and ``--host`` options that are
270different. The values of these options must be legal target triples that your
271GCC compiler supports.
272
273The result of such a build is executables that are not runnable on on the build
274host (--build option) but can be executed on the compile host (--host option).
275
276Check :doc:`HowToCrossCompileLLVM` and `Clang docs on how to cross-compile in general
277<http://clang.llvm.org/docs/CrossCompilation.html>`_ for more information
278about cross-compiling.
279
280The Location of LLVM Object Files
281---------------------------------
282
283The LLVM build system is capable of sharing a single LLVM source tree among
284several LLVM builds. Hence, it is possible to build LLVM for several different
285platforms or configurations using the same source tree.
286
287This is accomplished in the typical autoconf manner:
288
289* Change directory to where the LLVM object files should live:
290
291 .. code-block:: console
292
293 % cd OBJ_ROOT
294
295* Run the ``configure`` script found in the LLVM source directory:
296
297 .. code-block:: console
298
Jonathan Roelofscf1ba1d2015-04-29 20:06:41 +0000299 % $LLVM_SRC_DIR/configure
Chris Bieneman9f611e32015-03-13 01:58:14 +0000300
301The LLVM build will place files underneath *OBJ_ROOT* in directories named after
302the build type:
303
304Debug Builds with assertions enabled (the default)
305
306 Tools
307
308 ``OBJ_ROOT/Debug+Asserts/bin``
309
310 Libraries
311
312 ``OBJ_ROOT/Debug+Asserts/lib``
313
314Release Builds
315
316 Tools
317
318 ``OBJ_ROOT/Release/bin``
319
320 Libraries
321
322 ``OBJ_ROOT/Release/lib``
323
324Profile Builds
325
326 Tools
327
328 ``OBJ_ROOT/Profile/bin``
329
330 Libraries
331
332 ``OBJ_ROOT/Profile/lib``