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 |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 14 | PARALLEL=-j`grep -c proc /proc/cpuinfo` |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 15 | build_dir=$LLVM_BLD |
Diana Picus | b2a8786 | 2016-07-20 17:14:00 +0300 | [diff] [blame] | 16 | install_dir=$LLVM_INSTALL |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 17 | build_type=Release |
| 18 | shared= |
| 19 | targets= |
| 20 | prog=`basename $0` |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 21 | syntax="Syntax: $prog [-jN] [targets]" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 22 | update=false |
| 23 | check=false |
| 24 | master=false |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 25 | inst=false |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 26 | |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 27 | if [ "$1" = "-h" ]; then |
| 28 | echo $syntax |
| 29 | exit 0 |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 30 | fi |
| 31 | |
| 32 | ## Choose between make and ninja |
| 33 | make=make |
Diana Picus | 416bc4f | 2016-04-22 16:47:57 +0300 | [diff] [blame] | 34 | generator="Unix Makefiles" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 35 | if which ninja 2>&1 > /dev/null; then |
| 36 | make=ninja |
Diana Picus | 416bc4f | 2016-04-22 16:47:57 +0300 | [diff] [blame] | 37 | generator="Ninja" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 38 | fi |
| 39 | |
| 40 | ## Debug mode, make it lighter |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 41 | if [ "$LLVM_DEBUG" = true ]; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 42 | build_type=Debug |
| 43 | shared=-DBUILD_SHARED_LIBS=True |
| 44 | targets=-DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64" |
| 45 | fi |
| 46 | |
| 47 | ## Make sure sure build dir is there |
| 48 | if [ ! -d $build_dir ]; then |
Diana Picus | 5a10ae1 | 2016-04-27 18:29:38 +0300 | [diff] [blame] | 49 | safe_run mkdir -p $build_dir |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 50 | fi |
| 51 | cd $build_dir |
| 52 | |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 53 | ## Re-run CMake if files are damaged / not there |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 54 | if [ ! -f build.ninja ] && [ ! -f Makefile ]; then |
| 55 | echo " + Configuring Build" |
Diana Picus | 416bc4f | 2016-04-22 16:47:57 +0300 | [diff] [blame] | 56 | safe_run cmake -G "$generator" $LLVM_SRC \ |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 57 | -DCMAKE_BUILD_TYPE=$build_type \ |
| 58 | -DLLVM_BUILD_TESTS=True \ |
| 59 | -DLLVM_ENABLE_ASSERTIONS=True \ |
| 60 | -DPYTHON_EXECUTABLE=/usr/bin/python2 \ |
| 61 | -DCMAKE_INSTALL_PREFIX=$install_dir \ |
Renato Golin | db4c6a1 | 2016-08-01 17:03:26 +0100 | [diff] [blame^] | 62 | $LLVM_CMAKE_FLAGS $targets $shared |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 63 | fi |
| 64 | |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 65 | ## Allow the user to override the number of CPUs used with -jN |
| 66 | if [[ $1 =~ -j[0-9]+ ]]; then |
| 67 | PARALLEL=$1 |
| 68 | shift |
| 69 | fi |
| 70 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 71 | ## Build |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 72 | if [ "$1" == "" ]; then |
| 73 | echo " + Building LLVM" |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 74 | safe_run $make $PARALLEL |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 75 | else |
| 76 | for target in "$@"; do |
| 77 | echo " + Running $target" |
Diana Picus | 87d0632 | 2016-07-22 11:52:31 +0300 | [diff] [blame] | 78 | safe_run $make $PARALLEL $target |
Diana Picus | c581e19 | 2016-05-27 12:56:06 +0300 | [diff] [blame] | 79 | done |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 80 | fi |
| 81 | |