blob: f638c75534e54c7da201c2cf7f086d174f03e57f [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=
Renato Golin767231c2016-10-19 23:46:37 +010021dwarf=
Renato Golin94cc1042016-04-26 11:02:23 +010022prog=`basename $0`
Diana Picus87d06322016-07-22 11:52:31 +030023syntax="Syntax: $prog [-jN] [targets]"
Renato Golin94cc1042016-04-26 11:02:23 +010024update=false
25check=false
26master=false
Renato Golin94cc1042016-04-26 11:02:23 +010027inst=false
Renato Golin250b7aa2016-09-17 18:22:38 +010028minimal_targets="-DLLVM_TARGETS_TO_BUILD='ARM;X86;AArch64'"
29link_jobs=
Renato Golin94cc1042016-04-26 11:02:23 +010030
Diana Picusc581e192016-05-27 12:56:06 +030031if [ "$1" = "-h" ]; then
32 echo $syntax
33 exit 0
Renato Golin94cc1042016-04-26 11:02:23 +010034fi
35
36## Choose between make and ninja
37make=make
Diana Picus416bc4f2016-04-22 16:47:57 +030038generator="Unix Makefiles"
Renato Golin250b7aa2016-09-17 18:22:38 +010039if which ninja > /dev/null 2>&1; then
Renato Golin94cc1042016-04-26 11:02:23 +010040 make=ninja
Diana Picus416bc4f2016-04-22 16:47:57 +030041 generator="Ninja"
Renato Golin94cc1042016-04-26 11:02:23 +010042fi
43
44## Debug mode, make it lighter
Diana Picus72189fd2016-05-23 19:32:46 +030045if [ "$LLVM_DEBUG" = true ]; then
Renato Golin94cc1042016-04-26 11:02:23 +010046 build_type=Debug
47 shared=-DBUILD_SHARED_LIBS=True
Renato Golinddb25322016-10-26 11:59:06 +010048 # Disabling split-dwarf until we can be sure the relocation
49 # problems we're seeing aren't specific to this feature
50 # Error: R_ARM_ABS32 used with TLS symbol
51 #dwarf=-DLLVM_USE_SPLIT_DWARF=ON
Renato Golin250b7aa2016-09-17 18:22:38 +010052 targets=$minimal_targets
53fi
54
55# Building on ARM?
56if grep -q "ARM.* Processor" /proc/cpuinfo; then
57 targets=$minimal_targets
58 if [ "$make" = "ninja" ]; then
59 link=$(free -g | awk '/Mem/ {print $2}')
60 if [ "$link" -gt "$CPUS" ]; then
61 link=$CPUS
62 else
63 link=$((link+1))
64 fi
65 link_jobs="-DLLVM_PARALLEL_LINK_JOBS=$link"
66 fi
Renato Golin94cc1042016-04-26 11:02:23 +010067fi
68
69## Make sure sure build dir is there
70if [ ! -d $build_dir ]; then
Diana Picus5a10ae12016-04-27 18:29:38 +030071 safe_run mkdir -p $build_dir
Renato Golin94cc1042016-04-26 11:02:23 +010072fi
73cd $build_dir
74
Diana Picus0df00012016-09-15 16:10:44 +030075## Allow the user to override the number of CPUs used with -jN
76if [[ $1 =~ -j[0-9]+ ]]; then
77 PARALLEL=$1
78 shift
79fi
80
Diana Picusc581e192016-05-27 12:56:06 +030081## Re-run CMake if files are damaged / not there
Renato Golin94cc1042016-04-26 11:02:23 +010082if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
83 echo " + Configuring Build"
Diana Picus416bc4f2016-04-22 16:47:57 +030084 safe_run cmake -G "$generator" $LLVM_SRC \
Renato Golin94cc1042016-04-26 11:02:23 +010085 -DCMAKE_BUILD_TYPE=$build_type \
86 -DLLVM_BUILD_TESTS=True \
87 -DLLVM_ENABLE_ASSERTIONS=True \
88 -DPYTHON_EXECUTABLE=/usr/bin/python2 \
89 -DCMAKE_INSTALL_PREFIX=$install_dir \
Renato Golin250b7aa2016-09-17 18:22:38 +010090 -DLLVM_LIT_ARGS="-sv $PARALLEL" \
Diana Picus49270f32016-12-16 16:53:47 +020091 -DCMAKE_CXX_FLAGS="-Wall" \
92 $targets $shared $link_jobs $dwarf $LLVM_CMAKE_FLAGS
Renato Golin94cc1042016-04-26 11:02:23 +010093fi
94
95## Build
Diana Picusc581e192016-05-27 12:56:06 +030096if [ "$1" == "" ]; then
97 echo " + Building LLVM"
Diana Picus87d06322016-07-22 11:52:31 +030098 safe_run $make $PARALLEL
Diana Picusc581e192016-05-27 12:56:06 +030099else
100 for target in "$@"; do
101 echo " + Running $target"
Diana Picus87d06322016-07-22 11:52:31 +0300102 safe_run $make $PARALLEL $target
Diana Picusc581e192016-05-27 12:56:06 +0300103 done
Renato Golin94cc1042016-04-26 11:02:23 +0100104fi
105