aboutsummaryrefslogtreecommitdiff
path: root/helpers/llvm-build
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/llvm-build')
-rwxr-xr-xhelpers/llvm-build109
1 files changed, 109 insertions, 0 deletions
diff --git a/helpers/llvm-build b/helpers/llvm-build
new file mode 100755
index 0000000..8d2fab4
--- /dev/null
+++ b/helpers/llvm-build
@@ -0,0 +1,109 @@
+#!/usr/bin/env bash
+
+# This script helps you build LLVM. It can update the repositories first,
+# run the check-all after and even install it in your system. Since the
+# LLVM tree changes constantly, it's recommended that you run this script
+# with update+check at least once a week, and most importantly, before you
+# begin a big change, to make sure the repos are current and stable.
+
+. llvm-common
+
+## CMD line options and defaults
+CPUs=`grep -c proc /proc/cpuinfo`
+build_dir=$LLVM_BLD
+install_dir=$LLVM_BLD/../../install
+build_type=Release
+shared=
+targets=
+prog=`basename $0`
+syntax="Syntax: $prog [-u(pdate)] [-c(check-all)] [-i(nstall)] [-d(debug)]"
+update=false
+check=false
+master=false
+debug=false
+inst=false
+while getopts "ucimd" opt; do
+ case $opt in
+ u)
+ update=true
+ ;;
+ c)
+ check=true
+ ;;
+ i)
+ inst=true
+ ;;
+ m)
+ master=true
+ ;;
+ d)
+ debug=true
+ build_dir=$LLVM_BLD/../debug
+ ;;
+ *)
+ echo $syntax
+ exit 1
+ ;;
+ esac
+done
+
+## Run llvm-sync before
+if $update; then
+ echo " + Updating Repositories"
+ safe_run llvm-sync -a
+fi
+
+## Make sure all branches are on master
+if $master; then
+ echo " + Checking out master"
+ safe_run llvm-branch master
+fi
+
+## Choose between make and ninja
+make=make
+ninja=
+if which ninja 2>&1 > /dev/null; then
+ make=ninja
+ ninja="-G Ninja"
+fi
+
+## Debug mode, make it lighter
+if $debug; then
+ build_type=Debug
+ shared=-DBUILD_SHARED_LIBS=True
+ targets=-DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64"
+fi
+
+## Make sure sure build dir is there
+if [ ! -d $build_dir ]; then
+ mkdir -p $builddir
+fi
+cd $build_dir
+
+## Re-run CMake file files are damaged / not there
+if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
+ echo " + Configuring Build"
+ safe_run cmake $ninja $LLVM_SRC \
+ -DCMAKE_BUILD_TYPE=$build_type \
+ -DLLVM_BUILD_TESTS=True \
+ -DLLVM_ENABLE_ASSERTIONS=True \
+ -DPYTHON_EXECUTABLE=/usr/bin/python2 \
+ -DCMAKE_INSTALL_PREFIX=$install_dir \
+ $targets $shared
+fi
+
+## Build
+echo " + Building LLVM"
+safe_run $make -j$CPUs
+
+## Check
+if $check; then
+ echo " + Running Tests"
+ safe_run $make check-all
+fi
+
+## Install
+if $inst; then
+ echo " + Installing on the System"
+ safe_run $make install
+fi