blob: d38cf1da62182bddac3e33af72fd4fd4b0c63cf9 [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
Diana Picus72189fd2016-05-23 19:32:46 +030011safe_run verify_env
12
Renato Golin94cc1042016-04-26 11:02:23 +010013## CMD line options and defaults
Diana Picus87d06322016-07-22 11:52:31 +030014PARALLEL=-j`grep -c proc /proc/cpuinfo`
Renato Golin94cc1042016-04-26 11:02:23 +010015build_dir=$LLVM_BLD
Diana Picusb2a87862016-07-20 17:14:00 +030016install_dir=$LLVM_INSTALL
Renato Golin94cc1042016-04-26 11:02:23 +010017build_type=Release
18shared=
19targets=
20prog=`basename $0`
Diana Picus87d06322016-07-22 11:52:31 +030021syntax="Syntax: $prog [-jN] [targets]"
Renato Golin94cc1042016-04-26 11:02:23 +010022update=false
23check=false
24master=false
Renato Golin94cc1042016-04-26 11:02:23 +010025inst=false
Renato Golin94cc1042016-04-26 11:02:23 +010026
Diana Picusc581e192016-05-27 12:56:06 +030027if [ "$1" = "-h" ]; then
28 echo $syntax
29 exit 0
Renato Golin94cc1042016-04-26 11:02:23 +010030fi
31
32## Choose between make and ninja
33make=make
Diana Picus416bc4f2016-04-22 16:47:57 +030034generator="Unix Makefiles"
Renato Golin94cc1042016-04-26 11:02:23 +010035if which ninja 2>&1 > /dev/null; then
36 make=ninja
Diana Picus416bc4f2016-04-22 16:47:57 +030037 generator="Ninja"
Renato Golin94cc1042016-04-26 11:02:23 +010038fi
39
40## Debug mode, make it lighter
Diana Picus72189fd2016-05-23 19:32:46 +030041if [ "$LLVM_DEBUG" = true ]; then
Renato Golin94cc1042016-04-26 11:02:23 +010042 build_type=Debug
43 shared=-DBUILD_SHARED_LIBS=True
44 targets=-DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64"
45fi
46
47## Make sure sure build dir is there
48if [ ! -d $build_dir ]; then
Diana Picus5a10ae12016-04-27 18:29:38 +030049 safe_run mkdir -p $build_dir
Renato Golin94cc1042016-04-26 11:02:23 +010050fi
51cd $build_dir
52
Diana Picusc581e192016-05-27 12:56:06 +030053## Re-run CMake if files are damaged / not there
Renato Golin94cc1042016-04-26 11:02:23 +010054if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
55 echo " + Configuring Build"
Diana Picus416bc4f2016-04-22 16:47:57 +030056 safe_run cmake -G "$generator" $LLVM_SRC \
Renato Golin94cc1042016-04-26 11:02:23 +010057 -DCMAKE_BUILD_TYPE=$build_type \
58 -DLLVM_BUILD_TESTS=True \
59 -DLLVM_ENABLE_ASSERTIONS=True \
60 -DPYTHON_EXECUTABLE=/usr/bin/python2 \
61 -DCMAKE_INSTALL_PREFIX=$install_dir \
Renato Golindb4c6a12016-08-01 17:03:26 +010062 $LLVM_CMAKE_FLAGS $targets $shared
Renato Golin94cc1042016-04-26 11:02:23 +010063fi
64
Diana Picus87d06322016-07-22 11:52:31 +030065## Allow the user to override the number of CPUs used with -jN
66if [[ $1 =~ -j[0-9]+ ]]; then
67 PARALLEL=$1
68 shift
69fi
70
Renato Golin94cc1042016-04-26 11:02:23 +010071## Build
Diana Picusc581e192016-05-27 12:56:06 +030072if [ "$1" == "" ]; then
73 echo " + Building LLVM"
Diana Picus87d06322016-07-22 11:52:31 +030074 safe_run $make $PARALLEL
Diana Picusc581e192016-05-27 12:56:06 +030075else
76 for target in "$@"; do
77 echo " + Running $target"
Diana Picus87d06322016-07-22 11:52:31 +030078 safe_run $make $PARALLEL $target
Diana Picusc581e192016-05-27 12:56:06 +030079 done
Renato Golin94cc1042016-04-26 11:02:23 +010080fi
81