blob: 40c42e22a13cedc52949bd6fd1e3bea384c687a6 [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
14CPUs=`grep -c proc /proc/cpuinfo`
15build_dir=$LLVM_BLD
16install_dir=$LLVM_BLD/../../install
17build_type=Release
18shared=
19targets=
20prog=`basename $0`
Diana Picusc581e192016-05-27 12:56:06 +030021syntax="Syntax: $prog [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 \
62 $targets $shared
63fi
64
65## Build
Diana Picusc581e192016-05-27 12:56:06 +030066if [ "$1" == "" ]; then
67 echo " + Building LLVM"
68 safe_run $make -j$CPUs
69else
70 for target in "$@"; do
71 echo " + Running $target"
72 safe_run $make -j$CPUs $target
73 done
Renato Golin94cc1042016-04-26 11:02:23 +010074fi
75