LLVM has great documentation, but there are a couple issues with creating your own project if you're on *buntu. I hope you'll avoid the same traps I got into by following this guide!
The first thing you should do is get, configure, and build LLVM. This should be easy enough (just be sure to enable the options you need and make binaries only for your platform!). You will need to install flex, bison, and build-essential beforehand.
To create your own project, copy llvm/projects/sample to any directory you own. Copy Makefile.common, Makefile.common.in, configure, and config.status from the LLVM source root into the top of your project directory. Modify autoconf/configure.ac to your needs. Here is mine:
sudo apt-get install bison flex build-essential
Next, modify your top-level Makefile. Here is mine:
dnl Identify where LLVM source tree is
dnl Tell autoconf that the auxilliary files are actually located in
dnl the LLVM autoconf directory, not here.
dnl Tell autoconf that this is an LLVM project being configured
dnl This provides the --with-llvmsrc and --with-llvmobj options
dnl Verify that the source directory is valid
dnl Configure a common Makefile
dnl Configure project makefiles
dnl List every Makefile that exists within your source tree
Now you'll need to tweak Makefile.common. Here's mine:
LEVEL = .
DIRS = tests tools
EXTRA_DIST = include
ENABLE_OPTIMIZED = 1
DISABLE_ASSERTIONS = 1
Now you'll need to regenerate the configure scripts for your project. The script doesn't work AT ALL on Ubuntu.. so we'll hack it! First, do this:
# Set the name of the project here
PROJECT_NAME := foo
PROJ_VERSION := 0.01
# Set this variable to the top of the LLVM source tree.
LLVM_SRC_ROOT = /home/vk/Projects/llvm-2.5
# Set this variable to the top level directory where LLVM was built
# (this is *not* the same as OBJ_ROOT as defined in LLVM's Makefile.config).
LLVM_OBJ_ROOT = /home/vk/Projects/llvm-2.5
# Set the directory root of this project's source files
PROJ_SRC_ROOT := $(subst //,/,/home/vk/Projects/foo)
# Set the root directory of this project's object files
PROJ_OBJ_ROOT := $(subst //,/,@abs_top_objdir@)
# Set the root directory of this project's install prefix
PROJ_INSTALL_ROOT := /usr/local
# Include LLVM's Master Makefile.
Now, open autoconf/AutoRegen.sh with an editor (anything but emacs will do nicely). After the "die" function declaration, add this:
sudo apt-get install automake autoconf2.59
Now, delete everything after the line "cwd=`pwd`" until the line "# Patch the LLVM_ROOT in configure.ac, if it needs it". Add this in its place:
Now you can run this script.
llvm_src_root="/home/vk/Projects/llvm-2.5" # replace with wherever it is
At this point, you can lookup flags you need for the various makefiles you will have. If everything went well, you should be able to say "make" at your project root and have everything compile.
Here are some useful documents:
this guide should still apply for the svn version of llvm.