Skip to content

Instantly share code, notes, and snippets.

@tuoxie007
Last active January 2, 2018 03:41
Show Gist options
  • Save tuoxie007/3bf2e50bf1e4281b2239b627e944ae5a to your computer and use it in GitHub Desktop.
Save tuoxie007/3bf2e50bf1e4281b2239b627e944ae5a to your computer and use it in GitHub Desktop.
#!/bin/bash
BRANCH=release_50
ROOT=`pwd`
SRC=$ROOT/llvm
# GIT_BASE_URL=https://llvm.org/git
if [[ "$GIT_BASE_URL" == "" ]]; then
GIT_BASE_URL=https://github.com/llvm-mirror
fi
BUILDER=ninja
BUILD=$ROOT/build-$BUILDER
INSTALL=$ROOT/install-$BUILDER
UPGRADE_BRANCH=ON
ONLY_CONFIG=OFF
submodules=""
function add_submodule
{
submodules="${submodules}|$1"
}
add_submodule clang
add_submodule clang-tools-extra
if [[ $SUB_MODULES ]]; then
add_submodule $SUB_MODULES
fi
# add_submodule lldb
# add_submodule lld
# add_submodule polly
# add_submodule compiler-rt
# add_submodule libcxx
# add_submodule libcxxabi
# add_submodule test-suite
function pkg_install
{
if [[ `type $1 >/dev/null 2>&1` ]]; then
if [[ "`uname`" == "Darwin" ]]; then
brew install $1
else
if [[ $2 ]]; then
apt install -y $2
else
apt install -y $1
fi
fi
else
echo "checking $1... OK"
fi
}
pkg_install make
pkg_install cmake
pkg_install llvm
pkg_install libxml2-dev
pkg_install libncurses-dev
pkg_install doxygen
pkg_install swig
pkg_install python-dev
if [[ "${BUILDER}" == "ninja" ]]; then
pkg_install ninja, ninja-build
fi
if [[ "${SOURCE}" == "git" ]]; then
pkg_install git
fi
function fetch {
proj=$1
dir=$proj
if [[ $# > 1 ]]; then
dir=$2
fi
if [[ "${submodules}" == *"|$proj"* ]]; then
if [ -d $dir ]; then
pushd $dir
if [[ "${UPGRADE_BRANCH}" == "ON" ]]; then
git reset --hard
git pull
fi
popd
else
git clone ${GIT_BASE_URL}/$proj $dir
fi
pushd $dir
if [[ "${BRANCH}" != "" ]]; then
git checkout $BRANCH
fi
popd
elif [[ "$proj" != "llvm" ]]; then
rm -rf $dir
fi
}
fetch llvm
pushd llvm # /llvm
fetch clang tools/clang
fetch clang-tools-extra tools/clang/tools/extra
fetch lldb tools/lldb
fetch lld tools/lld
fetch polly tools/polly
fetch compiler-rt projects/compiler-rt
fetch libcxx projects/libcxx
fetch libcxxabi projects/libcxxabi
fetch test-suite projects/test-suite
popd # /
mkdir -p $BUILD
cd $BUILD
rm -f CMakeCache.txt # cleanup
if [[ "${BUILDER}" == "ninja" ]]; then
BUILDER_G=Ninja
elif [[ "${BUILDER}" == "make" ]]; then
BUILDER_G="Unix Makefiles"
elif [[ "${BUILDER}" == "xcode" ]]; then
BUILDER_G="Xcode"
fi
cmake -G ${BUILDER_G} ${SRC} \
-DCMAKE_INSTALL_PREFIX="${INSTALL}" \
-DLLVM_TARGETS_TO_BUILD="ARM;X86" \
-DCMAKE_BUILD_TYPE="Release" \
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
# -DLLVM_PARALLEL_COMPILE_JOBS=4 \
# -DLLVM_PARALLEL_LINK_JOBS=4 \
# -DCMAKE_BUILD_TYPE="Debug" \
# -DCMAKE_C_COMPILER=clang \
# -DCMAKE_CXX_COMPILER=clang++ \
# -DCMAKE_ASM_COMPILER=clang \
# -DLLVM_ENABLE_PIC=OFF \
if [[ "${ONLY_CONFIG}" == "ON" ]]; then
exit
fi
if [[ "${BUILDER}" == "ninja" ]]; then
ninja && ninja install
fi
if [[ "${BUILDER}" == "make" ]]; then
make && make install
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment