Last active
September 9, 2019 05:50
-
-
Save yen3/00361c2b8906766274bae7fd106a6ebe to your computer and use it in GitHub Desktop.
Build llvm manually
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
PREFIX=$HOME/usr/tools/llvm | |
LLVM_VERSION=7.0.0 | |
BASE_URL=https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION} | |
COMPOMENT=(llvm cfe compiler-rt libcxx libcxxabi openmp clang-tools-extra polly libunwind) | |
# Remove last build | |
rm -rf llvm | |
rm -rf build | |
# Download all files | |
for name in "${COMPOMENT[@]}"; do | |
fn="${name}-${LLVM_VERSION}.src.tar.xz" | |
[ ! -f ${fn} ] && wget ${BASE_URL}/${fn} | |
done | |
# Create folders for these projects | |
for name in "${COMPOMENT[@]}"; do | |
mkdir -p ${name} | |
done | |
# Untar these projects | |
for name in "${COMPOMENT[@]}"; do | |
fn="${name}-${LLVM_VERSION}.src.tar.xz" | |
tar xf ${fn} -C ${name} --strip-components=1 | |
done | |
# Move to destination folder | |
mv cfe llvm/tools/clang | |
mv clang-tools-extra llvm/tools/clang/tools/extra | |
mv compiler-rt llvm/projects/ | |
mv libcxx llvm/projects/ | |
mv libcxxabi llvm/projects/ | |
mv openmp llvm/projects/ | |
mv polly llvm/tools/ | |
mv libunwind llvm/runtimes/ | |
# Determine the build type | |
if hash ninja 2>/dev/null; then | |
BUILD_TYPE="NINJA" | |
else | |
BUILD_TYPE="MAKE" | |
fi | |
# Build | |
mkdir -p build | |
cd build | |
if [ x"${BUILD_TYPE}" == x"MAKE" ]; then | |
cmake ../llvm -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX=${PREFIX} | |
make -j8 | |
make install | |
else | |
cmake ../llvm -G "Ninja" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX=${PREFIX} | |
ninja | |
ninja install | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The script is still working. | |
PREFIX=${HOME}/Trek/tapir | |
WORK_DIR=$(pwd) | |
SRC_DIR=${PREFIX}/src | |
BUILD_DIR=${SRC_DIR}/build | |
TAPIR_LLVM_GIT="http://github.com/wsmoses/Tapir-LLVM.git" | |
TAPIR_LLVM_GIT_BRANCH="master" | |
CLANG_EXTRA_TOOLS_GIT="https://llvm.org/git/clang-tools-extra.git" | |
CLANG_EXTRA_TOOLS_GIT_BRANCH="release_50" | |
LIBCXX_GIT="https://llvm.org/git/libcxx.git" | |
LIBCXX_GIT_BRANCH="release_50" | |
LIBUNWIDE_GIT="https://llvm.org/git/libunwind.git" | |
LIBUNWIDE_GIT_BRANCH="release_50" | |
LLD_GIT="https://llvm.org/git/lld.git" | |
LLD_GIT_BRANCH="release_50" | |
LLDB_GIT="https://llvm.org/git/lldb.git" | |
LLDB_GIT_BRANCH="release_50" | |
LLVM_CMAKE_OPTS="" | |
# $1: variable name | |
# $2: dest folder | |
fun::clone_repo() { | |
var_name="$1" | |
dest_dir=${SRC_DIR}/$2 | |
repo_url=$(eval "echo \$${var_name}_GIT") | |
branch=$(eval "echo \$${var_name}_GIT_BRANCH") | |
echo ${repo_url} | |
echo ${branch} | |
echo ${dest_dir} | |
mkdir -p ${dest_dir} | |
cd ${WORK_DIR} | |
if [ ! -d ${dest_dir}/.git ]; then | |
git clone --recursive -b ${branch} ${repo_url} ${dest_dir} | |
else | |
cd ${dest_dir} | |
git pull | |
git submodule update --init --recursive | |
fi | |
} | |
fun::prepare_lldb_env() { | |
mkdir -p ${HOME}/Library/Preferences | |
security list-keychains -d user -s /Users/${USER}/Library/Keychains/login.keychain | |
} | |
fun::generate_llvm_cmake_opts() { | |
args="${LLVM_CMAKE_OPTS} -DCMAKE_INSTALL_PREFIX=${PREFIX} \ | |
-DCMAKE_C_FLAGS_RELEASE=-DNDEBUG \ | |
-DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG \ | |
-DLLVM_OPTIMIZED_TABLEGEN=ON \ | |
-DCMAKE_FIND_FRAMEWORK=LAST \ | |
-DCMAKE_VERBOSE_MAKEFILE=ON \ | |
-Wno-dev \ | |
-DLLVM_INCLUDE_DOCS=OFF \ | |
-DLLVM_ENABLE_RTTI=ON \ | |
-DLLVM_ENABLE_EH=ON \ | |
-DLLVM_INSTALL_UTILS=ON \ | |
-DWITH_POLLY=ON \ | |
-DLINK_POLLY_INTO_TOOLS=ON \ | |
-DLLVM_BUILD_LLVM_DYLIB=ON \ | |
-DLIBOMP_ENABLE_SHARED=ON \ | |
-DLLVM_ENABLE_ASSERTIONS=ON \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DLLVM_TARGETS_TO_BUILD=host \ | |
-DLIBOMP_ARCH=x86_64 \ | |
-DLLVM_ENABLE_LIBCXX=ON \ | |
" | |
if [ -d /usr/local/opt/libffi ]; then | |
args="${args} -DLLVM_ENABLE_FFI=ON" | |
args="${args} -DFFI_INCLUDE_DIR=/usr/local/opt/libffi/lib/libffi-3.2.1/include" | |
args="${args} -DFFI_LIBRARY_DIR=/usr/local/opt/libffi/lib" | |
fi | |
if [ -f /usr/bin/python ]; then | |
PYTHONHOME=$(/usr/bin/python-config --prefix) | |
pylib="${PYTHONHOME}/lib/libpython2.7.dylib" | |
pyinclude="${PYTHONHOME}/include/python2.7" | |
args="${args} -DLLDB_RELOCATABLE_PYTHON=ON" | |
args="${args} -DPYTHON_LIBRARY=${pylib}" | |
args="${args} -DPYTHON_INCLUDE_DIR=${pyinclude}" | |
fi | |
LLVM_CMAKE_OPTS=$(echo "$args" | python -c "import sys; print(\" \".join(sys.stdin.read().strip().split()))") | |
} | |
fun::cmake_llvm() { | |
rm -rf ${BUILD_DIR} | |
mkdir -p ${BUILD_DIR} | |
cd ${BUILD_DIR} | |
echo "cmake ${LLVM_CMAKE_OPTS} ${SRC_DIR}/llvm" | |
#cmake ${LLVM_CMAKE_OPTS} ${SRC_DIR}/llvm | |
#cmake --build . | |
#cmake --build . --target install | |
} | |
fun::build_tapir() { | |
fun::clone_repo TAPIR_LLVM llvm | |
fun::clone_repo CLANG_EXTRA_TOOLS llvm/tools/clang/tools/extra/ | |
fun::clone_repo LIBCXX llvm/projects/libcxx | |
fun::clone_repo LIBUNWIDE llvm/projects/libunwide | |
fun::clone_repo LLD llvm/tools/lld | |
fun::clone_repo LLDB llvm/tools/lldb | |
fun::prepare_lldb_env | |
fun::generate_llvm_cmake_opts | |
fun::cmake_llvm | |
} | |
func::build_cilkrt() { | |
echo "hello world" | |
} | |
fun::build_tapir | |
fun::build_cilkrt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment