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