Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 3 | # This script helps you build LLVM. |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 4 | |
| 5 | . llvm-common |
| 6 | |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 7 | progdir=$(dirname $0) |
| 8 | llvmtool=$progdir/../scripts/llvm.py |
| 9 | |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 10 | safe_run verify_env |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 11 | source_dir=$LLVM_SRC |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 12 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 13 | ## CMD line options and defaults |
Renato Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 14 | CPUS=$(grep -c proc /proc/cpuinfo) |
| 15 | PARALLEL=-j$CPUS |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 16 | build_dir=$LLVM_BLD |
Diana Picus | b2a8786 | 2016-07-20 17:14:00 +0300 | [diff] [blame] | 17 | install_dir=$LLVM_INSTALL |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 18 | build_type=Release |
| 19 | shared= |
| 20 | targets= |
| 21 | prog=`basename $0` |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 22 | syntax="Syntax: $prog [-jN] [targets]" |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 23 | minimal_targets="--cmake-def LLVM_TARGETS_TO_BUILD='ARM;X86;AArch64'" |
Renato Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 24 | link_jobs= |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 25 | |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 26 | if [ "$1" = "-h" ]; then |
| 27 | echo $syntax |
| 28 | exit 0 |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 29 | fi |
| 30 | |
| 31 | ## Choose between make and ninja |
Diana Picus | 416bc4f | 2016-04-22 16:47:57 +0300 | [diff] [blame] | 32 | generator="Unix Makefiles" |
Renato Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 33 | if which ninja > /dev/null 2>&1; then |
Diana Picus | 416bc4f | 2016-04-22 16:47:57 +0300 | [diff] [blame] | 34 | generator="Ninja" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 35 | fi |
| 36 | |
| 37 | ## Debug mode, make it lighter |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 38 | if [ "$LLVM_DEBUG" = true ]; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 39 | build_type=Debug |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 40 | shared="--cmake-def BUILD_SHARED_LIBS=True" |
Renato Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 41 | targets=$minimal_targets |
| 42 | fi |
| 43 | |
| 44 | # Building on ARM? |
| 45 | if grep -q "ARM.* Processor" /proc/cpuinfo; then |
| 46 | targets=$minimal_targets |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 47 | if [ "$generator" = "Ninja" ]; then |
Renato Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 48 | 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 Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 54 | link_jobs="--cmake-def LLVM_PARALLEL_LINK_JOBS=$link" |
Renato Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 55 | fi |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 56 | fi |
| 57 | |
| 58 | ## Make sure sure build dir is there |
| 59 | if [ ! -d $build_dir ]; then |
Diana Picus | 5a10ae1 | 2016-04-27 18:29:38 +0300 | [diff] [blame] | 60 | safe_run mkdir -p $build_dir |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 61 | fi |
| 62 | cd $build_dir |
| 63 | |
Diana Picus | 0df0001 | 2016-09-15 16:10:44 +0300 | [diff] [blame] | 64 | ## Allow the user to override the number of CPUs used with -jN |
| 65 | if [[ $1 =~ -j[0-9]+ ]]; then |
| 66 | PARALLEL=$1 |
| 67 | shift |
| 68 | fi |
| 69 | |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 70 | ## Re-run CMake if files are damaged / not there |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 71 | if [ ! -f build.ninja ] && [ ! -f Makefile ]; then |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 72 | echo " + Configuring Build" |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 73 | safe_run python3 $llvmtool configure \ |
| 74 | --source-dir $source_dir --build-dir $build_dir \ |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 75 | --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 Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 82 | $LLVM_CMAKE_FLAGS $targets $shared $link_jobs |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 83 | fi |
| 84 | |
| 85 | ## Build |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 86 | if [ "$1" == "" ]; then |
| 87 | echo " + Building LLVM" |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 88 | safe_run python3 $llvmtool build --build-dir $build_dir --build-flag=$PARALLEL |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 89 | else |
| 90 | for target in "$@"; do |
| 91 | echo " + Running $target" |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 92 | safe_run python3 $llvmtool build --build-dir $build_dir \ |
| 93 | --build-flag=$PARALLEL --build-flag $target |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 94 | done |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 95 | fi |
| 96 | |