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 | |
| 11 | ## CMD line options and defaults |
| 12 | CPUs=`grep -c proc /proc/cpuinfo` |
| 13 | build_dir=$LLVM_BLD |
| 14 | install_dir=$LLVM_BLD/../../install |
| 15 | build_type=Release |
| 16 | shared= |
| 17 | targets= |
| 18 | prog=`basename $0` |
| 19 | syntax="Syntax: $prog [-u(pdate)] [-c(check-all)] [-i(nstall)] [-d(debug)]" |
| 20 | update=false |
| 21 | check=false |
| 22 | master=false |
| 23 | debug=false |
| 24 | inst=false |
| 25 | while getopts "ucimd" opt; do |
| 26 | case $opt in |
| 27 | u) |
| 28 | update=true |
| 29 | ;; |
| 30 | c) |
| 31 | check=true |
| 32 | ;; |
| 33 | i) |
| 34 | inst=true |
| 35 | ;; |
| 36 | m) |
| 37 | master=true |
| 38 | ;; |
| 39 | d) |
| 40 | debug=true |
| 41 | build_dir=$LLVM_BLD/../debug |
| 42 | ;; |
| 43 | *) |
| 44 | echo $syntax |
| 45 | exit 1 |
| 46 | ;; |
| 47 | esac |
| 48 | done |
| 49 | |
| 50 | ## Run llvm-sync before |
| 51 | if $update; then |
| 52 | echo " + Updating Repositories" |
| 53 | safe_run llvm-sync -a |
| 54 | fi |
| 55 | |
| 56 | ## Make sure all branches are on master |
| 57 | if $master; then |
| 58 | echo " + Checking out master" |
| 59 | safe_run llvm-branch master |
| 60 | fi |
| 61 | |
| 62 | ## Choose between make and ninja |
| 63 | make=make |
| 64 | ninja= |
| 65 | if which ninja 2>&1 > /dev/null; then |
| 66 | make=ninja |
| 67 | ninja="-G Ninja" |
| 68 | fi |
| 69 | |
| 70 | ## Debug mode, make it lighter |
| 71 | if $debug; then |
| 72 | build_type=Debug |
| 73 | shared=-DBUILD_SHARED_LIBS=True |
| 74 | targets=-DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64" |
| 75 | fi |
| 76 | |
| 77 | ## Make sure sure build dir is there |
| 78 | if [ ! -d $build_dir ]; then |
| 79 | mkdir -p $builddir |
| 80 | fi |
| 81 | cd $build_dir |
| 82 | |
| 83 | ## Re-run CMake file files are damaged / not there |
| 84 | if [ ! -f build.ninja ] && [ ! -f Makefile ]; then |
| 85 | echo " + Configuring Build" |
| 86 | safe_run cmake $ninja $LLVM_SRC \ |
| 87 | -DCMAKE_BUILD_TYPE=$build_type \ |
| 88 | -DLLVM_BUILD_TESTS=True \ |
| 89 | -DLLVM_ENABLE_ASSERTIONS=True \ |
| 90 | -DPYTHON_EXECUTABLE=/usr/bin/python2 \ |
| 91 | -DCMAKE_INSTALL_PREFIX=$install_dir \ |
| 92 | $targets $shared |
| 93 | fi |
| 94 | |
| 95 | ## Build |
| 96 | echo " + Building LLVM" |
| 97 | safe_run $make -j$CPUs |
| 98 | |
| 99 | ## Check |
| 100 | if $check; then |
| 101 | echo " + Running Tests" |
| 102 | safe_run $make check-all |
| 103 | fi |
| 104 | |
| 105 | ## Install |
| 106 | if $inst; then |
| 107 | echo " + Installing on the System" |
| 108 | safe_run $make install |
| 109 | fi |