1 ====================================
2 Building LLVM With Autotools
3 ====================================
11 This document details how to use the LLVM autotools based build system to
12 configure and build LLVM from source. The normal developer process using CMake
13 is detailed `here <GettingStarted.html#check-here>`_.
18 #. Configure and build LLVM and Clang:
20 * ``cd where-you-want-to-build-llvm``
21 * ``mkdir build`` (for building without polluting the source dir)
23 * ``../llvm/configure [options]``
26 * ``--prefix=directory`` --- Specify for *directory* the full pathname of
27 where you want the LLVM tools and libraries to be installed (default
30 * ``--enable-optimized`` --- Compile with optimizations enabled (default
33 * ``--enable-assertions`` --- Compile with assertion checks enabled
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
41 * ``make check-all`` --- This run the regression tests to ensure everything
44 * If you get an "internal compiler error (ICE)" or test failures, see
45 `here <GettingStarted.html#check-here>`_.
47 Local LLVM Configuration
48 ------------------------
50 Once checked out from the Subversion repository, the LLVM suite source code must
51 be configured via the ``configure`` script. This script sets variables in the
52 various ``*.in`` files, most notably ``llvm/Makefile.config`` and
53 ``llvm/include/Config/config.h``. It also populates *OBJ_ROOT* with the
54 Makefiles needed to begin building LLVM.
56 The following environment variables are used by the ``configure`` script to
57 configure the build system:
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 |
72 +------------+-----------------------------------------------------------+
74 The following options can be used to set or enable LLVM specific options:
76 ``--enable-optimized``
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).
83 ``--enable-debug-runtime``
85 Enables debug symbols in the runtime libraries. The default is to strip debug
86 symbols from the runtime libraries.
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.
94 ``--enable-targets=target-option``
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:
102 ``aarch64, arm, arm64, cpp, hexagon, mips, mipsel, mips64, mips64el, msp430,
103 powerpc, nvptx, r600, sparc, systemz, x86, x86_64, xcore``.
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
112 To configure LLVM, follow these steps:
114 #. Change directory into the object root directory:
116 .. code-block:: console
120 #. Run the ``configure`` script located in the LLVM source tree:
122 .. code-block:: console
124 % $LLVM_SRC_DIR/configure --prefix=/install/path [other options]
126 Compiling the LLVM Suite Source Code
127 ------------------------------------
129 Once you have configured LLVM, you can build it. There are three types of
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``.
140 Release (Optimized) Builds
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.
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.
155 Once you have LLVM configured, you can build it by entering the *OBJ_ROOT*
156 directory and issuing the following command:
158 .. code-block:: console
162 If the build fails, please `check here <GettingStarted.html#check-here>`_
163 to see if you are using a version of GCC that is known not to compile LLVM.
165 If you have multiple processors in your machine, you may wish to use some of the
166 parallel build options provided by GNU Make. For example, you could use the
169 .. code-block:: console
173 There are several special targets which are useful when working with the LLVM
178 Removes all files generated by the build. This includes object files,
179 generated C/C++ files, libraries, and executables.
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.
189 Installs LLVM header files, libraries, tools, and documentation in a hierarchy
190 under ``$PREFIX``, specified with ``$LLVM_SRC_DIR/configure --prefix=[dir]``, which
191 defaults to ``/usr/local``.
193 ``gmake -C runtime install-bytecode``
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
200 Please see the `Makefile Guide <MakefileGuide.html>`_ for further details on
201 these ``make`` targets and descriptions of other targets available.
203 It is also possible to override default values from ``configure`` by declaring
204 variables on the command line. The following are some examples:
206 ``gmake ENABLE_OPTIMIZED=1``
208 Perform a Release (Optimized) build.
210 ``gmake ENABLE_OPTIMIZED=1 DISABLE_ASSERTIONS=1``
212 Perform a Release (Optimized) build without assertions enabled.
214 ``gmake ENABLE_OPTIMIZED=0``
216 Perform a Debug build.
218 ``gmake ENABLE_PROFILING=1``
220 Perform a Profiling build.
224 Print what ``gmake`` is doing on standard output.
226 ``gmake TOOL_VERBOSE=1``
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``.
231 Every directory in the LLVM object tree includes a ``Makefile`` to build it and
232 any subdirectories that it contains. Entering any directory inside the LLVM
233 object tree and typing ``gmake`` should rebuild anything in or below that
234 directory that is out of date.
236 This does not apply to building the documentation.
237 LLVM's (non-Doxygen) documentation is produced with the
238 `Sphinx <http://sphinx-doc.org/>`_ documentation generation system.
239 There are some HTML documents that have not yet been converted to the new
240 system (which uses the easy-to-read and easy-to-write
241 `reStructuredText <http://sphinx-doc.org/rest.html>`_ plaintext markup
243 The generated documentation is built in the ``$LLVM_SRC_DIR/docs`` directory using
245 For instructions on how to install Sphinx, see
246 `Sphinx Introduction for LLVM Developers
247 <http://lld.llvm.org/sphinx_intro.html>`_.
248 After following the instructions there for installing Sphinx, build the LLVM
249 HTML documentation by doing the following:
251 .. code-block:: console
253 $ cd $LLVM_SRC_DIR/docs
254 $ make -f Makefile.sphinx
256 This creates a ``_build/html`` sub-directory with all of the HTML files, not
257 just the generated ones.
258 This directory corresponds to ``llvm.org/docs``.
259 For example, ``_build/html/SphinxQuickstartTemplate.html`` corresponds to
260 ``llvm.org/docs/SphinxQuickstartTemplate.html``.
261 The :doc:`SphinxQuickstartTemplate` is useful when creating a new document.
266 It is possible to cross-compile LLVM itself. That is, you can create LLVM
267 executables and libraries to be hosted on a platform different from the platform
268 where they are built (a Canadian Cross build). To configure a cross-compile,
269 supply the configure script with ``--build`` and ``--host`` options that are
270 different. The values of these options must be legal target triples that your
271 GCC compiler supports.
273 The result of such a build is executables that are not runnable on on the build
274 host (--build option) but can be executed on the compile host (--host option).
276 Check :doc:`HowToCrossCompileLLVM` and `Clang docs on how to cross-compile in general
277 <http://clang.llvm.org/docs/CrossCompilation.html>`_ for more information
278 about cross-compiling.
280 The Location of LLVM Object Files
281 ---------------------------------
283 The LLVM build system is capable of sharing a single LLVM source tree among
284 several LLVM builds. Hence, it is possible to build LLVM for several different
285 platforms or configurations using the same source tree.
287 This is accomplished in the typical autoconf manner:
289 * Change directory to where the LLVM object files should live:
291 .. code-block:: console
295 * Run the ``configure`` script found in the LLVM source directory:
297 .. code-block:: console
299 % $LLVM_SRC_DIR/configure
301 The LLVM build will place files underneath *OBJ_ROOT* in directories named after
304 Debug Builds with assertions enabled (the default)
308 ``OBJ_ROOT/Debug+Asserts/bin``
312 ``OBJ_ROOT/Debug+Asserts/lib``
318 ``OBJ_ROOT/Release/bin``
322 ``OBJ_ROOT/Release/lib``
328 ``OBJ_ROOT/Profile/bin``
332 ``OBJ_ROOT/Profile/lib``