Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # This script keeps track of all projects that are linked to the llvm src |
| 4 | # directory. It can detect, enable, disable and map to specific projects, |
| 5 | # so different builds get to see the source dir as they saw originally. |
| 6 | |
| 7 | . llvm-common |
| 8 | |
| 9 | prog=`basename $0` |
| 10 | syntax() { |
| 11 | echo "Syntax: $prog {+/-}[clang|rt|libs|tools|test]" |
| 12 | echo " noarg: list linked projects" |
| 13 | echo " {+/-}: link / unlik projects (default: link)" |
| 14 | } |
| 15 | |
| 16 | # Dirs and links into LLVM |
| 17 | clang_dir=clang |
| 18 | clang_link=tools/clang |
| 19 | rt_dir=compiler-rt |
| 20 | rt_link=projects/compiler-rt |
| 21 | libcxx_dir=libcxx |
| 22 | libcxx_link=projects/libcxx |
| 23 | libcxxabi_dir=libcxxabi |
| 24 | libcxxabi_link=projects/libcxxabi |
| 25 | libunwind_dir=libunwind |
| 26 | libunwind_link=projects/libunwind |
| 27 | lld_dir=lld |
| 28 | lld_link=tools/lld |
| 29 | lldb_dir=lldb |
| 30 | lldb_link=tools/lldb |
| 31 | tests_dir=test-suite |
| 32 | tests_link=projects/test-suite |
| 33 | |
| 34 | # Check if link exists |
| 35 | has() { |
| 36 | link=$1 |
| 37 | [ -s "$LLVM_SRC/$link" ] |
| 38 | } |
| 39 | |
| 40 | # Initialise status |
| 41 | init() { |
| 42 | link=$1 |
| 43 | if has $link; then |
| 44 | echo "true"; |
| 45 | else |
| 46 | echo "false" |
| 47 | fi |
| 48 | } |
| 49 | |
| 50 | # Link/Unlink upon need |
| 51 | update() { |
| 52 | dir=$1 |
| 53 | link=$2 |
| 54 | need=$3 |
| 55 | if $need; then |
| 56 | ln -sf $LLVM_SRC/../$dir $LLVM_SRC/$link |
| 57 | else |
| 58 | rm -f $LLVM_SRC/$link |
| 59 | fi |
| 60 | } |
| 61 | |
| 62 | # Lists linked projects and quit |
| 63 | list_all() { |
| 64 | echo "Projects linked:" |
| 65 | has $clang_link && echo " + Clang" |
| 66 | has $rt_link && echo " + Compiler-RT" |
| 67 | has $libcxx_link && echo " + LibC++" |
| 68 | has $libcxxabi_link && echo " + LibC++abi" |
| 69 | has $libunwind_link && echo " + LibUnwind" |
| 70 | has $lld_link && echo " + LLD" |
| 71 | has $lldb_link && echo " + LLDB" |
| 72 | has $tests_link && echo " + Test-Suite" |
| 73 | echo |
| 74 | } |
| 75 | |
| 76 | # No args, list |
| 77 | if [ "$1" = "" ]; then |
| 78 | echo "Use $prog -h for options" |
| 79 | echo |
| 80 | list_all |
| 81 | exit |
| 82 | fi |
| 83 | |
| 84 | # Need/not need |
| 85 | clang=`init $clang_link` |
| 86 | rt=`init $rt_link` |
| 87 | libcxx=`init $libcxx_link` |
| 88 | libcxxabi=`init $libcxxabi_link` |
| 89 | libunwind=`init $libunwind_link` |
| 90 | lld=`init $lld_link` |
| 91 | lldb=`init $lldb_link` |
| 92 | tests=`init $tests_link` |
| 93 | |
| 94 | # Check all needed projects |
| 95 | while ! test -z $1; do |
| 96 | opt=$1 |
| 97 | sign=${opt:0:1} |
| 98 | flag=true |
| 99 | if [ "$sign" = "-" ]; then |
| 100 | flag=false |
| 101 | opt=${opt:1} |
| 102 | fi |
| 103 | if [ "$sign" = "+" ]; then |
| 104 | opt=${opt:1} |
| 105 | fi |
| 106 | |
| 107 | case $opt in |
| 108 | clang) |
| 109 | clang=$flag |
| 110 | ;; |
| 111 | rt) |
| 112 | rt=$flag |
| 113 | ;; |
| 114 | libs) |
| 115 | libcxx=$flag |
| 116 | libcxxabi=$flag |
| 117 | libunwind=$flag |
| 118 | ;; |
| 119 | tools) |
| 120 | lld=$flag |
| 121 | lldb=$flag |
| 122 | ;; |
| 123 | test) |
| 124 | tests=$flag |
| 125 | ;; |
| 126 | list) |
| 127 | list_all |
| 128 | exit |
| 129 | ;; |
| 130 | -h) |
| 131 | syntax |
| 132 | exit |
| 133 | ;; |
| 134 | *) |
| 135 | syntax |
| 136 | exit 1 |
| 137 | esac |
| 138 | shift |
| 139 | done |
| 140 | |
| 141 | # Update links |
| 142 | update $tests_dir $tests_link $tests |
| 143 | update $lldb_dir $lldb_link $lldb |
| 144 | update $lld_dir $lld_link $lld |
| 145 | update $libunwind_dir $libunwind_link $libunwind |
| 146 | update $libcxxabi_dir $libcxxabi_link $libcxxabi |
| 147 | update $libcxx_dir $libcxx_link $libcxx |
| 148 | update $rt_dir $rt_link $rt |
| 149 | update $clang_dir $clang_link $clang |
| 150 | list_all |