This script installs self-contained standalone 8.0 versions of clang,
LLVM, libc++, compiler-rt, libc++abi, lldb,
and lld, on macOS and Linux, including linking clang and LLVM
against libc++ themselves as well. The script keeps all of the
installation within a given target prefix (e.g.,
hence separate from any already installed compilers, libraries, and
include files. In particular, you can later uninstall everything
easily by just deleting, e.g.,
/opt/llvm. Furthermore, as long as
the prefix path is writable, the installation doesn't need root
If you have used older version of this script before, see News below for changes.
To see the available options, use
> ./install-clang -h Usage: install-clang [<options>] <install-prefix> Available options: -A enables assertions in LLVM libraries -b build type (Release, Debug, RelWithDebInfo) [default: RelWithDebInfo] -c skip cloning repositories, assume they are in place -h|-? display this help -j <n> build with <n> threads in parallel [default: 1] -m use git/master instead of preconfigured versions -s <stage> begin build from <stage> [0, 1, 2] -u update an existing build in <prefix> instead of installing new Environment variables: CC path to the C compiler for bootstrapping CXX path to the C++ compiler for bootstrapping
For example, to build Clang on a machine with multiple cores and
install it in
/opt/llvm, you can use:
> ./install-clang -j 16 /opt/llvm
Once finished, just prefix your PATH with
<prefix>/bin and you're
ready to use the new binaries:
> clang++ --std=c++11 --stdlib=libc++ test.cc -o a.out && ./a.out Hello, Clang!
By default, install-clang currently installs the 8.0 release branches
of the relevant llvm.org projects. Adding
-m on the command line
instructs the script to use the current git master versions instead.
The script downloads all the sources from the corresponding git
repositories and compiles the pieces as needed. Other OSs than macOS,
and Linux are not currently supported.
The script also has an update option
-u that allows for catching up
with upstream repository changes without doing the complete
compile/install-from-scratch cycle again. Note, however, that unless
-m, this flag has no immediate effect since the git
versions to use are hardcoded to the Clang/LLVM release versions.
Doing a self-contained Clang installation is a bit more messy than one would hope because the projects make assumptions about specific system-wide installation paths to use. The install-clang script captures some trial-and-error I (and others) went through to get an independent setup working. It compiles Clang up to three times, bootstrapping things with the system compiler as it goes. It also patches some of the Clang/LLVM projects to incorporate the installation prefix into configuration and search paths, and also fixes/tweaks a few other things as well.
install-clang comes with a Dockerfile to build a Docker image, based on Ubuntu, with Clang then in /opt/llvm:
# make docker-build && make docker-run [... get a beer ...] root@f39b941f177c:/# clang --version clang version 8.0.0 Target: x86_64--linux-gnu Thread model: posix root@f39b941f177c:/# which clang /opt/clang/bin/clang
A prebuilt image is available at https://hub.docker.com/r/rsmmr/clang/ .
Version for Clang 8.0 (git
The install-clang script for Clang 8.0 comes with these changes compared to the 6.0 version:
Fix computed RPATH when the clang binary has been symlinked from elsehwere (#18).
We now honor preset environment variables CFLAGS, CXXFLAGS, and LDFLAGS to find dependencies.
On macOS, we now set clang's DEFAULT_SYSROOT to the current macOS SDK.
We apply a custom clang-format patch that adds a couple of custom formatting options.
Removed any customziation for FreeBSD; support had been untested in a long time.
Version for Clang 6.0 (git tag
The install-clang script for Clang 6.0 comes with these changes compared to the 3.5 version:
The default build type is now
Release. It used to be
lldb and lld seem to built correctly on both Linux and Darwin now and both are enabled by default.
FreeBSD support is untested and hence disabled for now. Will be reactivated once confirmed that it's working.
On macOS, we no longer build for i386.
The Docker image is now based on Ubuntu Xenial and puts everything into
Version for Clang 3.5 (git tag
The install-clang script for Clang 3.5 comes with a few changes compared to earlier version:
The script now supports FreeBSD as well. (Contributed by Matthias Vallentin).
The script now generally shared libraries for LLVM and clang, rather than static ones.
As libc++abi now works well on Linux as well, we use it generally and no longer support libcxxrt.
There are now command line options to select build mode and assertions explicitly.
There's no 3rd phase anymore building assertion-enabled LLVM libraries, as changing compilation options isn't useful with shared libraries.
In return, there's a phase 0 now if the system compiler isn't a clang; libc++abi needs clang that for its initial compilation already.
There's now a Dockerfile to build an image with Clang/LLVM in /opt/llvm.