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() { |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 11 | echo "Syntax: $prog [clang|lldb|lld|rt|libs|all|none] {+/-}[c|x|r|k|d|l|a|u|t]" |
| 12 | echo " no args: List linked projects" |
| 13 | echo " clang: Clang + Clang Tools Extra" |
| 14 | echo " lldb: Clang + lldb" |
| 15 | echo " lld: Clang + lld" |
| 16 | echo " rt: Clang + compiler-rt" |
| 17 | echo " libs: Clang + libcxx + libcxxabi + libunwind" |
| 18 | echo " all: Link all projects" |
| 19 | echo " none: Unlink all projects" |
| 20 | echo " {+/-}: link / unlink projects (default: link)" |
| 21 | echo " c Clang" |
| 22 | echo " x Clang Tools Extra" |
| 23 | echo " r Compiler-rt" |
| 24 | echo " k lld" |
| 25 | echo " d lldb" |
| 26 | echo " l libcxx" |
| 27 | echo " a libcxxabi" |
| 28 | echo " u libunwind" |
| 29 | echo " t test-suite" |
| 30 | echo " Long options unlink everything before proceeding. Use the short options for fine-tuning" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | # Dirs and links into LLVM |
| 34 | clang_dir=clang |
| 35 | clang_link=tools/clang |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 36 | clang_extra_dir=clang-tools-extra |
| 37 | clang_extra_link=tools/clang/tools/extra |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 38 | rt_dir=compiler-rt |
| 39 | rt_link=projects/compiler-rt |
| 40 | libcxx_dir=libcxx |
| 41 | libcxx_link=projects/libcxx |
| 42 | libcxxabi_dir=libcxxabi |
| 43 | libcxxabi_link=projects/libcxxabi |
| 44 | libunwind_dir=libunwind |
| 45 | libunwind_link=projects/libunwind |
| 46 | lld_dir=lld |
| 47 | lld_link=tools/lld |
| 48 | lldb_dir=lldb |
| 49 | lldb_link=tools/lldb |
| 50 | tests_dir=test-suite |
| 51 | tests_link=projects/test-suite |
| 52 | |
| 53 | # Check if link exists |
| 54 | has() { |
| 55 | link=$1 |
| 56 | [ -s "$LLVM_SRC/$link" ] |
| 57 | } |
| 58 | |
| 59 | # Initialise status |
| 60 | init() { |
| 61 | link=$1 |
| 62 | if has $link; then |
| 63 | echo "true"; |
| 64 | else |
| 65 | echo "false" |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | # Link/Unlink upon need |
| 70 | update() { |
| 71 | dir=$1 |
| 72 | link=$2 |
| 73 | need=$3 |
| 74 | if $need; then |
| 75 | ln -sf $LLVM_SRC/../$dir $LLVM_SRC/$link |
| 76 | else |
| 77 | rm -f $LLVM_SRC/$link |
| 78 | fi |
| 79 | } |
| 80 | |
| 81 | # Lists linked projects and quit |
| 82 | list_all() { |
| 83 | echo "Projects linked:" |
| 84 | has $clang_link && echo " + Clang" |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 85 | has $clang_extra_link && echo " + Clang Tools Extra" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 86 | has $rt_link && echo " + Compiler-RT" |
| 87 | has $libcxx_link && echo " + LibC++" |
| 88 | has $libcxxabi_link && echo " + LibC++abi" |
| 89 | has $libunwind_link && echo " + LibUnwind" |
| 90 | has $lld_link && echo " + LLD" |
| 91 | has $lldb_link && echo " + LLDB" |
| 92 | has $tests_link && echo " + Test-Suite" |
| 93 | echo |
| 94 | } |
| 95 | |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 96 | need_all() { |
| 97 | need=$1 |
| 98 | clang=$need |
| 99 | clang_extra=$need |
| 100 | rt=$need |
| 101 | libcxx=$need |
| 102 | libcxxabi=$need |
| 103 | libunwind=$need |
| 104 | lld=$need |
| 105 | lldb=$need |
| 106 | tests=$need |
| 107 | } |
| 108 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 109 | # No args, list |
| 110 | if [ "$1" = "" ]; then |
| 111 | echo "Use $prog -h for options" |
| 112 | echo |
| 113 | list_all |
| 114 | exit |
| 115 | fi |
| 116 | |
| 117 | # Need/not need |
| 118 | clang=`init $clang_link` |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 119 | clang_extra=`init $clang_extra_link` |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 120 | rt=`init $rt_link` |
| 121 | libcxx=`init $libcxx_link` |
| 122 | libcxxabi=`init $libcxxabi_link` |
| 123 | libunwind=`init $libunwind_link` |
| 124 | lld=`init $lld_link` |
| 125 | lldb=`init $lldb_link` |
| 126 | tests=`init $tests_link` |
| 127 | |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 128 | # See if the first option is one of the long options |
| 129 | opt=$1 |
| 130 | case $opt in |
| 131 | clang) |
| 132 | need_all false |
| 133 | clang=true |
| 134 | clang_extra=true |
| 135 | shift |
| 136 | ;; |
| 137 | lldb) |
| 138 | need_all false |
| 139 | clang=true |
| 140 | lldb=true |
| 141 | shift |
| 142 | ;; |
| 143 | lld) |
| 144 | need_all false |
| 145 | clang=true |
| 146 | lld=true |
| 147 | shift |
| 148 | ;; |
| 149 | rt) |
| 150 | need_all false |
| 151 | clang=true |
| 152 | rt=true |
| 153 | shift |
| 154 | ;; |
| 155 | libs) |
| 156 | need_all false |
| 157 | clang=true |
| 158 | libcxx=true |
| 159 | libcxxabi=true |
| 160 | libunwind=true |
| 161 | shift |
| 162 | ;; |
| 163 | all) |
| 164 | need_all true |
| 165 | shift |
| 166 | ;; |
| 167 | none) |
| 168 | need_all false |
| 169 | shift |
| 170 | ;; |
| 171 | list) |
| 172 | list_all |
| 173 | exit |
| 174 | ;; |
| 175 | -h) |
| 176 | syntax |
| 177 | exit |
| 178 | ;; |
| 179 | esac |
| 180 | |
| 181 | # Parse short options, if any |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 182 | while ! test -z $1; do |
| 183 | opt=$1 |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 184 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 185 | sign=${opt:0:1} |
| 186 | flag=true |
| 187 | if [ "$sign" = "-" ]; then |
| 188 | flag=false |
| 189 | opt=${opt:1} |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 190 | elif [ "$sign" = "+" ]; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 191 | opt=${opt:1} |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 192 | else |
| 193 | # Doesn't look like one of our short options |
| 194 | syntax |
| 195 | exit |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 196 | fi |
| 197 | |
| 198 | case $opt in |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 199 | c) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 200 | clang=$flag |
| 201 | ;; |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 202 | x) |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 203 | clang_extra=$flag |
| 204 | ;; |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 205 | r) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 206 | rt=$flag |
| 207 | ;; |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 208 | k) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 209 | lld=$flag |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 210 | ;; |
| 211 | d) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 212 | lldb=$flag |
| 213 | ;; |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 214 | l) |
| 215 | libcxx=$flag |
| 216 | ;; |
| 217 | a) |
| 218 | libcxxabi=$flag |
| 219 | ;; |
| 220 | u) |
| 221 | libunwind=$flag |
| 222 | ;; |
| 223 | t) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 224 | tests=$flag |
| 225 | ;; |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 226 | *) |
| 227 | syntax |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 228 | exit |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 229 | esac |
| 230 | shift |
| 231 | done |
| 232 | |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 233 | # clang and clang-tools-extra have a special relationship: we can't enable |
| 234 | # clang-tools-extra without enabling clang, and we also can't disable clang |
| 235 | # without also disabling clang-tools-extra |
| 236 | if [ "$clang_extra" = true -a "$clang" = false ]; then |
| 237 | echo "Can't have Clang Tools Extra without Clang! Try to add +c or -x" |
| 238 | exit |
| 239 | fi |
| 240 | |
| 241 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 242 | # Update links |
| 243 | update $tests_dir $tests_link $tests |
| 244 | update $lldb_dir $lldb_link $lldb |
| 245 | update $lld_dir $lld_link $lld |
| 246 | update $libunwind_dir $libunwind_link $libunwind |
| 247 | update $libcxxabi_dir $libcxxabi_link $libcxxabi |
| 248 | update $libcxx_dir $libcxx_link $libcxx |
| 249 | update $rt_dir $rt_link $rt |
| 250 | update $clang_dir $clang_link $clang |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 251 | update $clang_extra_dir $clang_extra_link $clang_extra |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 252 | list_all |