Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
2 | |||||
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 3 | # Shorthand script for adding/removing llvm subprojects. It has a simpler |
4 | # interface than llvm.py, but it calls it to do the actual work. | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 5 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 6 | prog=$(basename $0) |
7 | progdir=$(dirname $0) | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 8 | syntax() { |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 9 | echo "Syntax: $prog [clang|lldb|lld|rt|libs|all|none] {+/-}[c|x|r|k|d|l|a|u|t]" |
10 | echo " no args: List linked projects" | ||||
11 | echo " clang: Clang + Clang Tools Extra" | ||||
12 | echo " lldb: Clang + lldb" | ||||
13 | echo " lld: Clang + lld" | ||||
14 | echo " rt: Clang + compiler-rt" | ||||
15 | echo " libs: Clang + libcxx + libcxxabi + libunwind" | ||||
16 | echo " all: Link all projects" | ||||
17 | echo " none: Unlink all projects" | ||||
18 | echo " {+/-}: link / unlink projects (default: link)" | ||||
19 | echo " c Clang" | ||||
20 | echo " x Clang Tools Extra" | ||||
21 | echo " r Compiler-rt" | ||||
22 | echo " k lld" | ||||
23 | echo " d lldb" | ||||
24 | echo " l libcxx" | ||||
25 | echo " a libcxxabi" | ||||
26 | echo " u libunwind" | ||||
27 | echo " t test-suite" | ||||
28 | 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] | 29 | } |
30 | |||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 31 | need_all() { |
32 | need=$1 | ||||
33 | clang=$need | ||||
34 | clang_extra=$need | ||||
35 | rt=$need | ||||
36 | libcxx=$need | ||||
37 | libcxxabi=$need | ||||
38 | libunwind=$need | ||||
39 | lld=$need | ||||
40 | lldb=$need | ||||
41 | tests=$need | ||||
42 | } | ||||
43 | |||||
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 44 | llvmtool=$progdir/../scripts/llvm.py |
45 | |||||
Diana Picus | 3d1a301 | 2017-03-14 17:38:32 +0100 | [diff] [blame^] | 46 | # Grab the environment name from $LLVM_SRC |
47 | . llvm-common | ||||
48 | verify_env | ||||
49 | env=$(basename $(dirname $LLVM_SRC)) | ||||
50 | |||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 51 | # No args, list |
52 | if [ "$1" = "" ]; then | ||||
53 | echo "Use $prog -h for options" | ||||
54 | echo | ||||
Diana Picus | 3d1a301 | 2017-03-14 17:38:32 +0100 | [diff] [blame^] | 55 | safe_run python3 $llvmtool $env projects |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 56 | exit |
57 | fi | ||||
58 | |||||
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 59 | need_all UNDEF |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 60 | |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 61 | # See if the first option is one of the long options |
62 | opt=$1 | ||||
63 | case $opt in | ||||
64 | clang) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 65 | need_all OFF |
66 | clang=ON | ||||
67 | clang_extra=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 68 | shift |
69 | ;; | ||||
70 | lldb) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 71 | need_all OFF |
72 | clang=ON | ||||
73 | lldb=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 74 | shift |
75 | ;; | ||||
76 | lld) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 77 | need_all OFF |
78 | clang=ON | ||||
79 | lld=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 80 | shift |
81 | ;; | ||||
82 | rt) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 83 | need_all OFF |
84 | clang=ON | ||||
85 | rt=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 86 | shift |
87 | ;; | ||||
88 | libs) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 89 | need_all OFF |
90 | clang=ON | ||||
91 | libcxx=ON | ||||
92 | libcxxabi=ON | ||||
93 | libunwind=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 94 | shift |
95 | ;; | ||||
96 | all) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 97 | need_all ON |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 98 | shift |
99 | ;; | ||||
100 | none) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 101 | need_all OFF |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 102 | shift |
103 | ;; | ||||
104 | list) | ||||
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 105 | python $llvmtool projects |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 106 | exit |
107 | ;; | ||||
108 | -h) | ||||
109 | syntax | ||||
110 | exit | ||||
111 | ;; | ||||
112 | esac | ||||
113 | |||||
114 | # Parse short options, if any | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 115 | while ! test -z $1; do |
116 | opt=$1 | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 117 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 118 | sign=${opt:0:1} |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 119 | flag=ON |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 120 | if [ "$sign" = "-" ]; then |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 121 | flag=OFF |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 122 | opt=${opt:1} |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 123 | elif [ "$sign" = "+" ]; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 124 | opt=${opt:1} |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 125 | else |
126 | # Doesn't look like one of our short options | ||||
127 | syntax | ||||
128 | exit | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 129 | fi |
130 | |||||
131 | case $opt in | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 132 | c) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 133 | clang=$flag |
134 | ;; | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 135 | x) |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 136 | clang_extra=$flag |
137 | ;; | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 138 | r) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 139 | rt=$flag |
140 | ;; | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 141 | k) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 142 | lld=$flag |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 143 | ;; |
144 | d) | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 145 | lldb=$flag |
146 | ;; | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 147 | l) |
148 | libcxx=$flag | ||||
149 | ;; | ||||
150 | a) | ||||
151 | libcxxabi=$flag | ||||
152 | ;; | ||||
153 | u) | ||||
154 | libunwind=$flag | ||||
155 | ;; | ||||
156 | t) | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 157 | tests=$flag |
158 | ;; | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 159 | *) |
160 | syntax | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 161 | exit |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 162 | esac |
163 | shift | ||||
164 | done | ||||
165 | |||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 166 | # clang and clang-tools-extra have a special relationship: we can't enable |
167 | # clang-tools-extra without enabling clang, and we also can't disable clang | ||||
168 | # without also disabling clang-tools-extra | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 169 | if [ "$clang_extra" = ON -a "$clang" = OFF ]; then |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 170 | echo "Can't have Clang Tools Extra without Clang! Try to add +c or -x" |
171 | exit | ||||
172 | fi | ||||
173 | |||||
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 174 | add="" |
175 | remove="" | ||||
176 | |||||
177 | update() { | ||||
178 | project="$1" | ||||
179 | flag="$2" | ||||
180 | |||||
181 | case $flag in | ||||
182 | ON) | ||||
183 | add="$add $project" | ||||
184 | ;; | ||||
185 | OFF) | ||||
186 | remove="$remove $project" | ||||
187 | ;; | ||||
188 | UNDEF) | ||||
189 | # Don't care | ||||
190 | ;; | ||||
191 | esac | ||||
192 | } | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 193 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 194 | # Update links |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 195 | update "test-suite" $tests |
196 | update "lldb" $lldb | ||||
197 | update "lld" $lld | ||||
198 | update "libunwind" $libunwind | ||||
199 | update "libcxxabi" $libcxxabi | ||||
200 | update "libcxx" $libcxx | ||||
201 | update "compiler-rt" $rt | ||||
202 | update "clang" $clang | ||||
203 | update "clang-tools-extra" $clang_extra | ||||
204 | |||||
205 | if [ "$add" != "" ]; then | ||||
206 | add="-a $add" | ||||
207 | fi | ||||
208 | |||||
209 | if [ "$remove" != "" ]; then | ||||
210 | remove="-r $remove" | ||||
211 | fi | ||||
212 | |||||
Diana Picus | 3d1a301 | 2017-03-14 17:38:32 +0100 | [diff] [blame^] | 213 | safe_run python3 $llvmtool $env projects $add $remove |