Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 1 | #!/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 Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 11 | safe_run verify_env |
| 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= |
Renato Golin | 767231c | 2016-10-19 23:46:37 +0100 | [diff] [blame] | 21 | dwarf= |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 22 | prog=`basename $0` |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 23 | syntax="Syntax: $prog [-jN] [targets]" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 24 | update=false |
| 25 | check=false |
| 26 | master=false |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 27 | inst=false |
Renato Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 28 | minimal_targets="-DLLVM_TARGETS_TO_BUILD='ARM;X86;AArch64'" |
| 29 | link_jobs= |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 30 | |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 31 | if [ "$1" = "-h" ]; then |
| 32 | echo $syntax |
| 33 | exit 0 |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 34 | fi |
| 35 | |
| 36 | ## Choose between make and ninja |
| 37 | make=make |
Diana Picus | 416bc4f | 2016-04-22 16:47:57 +0300 | [diff] [blame] | 38 | generator="Unix Makefiles" |
Renato Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 39 | if which ninja > /dev/null 2>&1; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 40 | make=ninja |
Diana Picus | 416bc4f | 2016-04-22 16:47:57 +0300 | [diff] [blame] | 41 | generator="Ninja" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 42 | fi |
| 43 | |
| 44 | ## Debug mode, make it lighter |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 45 | if [ "$LLVM_DEBUG" = true ]; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 46 | build_type=Debug |
| 47 | shared=-DBUILD_SHARED_LIBS=True |
Renato Golin | ddb2532 | 2016-10-26 11:59:06 +0100 | [diff] [blame] | 48 | # 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 Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 52 | targets=$minimal_targets |
| 53 | fi |
| 54 | |
| 55 | # Building on ARM? |
| 56 | if 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 Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 67 | fi |
| 68 | |
| 69 | ## Make sure sure build dir is there |
| 70 | if [ ! -d $build_dir ]; then |
Diana Picus | 5a10ae1 | 2016-04-27 18:29:38 +0300 | [diff] [blame] | 71 | safe_run mkdir -p $build_dir |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 72 | fi |
| 73 | cd $build_dir |
| 74 | |
Diana Picus | 0df0001 | 2016-09-15 16:10:44 +0300 | [diff] [blame] | 75 | ## Allow the user to override the number of CPUs used with -jN |
| 76 | if [[ $1 =~ -j[0-9]+ ]]; then |
| 77 | PARALLEL=$1 |
| 78 | shift |
| 79 | fi |
| 80 | |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 81 | ## Re-run CMake if files are damaged / not there |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 82 | if [ ! -f build.ninja ] && [ ! -f Makefile ]; then |
| 83 | echo " + Configuring Build" |
Diana Picus | 416bc4f | 2016-04-22 16:47:57 +0300 | [diff] [blame] | 84 | safe_run cmake -G "$generator" $LLVM_SRC \ |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 85 | -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 Golin | 250b7aa | 2016-09-17 18:22:38 +0100 | [diff] [blame] | 90 | -DLLVM_LIT_ARGS="-sv $PARALLEL" \ |
Diana Picus | 49270f3 | 2016-12-16 16:53:47 +0200 | [diff] [blame] | 91 | -DCMAKE_CXX_FLAGS="-Wall" \ |
| 92 | $targets $shared $link_jobs $dwarf $LLVM_CMAKE_FLAGS |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 93 | fi |
| 94 | |
| 95 | ## Build |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 96 | if [ "$1" == "" ]; then |
| 97 | echo " + Building LLVM" |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 98 | safe_run $make $PARALLEL |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 99 | else |
| 100 | for target in "$@"; do |
| 101 | echo " + Running $target" |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 102 | safe_run $make $PARALLEL $target |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 103 | done |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 104 | fi |
| 105 | |