aboutsummaryrefslogtreecommitdiff
path: root/helpers/llvm-build
blob: f638c75534e54c7da201c2cf7f086d174f03e57f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash

# This script helps you build LLVM. It can update the repositories first,
# run the check-all after and even install it in your system. Since the
# LLVM tree changes constantly, it's recommended that you run this script
# with update+check at least once a week, and most importantly, before you
# begin a big change, to make sure the repos are current and stable.

. llvm-common

safe_run verify_env

## CMD line options and defaults
CPUS=$(grep -c proc /proc/cpuinfo)
PARALLEL=-j$CPUS
build_dir=$LLVM_BLD
install_dir=$LLVM_INSTALL
build_type=Release
shared=
targets=
dwarf=
prog=`basename $0`
syntax="Syntax: $prog [-jN] [targets]"
update=false
check=false
master=false
inst=false
minimal_targets="-DLLVM_TARGETS_TO_BUILD='ARM;X86;AArch64'"
link_jobs=

if [ "$1" = "-h" ]; then
  echo $syntax
  exit 0
fi

## Choose between make and ninja
make=make
generator="Unix Makefiles"
if which ninja > /dev/null 2>&1; then
  make=ninja
  generator="Ninja"
fi

## Debug mode, make it lighter
if [ "$LLVM_DEBUG" = true ]; then
  build_type=Debug
  shared=-DBUILD_SHARED_LIBS=True
  # Disabling split-dwarf until we can be sure the relocation
  # problems we're seeing aren't specific to this feature
  # Error: R_ARM_ABS32 used with TLS symbol
  #dwarf=-DLLVM_USE_SPLIT_DWARF=ON
  targets=$minimal_targets
fi

# Building on ARM?
if grep -q "ARM.* Processor" /proc/cpuinfo; then
  targets=$minimal_targets
  if [ "$make" = "ninja" ]; then
    link=$(free -g | awk '/Mem/ {print $2}')
    if [ "$link" -gt "$CPUS" ]; then
      link=$CPUS
    else
      link=$((link+1))
    fi
    link_jobs="-DLLVM_PARALLEL_LINK_JOBS=$link"
  fi
fi

## Make sure sure build dir is there
if [ ! -d $build_dir ]; then
  safe_run mkdir -p $build_dir
fi
cd $build_dir

## Allow the user to override the number of CPUs used with -jN
if [[ $1 =~ -j[0-9]+ ]]; then
  PARALLEL=$1
  shift
fi

## Re-run CMake if files are damaged / not there
if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
	echo " + Configuring Build"
  safe_run cmake -G "$generator" $LLVM_SRC \
            -DCMAKE_BUILD_TYPE=$build_type \
            -DLLVM_BUILD_TESTS=True \
            -DLLVM_ENABLE_ASSERTIONS=True \
            -DPYTHON_EXECUTABLE=/usr/bin/python2 \
            -DCMAKE_INSTALL_PREFIX=$install_dir \
            -DLLVM_LIT_ARGS="-sv $PARALLEL" \
            -DCMAKE_CXX_FLAGS="-Wall" \
            $targets $shared $link_jobs $dwarf $LLVM_CMAKE_FLAGS
fi

## Build
if [ "$1" == "" ]; then
  echo " + Building LLVM"
  safe_run $make $PARALLEL
else
  for target in "$@"; do
    echo " + Running $target"
    safe_run $make $PARALLEL $target
  done
fi