blob: b6fb46b8041a5b927c3fba323b2279b2834f9be7 [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 Golin767231c2016-10-19 23:46:37 +010048 dwarf=-DLLVM_USE_SPLIT_DWARF=ON
Renato Golin250b7aa2016-09-17 18:22:38 +010049 targets=$minimal_targets
50fi
51
52# Building on ARM?
53if grep -q "ARM.* Processor" /proc/cpuinfo; then
54 targets=$minimal_targets
55 if [ "$make" = "ninja" ]; then
56 link=$(free -g | awk '/Mem/ {print $2}')
57 if [ "$link" -gt "$CPUS" ]; then
58 link=$CPUS
59 else
60 link=$((link+1))
61 fi
62 link_jobs="-DLLVM_PARALLEL_LINK_JOBS=$link"
63 fi
Renato Golin94cc1042016-04-26 11:02:23 +010064fi
65
66## Make sure sure build dir is there
67if [ ! -d $build_dir ]; then
Diana Picus5a10ae12016-04-27 18:29:38 +030068 safe_run mkdir -p $build_dir
Renato Golin94cc1042016-04-26 11:02:23 +010069fi
70cd $build_dir
71
Diana Picus0df00012016-09-15 16:10:44 +030072## Allow the user to override the number of CPUs used with -jN
73if [[ $1 =~ -j[0-9]+ ]]; then
74 PARALLEL=$1
75 shift
76fi
77
Diana Picusc581e192016-05-27 12:56:06 +030078## Re-run CMake if files are damaged / not there
Renato Golin94cc1042016-04-26 11:02:23 +010079if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
80 echo " + Configuring Build"
Diana Picus416bc4f2016-04-22 16:47:57 +030081 safe_run cmake -G "$generator" $LLVM_SRC \
Renato Golin94cc1042016-04-26 11:02:23 +010082 -DCMAKE_BUILD_TYPE=$build_type \
83 -DLLVM_BUILD_TESTS=True \
84 -DLLVM_ENABLE_ASSERTIONS=True \
85 -DPYTHON_EXECUTABLE=/usr/bin/python2 \
86 -DCMAKE_INSTALL_PREFIX=$install_dir \
Renato Golin250b7aa2016-09-17 18:22:38 +010087 -DLLVM_LIT_ARGS="-sv $PARALLEL" \
Renato Golin767231c2016-10-19 23:46:37 +010088 $LLVM_CMAKE_FLAGS $targets $shared $link_jobs $dwarf
Renato Golin94cc1042016-04-26 11:02:23 +010089fi
90
91## Build
Diana Picusc581e192016-05-27 12:56:06 +030092if [ "$1" == "" ]; then
93 echo " + Building LLVM"
Diana Picus87d06322016-07-22 11:52:31 +030094 safe_run $make $PARALLEL
Diana Picusc581e192016-05-27 12:56:06 +030095else
96 for target in "$@"; do
97 echo " + Running $target"
Diana Picus87d06322016-07-22 11:52:31 +030098 safe_run $make $PARALLEL $target
Diana Picusc581e192016-05-27 12:56:06 +030099 done
Renato Golin94cc1042016-04-26 11:02:23 +0100100fi
101