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.
sudo apt-get install bison flex build-essential
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:
Code:
# <snip>
AC_INIT([FOO_PROJECT],[0.01],[obfuscated@gmail.com])
dnl Identify where LLVM source tree is
LLVM_SRC_ROOT="/home/vk/Projects/llvm-2.5"
LLVM_OBJ_ROOT="/home/vk/Projects/llvm-2.5"
dnl Tell autoconf that the auxilliary files are actually located in
dnl the LLVM autoconf directory, not here.
AC_CONFIG_AUX_DIR($LLVM_SRC_ROOT/autoconf)
dnl Tell autoconf that this is an LLVM project being configured
dnl This provides the --with-llvmsrc and --with-llvmobj options
LLVM_CONFIG_PROJECT($LLVM_SRC_ROOT,$LLVM_OBJ_ROOT)
dnl Verify that the source directory is valid
AC_CONFIG_SRCDIR(["Makefile.common.in"])
dnl Configure a common Makefile
AC_CONFIG_FILES(Makefile.common)
dnl Configure project makefiles
dnl List every Makefile that exists within your source tree
AC_CONFIG_MAKEFILE(Makefile)
AC_CONFIG_MAKEFILE(tools/Makefile)
AC_CONFIG_MAKEFILE(tools/fookl/Makefile)
AC_CONFIG_MAKEFILE(tests/Makefile)
# <snip>
Next, modify your top-level Makefile. Here is mine:
Code:
LEVEL = .
DIRS = tests tools
EXTRA_DIST = include
# flags
ENABLE_OPTIMIZED = 1
DISABLE_ASSERTIONS = 1
include $(LEVEL)/Makefile.common
Now you'll need to tweak Makefile.common. Here's mine:
Code:
# 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.
include $(LLVM_OBJ_ROOT)/Makefile.common
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:
sudo apt-get install automake autoconf2.59
Now, open autoconf/AutoRegen.sh with an editor (anything but emacs will do nicely). After the "die" function declaration, add this:
Code:
alias autoconf='autoconf2.59'
alias aclocal='aclocal-1.9'
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:
Code:
llvm_src_root="/home/vk/Projects/llvm-2.5" # replace with wherever it is
llvm_m4="$llvm_src_root/autoconf/m4"
llvm_obj_root=$llvm_src_root
Now you can run this script.
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:
1) http://llvm.org/docs/MakefileGuide.html
2) http://llvm.org/docs/Projects.html
3) http://llvm.org/docs/GettingStarted.html
edit:
this guide should still apply for the svn version of llvm.
Bookmarks