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:
There are two ways that you can set all of these variables:
This document assumes that you will base your project off of 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:
% cd autoconf
% autoconf -o ../configure
You must be using Autoconf version 2.57 or higher.
That's it! Now all you have to do is type gmake 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:
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.
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".
Currently, the LLVM build system provides little support for tests, although some exists. Expanded support for tests will hopefully occur in the future. In the meantime, the LLVM system does provide the following:
Currently, there is no way to hook your tests directly into the llvm/test/Programs 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:
Note that this works only for statically linked libraries.
For example, to link libsample.so, you would have the following line in your Makefile:
LIBS += -lsample
It is highly suggested that you append to CFLAGS and CPPFLAGS as opposed to overwriting them. The master Makefiles may already have useful options in them that you may not want to overwrite.
The final location of built libraries and executables will depend upon whether you do a Debug, Release, or Profile build.
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.