blob: 0556b6ed712a5b98a4bb1e0428dd99def277cf61 [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
Renato Golin250b7aa2016-09-17 18:22:38 +010014CPUS=$(grep -c proc /proc/cpuinfo)
15PARALLEL=-j$CPUS
Renato Golin94cc1042016-04-26 11:02:23 +010016build_dir=$LLVM_BLD
Diana Picusb2a87862016-07-20 17:14:00 +030017install_dir=$LLVM_INSTALL
Renato Golin94cc1042016-04-26 11:02:23 +010018build_type=Release
19shared=
20targets=
21prog=`basename $0`
Diana Picus87d06322016-07-22 11:52:31 +030022syntax="Syntax: $prog [-jN] [targets]"
Renato Golin94cc1042016-04-26 11:02:23 +010023update=false
24check=false
25master=false
Renato Golin94cc1042016-04-26 11:02:23 +010026inst=false
Renato Golin250b7aa2016-09-17 18:22:38 +010027minimal_targets="-DLLVM_TARGETS_TO_BUILD='ARM;X86;AArch64'"
28link_jobs=
Renato Golin94cc1042016-04-26 11:02:23 +010029
Diana Picusc581e192016-05-27 12:56:06 +030030if [ "$1" = "-h" ]; then
31 echo $syntax
32 exit 0
Renato Golin94cc1042016-04-26 11:02:23 +010033fi
34
35## Choose between make and ninja
36make=make
Diana Picus416bc4f2016-04-22 16:47:57 +030037generator="Unix Makefiles"
Renato Golin250b7aa2016-09-17 18:22:38 +010038if which ninja > /dev/null 2>&1; then
Renato Golin94cc1042016-04-26 11:02:23 +010039 make=ninja
Diana Picus416bc4f2016-04-22 16:47:57 +030040 generator="Ninja"
Renato Golin94cc1042016-04-26 11:02:23 +010041fi
42
43## Debug mode, make it lighter
Diana Picus72189fd2016-05-23 19:32:46 +030044if [ "$LLVM_DEBUG" = true ]; then
Renato Golin94cc1042016-04-26 11:02:23 +010045 build_type=Debug
46 shared=-DBUILD_SHARED_LIBS=True
Renato Golin250b7aa2016-09-17 18:22:38 +010047 targets=$minimal_targets
48fi
49
50# Building on ARM?
51if grep -q "ARM.* Processor" /proc/cpuinfo; then
52 targets=$minimal_targets
53 if [ "$make" = "ninja" ]; then
54 link=$(free -g | awk '/Mem/ {print $2}')
55 if [ "$link" -gt "$CPUS" ]; then
56 link=$CPUS
57 else
58 link=$((link+1))
59 fi
60 link_jobs="-DLLVM_PARALLEL_LINK_JOBS=$link"
61 fi
Renato Golin94cc1042016-04-26 11:02:23 +010062fi
63
64## Make sure sure build dir is there
65if [ ! -d $build_dir ]; then
Diana Picus5a10ae12016-04-27 18:29:38 +030066 safe_run mkdir -p $build_dir
Renato Golin94cc1042016-04-26 11:02:23 +010067fi
68cd $build_dir
69
Diana Picus0df00012016-09-15 16:10:44 +030070## Allow the user to override the number of CPUs used with -jN
71if [[ $1 =~ -j[0-9]+ ]]; then
72 PARALLEL=$1
73 shift
74fi
75
Diana Picusc581e192016-05-27 12:56:06 +030076## Re-run CMake if files are damaged / not there
Renato Golin94cc1042016-04-26 11:02:23 +010077if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
78 echo " + Configuring Build"
Diana Picus416bc4f2016-04-22 16:47:57 +030079 safe_run cmake -G "$generator" $LLVM_SRC \
Renato Golin94cc1042016-04-26 11:02:23 +010080 -DCMAKE_BUILD_TYPE=$build_type \
81 -DLLVM_BUILD_TESTS=True \
82 -DLLVM_ENABLE_ASSERTIONS=True \
83 -DPYTHON_EXECUTABLE=/usr/bin/python2 \
84 -DCMAKE_INSTALL_PREFIX=$install_dir \
Renato Golin250b7aa2016-09-17 18:22:38 +010085 -DLLVM_LIT_ARGS="-sv $PARALLEL" \
86 $LLVM_CMAKE_FLAGS $targets $shared $link_jobs
Renato Golin94cc1042016-04-26 11:02:23 +010087fi
88
89## Build
Diana Picusc581e192016-05-27 12:56:06 +030090if [ "$1" == "" ]; then
91 echo " + Building LLVM"
Diana Picus87d06322016-07-22 11:52:31 +030092 safe_run $make $PARALLEL
Diana Picusc581e192016-05-27 12:56:06 +030093else
94 for target in "$@"; do
95 echo " + Running $target"
Diana Picus87d06322016-07-22 11:52:31 +030096 safe_run $make $PARALLEL $target
Diana Picusc581e192016-05-27 12:56:06 +030097 done
Renato Golin94cc1042016-04-26 11:02:23 +010098fi
99