blob: 773c16a079ddea6305aa79f3393293218c615324 [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/usr/bin/env bash
2
Diana Picus37126b82018-01-19 16:14:26 +01003# This script helps you build LLVM.
Renato Golin94cc1042016-04-26 11:02:23 +01004
5. llvm-common
6
Diana Picus052b7d32017-11-24 16:19:41 +01007progdir=$(dirname $0)
8llvmtool=$progdir/../scripts/llvm.py
9
Diana Picus72189fd2016-05-23 19:32:46 +030010safe_run verify_env
Diana Picus9f756862017-12-20 10:35:08 +010011source_dir=$LLVM_SRC
Diana Picus72189fd2016-05-23 19:32:46 +030012
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]"
Diana Picus052b7d32017-11-24 16:19:41 +010023minimal_targets="--cmake-def LLVM_TARGETS_TO_BUILD='ARM;X86;AArch64'"
Renato Golin250b7aa2016-09-17 18:22:38 +010024link_jobs=
Renato Golin94cc1042016-04-26 11:02:23 +010025
Diana Picusc581e192016-05-27 12:56:06 +030026if [ "$1" = "-h" ]; then
27 echo $syntax
28 exit 0
Renato Golin94cc1042016-04-26 11:02:23 +010029fi
30
31## Choose between make and ninja
Diana Picus416bc4f2016-04-22 16:47:57 +030032generator="Unix Makefiles"
Renato Golin250b7aa2016-09-17 18:22:38 +010033if which ninja > /dev/null 2>&1; then
Diana Picus416bc4f2016-04-22 16:47:57 +030034 generator="Ninja"
Renato Golin94cc1042016-04-26 11:02:23 +010035fi
36
37## Debug mode, make it lighter
Diana Picus72189fd2016-05-23 19:32:46 +030038if [ "$LLVM_DEBUG" = true ]; then
Renato Golin94cc1042016-04-26 11:02:23 +010039 build_type=Debug
Diana Picus052b7d32017-11-24 16:19:41 +010040 shared="--cmake-def BUILD_SHARED_LIBS=True"
Renato Golin250b7aa2016-09-17 18:22:38 +010041 targets=$minimal_targets
42fi
43
44# Building on ARM?
45if grep -q "ARM.* Processor" /proc/cpuinfo; then
46 targets=$minimal_targets
Diana Picus37126b82018-01-19 16:14:26 +010047 if [ "$generator" = "Ninja" ]; then
Renato Golin250b7aa2016-09-17 18:22:38 +010048 link=$(free -g | awk '/Mem/ {print $2}')
49 if [ "$link" -gt "$CPUS" ]; then
50 link=$CPUS
51 else
52 link=$((link+1))
53 fi
Diana Picus052b7d32017-11-24 16:19:41 +010054 link_jobs="--cmake-def LLVM_PARALLEL_LINK_JOBS=$link"
Renato Golin250b7aa2016-09-17 18:22:38 +010055 fi
Renato Golin94cc1042016-04-26 11:02:23 +010056fi
57
58## Make sure sure build dir is there
59if [ ! -d $build_dir ]; then
Diana Picus5a10ae12016-04-27 18:29:38 +030060 safe_run mkdir -p $build_dir
Renato Golin94cc1042016-04-26 11:02:23 +010061fi
62cd $build_dir
63
Diana Picus0df00012016-09-15 16:10:44 +030064## Allow the user to override the number of CPUs used with -jN
65if [[ $1 =~ -j[0-9]+ ]]; then
66 PARALLEL=$1
67 shift
68fi
69
Diana Picusc581e192016-05-27 12:56:06 +030070## Re-run CMake if files are damaged / not there
Renato Golin94cc1042016-04-26 11:02:23 +010071if [ ! -f build.ninja ] && [ ! -f Makefile ]; then
Diana Picus052b7d32017-11-24 16:19:41 +010072 echo " + Configuring Build"
Diana Picus9f756862017-12-20 10:35:08 +010073 safe_run python3 $llvmtool configure \
74 --source-dir $source_dir --build-dir $build_dir \
Diana Picus052b7d32017-11-24 16:19:41 +010075 --cmake-generator "$generator" \
76 --cmake-def CMAKE_BUILD_TYPE=$build_type \
77 --cmake-def LLVM_BUILD_TESTS=True \
78 --cmake-def LLVM_ENABLE_ASSERTIONS=True \
79 --cmake-def PYTHON_EXECUTABLE=/usr/bin/python2 \
80 --cmake-def CMAKE_INSTALL_PREFIX=$install_dir \
81 --cmake-def LLVM_LIT_ARGS="-sv $PARALLEL" \
Renato Golin250b7aa2016-09-17 18:22:38 +010082 $LLVM_CMAKE_FLAGS $targets $shared $link_jobs
Renato Golin94cc1042016-04-26 11:02:23 +010083fi
84
85## Build
Diana Picusc581e192016-05-27 12:56:06 +030086if [ "$1" == "" ]; then
87 echo " + Building LLVM"
Diana Picus37126b82018-01-19 16:14:26 +010088 safe_run python3 $llvmtool build --build-dir $build_dir --build-flag=$PARALLEL
Diana Picusc581e192016-05-27 12:56:06 +030089else
90 for target in "$@"; do
91 echo " + Running $target"
Diana Picus37126b82018-01-19 16:14:26 +010092 safe_run python3 $llvmtool build --build-dir $build_dir \
93 --build-flag=$PARALLEL --build-flag $target
Diana Picusc581e192016-05-27 12:56:06 +030094 done
Renato Golin94cc1042016-04-26 11:02:23 +010095fi
96