blob: 8d2fab4ffe261c0ef2783b5686c60a10e89aee62 [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/usr/bin/env bash
2
3# This script helps you build LLVM. It can update the repositories first,
4# run the check-all after and even install it in your system. Since the
5# LLVM tree changes constantly, it's recommended that you run this script
6# with update+check at least once a week, and most importantly, before you
7# begin a big change, to make sure the repos are current and stable.
8
9. llvm-common
10
11## CMD line options and defaults
12CPUs=`grep -c proc /proc/cpuinfo`
13build_dir=$LLVM_BLD
14install_dir=$LLVM_BLD/../../install
15build_type=Release
16shared=
17targets=
18prog=`basename $0`
19syntax="Syntax: $prog [-u(pdate)] [-c(check-all)] [-i(nstall)] [-d(debug)]"
20update=false
21check=false
22master=false
23debug=false
24inst=false
25while getopts "ucimd" opt; do
26 case $opt in
27 u)
28 update=true
29 ;;
30 c)
31 check=true
32 ;;
33 i)
34 inst=true
35 ;;
36 m)
37 master=true
38 ;;
39 d)
40 debug=true
41 build_dir=$LLVM_BLD/../debug
42 ;;
43 *)
44 echo $syntax
45 exit 1
46 ;;
47 esac
48done
49
50## Run llvm-sync before
51if $update; then
52 echo " + Updating Repositories"
53 safe_run llvm-sync -a
54fi
55
56## Make sure all branches are on master
57if $master; then
58 echo " + Checking out master"
59 safe_run llvm-branch master
60fi
61
62## Choose between make and ninja
63make=make
64ninja=
65if which ninja 2>&1 > /dev/null; then
66 make=ninja
67 ninja="-G Ninja"
68fi
69
70## Debug mode, make it lighter
71if $debug; then
72 build_type=Debug
73 shared=-DBUILD_SHARED_LIBS=True
74 targets=-DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64"
75fi
76
77## Make sure sure build dir is there
78if [ ! -d $build_dir ]; then
79 mkdir -p $builddir
80fi
81cd $build_dir
82
83## Re-run CMake file files are damaged / not there
84if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
85 echo " + Configuring Build"
86 safe_run cmake $ninja $LLVM_SRC \
87 -DCMAKE_BUILD_TYPE=$build_type \
88 -DLLVM_BUILD_TESTS=True \
89 -DLLVM_ENABLE_ASSERTIONS=True \
90 -DPYTHON_EXECUTABLE=/usr/bin/python2 \
91 -DCMAKE_INSTALL_PREFIX=$install_dir \
92 $targets $shared
93fi
94
95## Build
96echo " + Building LLVM"
97safe_run $make -j$CPUs
98
99## Check
100if $check; then
101 echo " + Running Tests"
102 safe_run $make check-all
103fi
104
105## Install
106if $inst; then
107 echo " + Installing on the System"
108 safe_run $make install
109fi