Skip to content

Instantly share code, notes, and snippets.

@sixman9
Last active December 3, 2022 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sixman9/4141919 to your computer and use it in GitHub Desktop.
Save sixman9/4141919 to your computer and use it in GitHub Desktop.
Bash script to download and build LLVM and Clang
#!/bin/bash
# install-llvm.sh
# Copyright (c) 2010 Ben Karel. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE.txt file or at http://eschew.org/txt/bsd.txt
# This file was found at http://foster.googlecode.com/hg/scripts and updated by Richard Joseph, Nov 2012
#The current LLVM and CLANG version can be found at http://llvm.org/releases/download.html
LLVM_VERSION=3.4
LLVM_ROOT=${HOME}/llvm
#Resolve LLVM archive naming convention
if [ `echo "$LLVM_VERSION >= 3.0" | bc` ]; then
downloadSrcSuffixPart=src
tarGzipSuffix="tar.gz"
LLVM_VERSION_PLUS_SRC_SUFFIX_PART="${LLVM_VERSION}.${downloadSrcSuffixPart}"
else
downloadSrcSuffixPart=
tarGzipSuffix="targz"
LLVM_VERSION_PLUS_SRC_SUFFIX_PART="${LLVM_VERSION}"
fi
# invoke from LLVM_ROOT
download_source() {
pushd ${LLVM_ROOT}/src
echo "downloading llvm..."
wget http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION_PLUS_SRC_SUFFIX_PART}."${tarGzipSuffix}"
echo "downloading clang..."
wget http://llvm.org/releases/${LLVM_VERSION}/clang-${LLVM_VERSION_PLUS_SRC_SUFFIX_PART}."${tarGzipSuffix}"
for tarball in *."${tarGzipSuffix}"; do
echo "extracting $tarball..."
tar xzf $tarball
done
rm *."${tarGzipSuffix}"
mv clang-${LLVM_VERSION_PLUS_SRC_SUFFIX_PART} llvm-${LLVM_VERSION_PLUS_SRC_SUFFIX_PART}/tools/clang
popd
}
# invoke from LLVM_ROOT
build_source () {
pushd ${LLVM_ROOT}/src/llvm-${LLVM_VERSION_PLUS_SRC_SUFFIX_PART}
./configure --prefix=${LLVM_ROOT}/${LLVM_VERSION} --enable-targets=host,cpp --enable-debug-symbols --enable-assertions --enable-optimized
make
make install
popd
}
mkdir -p ${LLVM_ROOT}
pushd ${LLVM_ROOT}
mkdir -p src
mkdir -p ${LLVM_VERSION}
download_source
build_source
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment