The LLVM build system is designed to facilitate the building of third party
projects that use LLVM header files, libraries, and tools. In order to use
these facilities, a Makefile from a project must do the following things:
- Set make variables. There are several variables that a Makefile
needs to set to use the LLVM build system:
- PROJECT_NAME - The name by which your project is known.
- LLVM_SRC_ROOT - The root of the LLVM source tree.
- LLVM_OBJ_ROOT - The root of the LLVM object tree.
- PROJ_SRC_ROOT - The root of the project's source tree.
- PROJ_OBJ_ROOT - The root of the project's object tree.
- PROJ_INSTALL_ROOT - The root installation directory.
- LEVEL - The relative path from the current directory to the
project's root ($PROJ_OBJ_ROOT).
- Include Makefile.config from $(LLVM_OBJ_ROOT).
- Include Makefile.rules from $(LLVM_SRC_ROOT).
There are two ways that you can set all of these variables:
- You can write your own Makefiles which hard-code these values.
- You can use the pre-made LLVM sample project. This sample project
includes Makefiles, a configure script that can be used to configure the
location of LLVM, and the ability to support multiple object directories
from a single source directory.
This document assumes that you will base your project on the LLVM sample
project found in llvm/projects/sample. If you want to devise your own
build system, studying the sample project and LLVM Makefiles will probably
provide enough information on how to write your own Makefiles.
Follow these simple steps to start your project:
- Copy the llvm/projects/sample directory to any place of your
choosing. You can place it anywhere you like. Rename the directory to match
the name of your project.
-
If you downloaded LLVM using CVS, remove all the directories named CVS (and all
the files therein) from your project's new source tree. This will keep CVS
from thinking that your project is inside llvm/projects/sample.
- Add your source code and Makefiles to your source tree.
- If you want your project to be configured with the configure script
then you need to edit autoconf/configure.ac as follows:
- AC_INIT. Place the name of your project, its version number and
a contact email address for your project as the arguments to this macro
- AC_CONFIG_AUX_DIR. If your project isn't in the
llvm/projects directory then you might need to adjust this so that
it specifies a relative path to the llvm/autoconf directory.
- LLVM_CONFIG_PROJECT. Just leave this alone.
- AC_CONFIG_SRCDIR. Specify a path to a file name that identifies
your project; or just leave it at Makefile.common.in
- AC_CONFIG_FILES. Do not change.
- AC_CONFIG_MAKEFILE. Use one of these macros for each Makefile
that your project uses. This macro arranges for your makefiles to be copied
from the source directory, unmodified, to the build directory.
- After updating autoconf/configure.ac, regenerate the
configure script with these commands:
% cd autoconf
% AutoRegen.sh
You must be using Autoconf version 2.59 or later and your aclocal version
should 1.9 or later.
- Run configure in the directory in which you want to place
object code. Use the following options to tell your project where it
can find LLVM:
- --with-llvmsrc=<directory>
- Tell your project where the LLVM source tree is located.
--with-llvmobj=<directory>
- Tell your project where the LLVM object tree is located.
--prefix=<directory>
- Tell your project where it should get installed.
That's it! Now all you have to do is type gmake (or make
if your on a GNU/Linux system) in the root of your object directory, and your
project should build.
In order to use the LLVM build system, you will want to organize your
source code so that it can benefit from the build system's features.
Mainly, you want your source tree layout to look similar to the LLVM
source tree layout. The best way to do this is to just copy the
project tree from llvm/projects/sample and modify it to meet
your needs, but you can certainly add to it if you want.
Underneath your top level directory, you should have the following
directories:
- lib
-
This subdirectory should contain all of your library source
code. For each library that you build, you will have one
directory in lib that will contain that library's source
code.
Libraries can be object files, archives, or dynamic libraries.
The lib directory is just a convenient place for libraries
as it places them all in a directory from which they can be linked
later.
- include
-
This subdirectory should contain any header files that are
global to your project. By global, we mean that they are used
by more than one library or executable of your project.
By placing your header files in include, they will be
found automatically by the LLVM build system. For example, if
you have a file include/jazz/note.h, then your source
files can include it simply with #include "jazz/note.h".
- tools
-
This subdirectory should contain all of your source
code for executables. For each program that you build, you
will have one directory in tools that will contain that
program's source code.
- test
-
This subdirectory should contain tests that verify that your code
works correctly. Automated tests are especially useful.
Currently, the LLVM build system provides basic support for tests.
The LLVM system provides the following:
-
LLVM provides a tcl procedure that is used by Dejagnu to run
tests. It can be found in llvm/lib/llvm-dg.exp. This
test procedure uses RUN lines in the actual test case to determine
how to run the test. See the TestingGuide for more details. You
can easily write Makefile support similar to the Makefiles in
llvm/test to use Dejagnu to run your project's tests.
-
LLVM contains an optional package called llvm-test
which provides benchmarks and programs that are known to compile with the
LLVM GCC front ends. You can use these
programs to test your code, gather statistics information, and
compare it to the current LLVM performance statistics.
Currently, there is no way to hook your tests directly into the
llvm/test testing harness. You will simply
need to find a way to use the source provided within that directory
on your own.
Typically, you will want to build your lib directory first followed by
your tools directory.
The LLVM build system provides a convenient way to build libraries and
executables. Most of your project Makefiles will only need to define a few
variables. Below is a list of the variables one can set and what they can
do:
The final location of built libraries and executables will depend upon
whether you do a Debug, Release, or Profile build.
- Libraries
-
All libraries (static and dynamic) will be stored in
PROJ_OBJ_ROOT/<type>/lib, where type is Debug,
Release, or Profile for a debug, optimized, or
profiled build, respectively.
- Executables
- All executables will be stored in
PROJ_OBJ_ROOT/<type>/bin, where type is Debug,
Release, or Profile for a debug, optimized, or profiled
build, respectively.
If you have any questions or need any help creating an LLVM project,
the LLVM team would be more than happy to help. You can always post your
questions to the LLVM Developers
Mailing List.