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 | 36317e8 | 2017-10-31 15:35:24 +0100 | [diff] [blame] | 9 | echo "Syntax: $prog [clang|lldb|lld|rt|libs|all|none] {+/-}[c|r|k|d|l|a|u|t]" |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 10 | echo " no args: List linked projects" |
Diana Picus | 36317e8 | 2017-10-31 15:35:24 +0100 | [diff] [blame] | 11 | echo " clang: Clang" |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 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" | ||||
Diana Picus | 36317e8 | 2017-10-31 15:35:24 +0100 | [diff] [blame] | 18 | echo " {+/-}: enable / disable projects" |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 19 | echo " c Clang" |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 20 | echo " r Compiler-rt" |
21 | echo " k lld" | ||||
22 | echo " d lldb" | ||||
23 | echo " l libcxx" | ||||
24 | echo " a libcxxabi" | ||||
25 | echo " u libunwind" | ||||
26 | echo " t test-suite" | ||||
27 | 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] | 28 | } |
29 | |||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 30 | need_all() { |
31 | need=$1 | ||||
32 | clang=$need | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 33 | rt=$need |
34 | libcxx=$need | ||||
35 | libcxxabi=$need | ||||
36 | libunwind=$need | ||||
37 | lld=$need | ||||
38 | lldb=$need | ||||
39 | tests=$need | ||||
40 | } | ||||
41 | |||||
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 42 | llvmtool=$progdir/../scripts/llvm.py |
43 | |||||
Diana Picus | 3d1a301 | 2017-03-14 17:38:32 +0100 | [diff] [blame] | 44 | # Grab the environment name from $LLVM_SRC |
45 | . llvm-common | ||||
46 | verify_env | ||||
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 47 | repos=$LLVM_ROOT/repos |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 48 | source_dir=$LLVM_SRC |
49 | env=$(dirname $source_dir) | ||||
Diana Picus | 3d1a301 | 2017-03-14 17:38:32 +0100 | [diff] [blame] | 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 | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 55 | safe_run python3 $llvmtool projects --source-dir $source_dir |
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 | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 67 | shift |
68 | ;; | ||||
69 | lldb) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 70 | need_all OFF |
71 | clang=ON | ||||
72 | lldb=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 73 | shift |
74 | ;; | ||||
75 | lld) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 76 | need_all OFF |
77 | clang=ON | ||||
78 | lld=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 79 | shift |
80 | ;; | ||||
81 | rt) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 82 | need_all OFF |
83 | clang=ON | ||||
84 | rt=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 85 | shift |
86 | ;; | ||||
87 | libs) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 88 | need_all OFF |
89 | clang=ON | ||||
90 | libcxx=ON | ||||
91 | libcxxabi=ON | ||||
92 | libunwind=ON | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 93 | shift |
94 | ;; | ||||
95 | all) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 96 | need_all ON |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 97 | shift |
98 | ;; | ||||
99 | none) | ||||
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 100 | need_all OFF |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 101 | shift |
102 | ;; | ||||
103 | list) | ||||
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 104 | safe_run python3 $llvmtool projects --source-dir $source_dir |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 105 | exit |
106 | ;; | ||||
107 | -h) | ||||
108 | syntax | ||||
109 | exit | ||||
110 | ;; | ||||
111 | esac | ||||
112 | |||||
113 | # Parse short options, if any | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 114 | while ! test -z $1; do |
115 | opt=$1 | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 116 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 117 | sign=${opt:0:1} |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 118 | flag=ON |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 119 | if [ "$sign" = "-" ]; then |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 120 | flag=OFF |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 121 | opt=${opt:1} |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 122 | elif [ "$sign" = "+" ]; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 123 | opt=${opt:1} |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 124 | else |
125 | # Doesn't look like one of our short options | ||||
126 | syntax | ||||
127 | exit | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 128 | fi |
129 | |||||
130 | case $opt in | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 131 | c) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 132 | clang=$flag |
133 | ;; | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 134 | r) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 135 | rt=$flag |
136 | ;; | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 137 | k) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 138 | lld=$flag |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 139 | ;; |
140 | d) | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 141 | lldb=$flag |
142 | ;; | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 143 | l) |
144 | libcxx=$flag | ||||
145 | ;; | ||||
146 | a) | ||||
147 | libcxxabi=$flag | ||||
148 | ;; | ||||
149 | u) | ||||
150 | libunwind=$flag | ||||
151 | ;; | ||||
152 | t) | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 153 | tests=$flag |
154 | ;; | ||||
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 155 | *) |
156 | syntax | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 157 | exit |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 158 | esac |
159 | shift | ||||
160 | done | ||||
161 | |||||
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 162 | add="" |
163 | remove="" | ||||
164 | |||||
165 | update() { | ||||
166 | project="$1" | ||||
167 | flag="$2" | ||||
168 | |||||
169 | case $flag in | ||||
170 | ON) | ||||
171 | add="$add $project" | ||||
172 | ;; | ||||
173 | OFF) | ||||
174 | remove="$remove $project" | ||||
175 | ;; | ||||
176 | UNDEF) | ||||
177 | # Don't care | ||||
178 | ;; | ||||
179 | esac | ||||
180 | } | ||||
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 181 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 182 | # Update links |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 183 | update "test-suite" $tests |
184 | update "lldb" $lldb | ||||
185 | update "lld" $lld | ||||
186 | update "libunwind" $libunwind | ||||
187 | update "libcxxabi" $libcxxabi | ||||
188 | update "libcxx" $libcxx | ||||
189 | update "compiler-rt" $rt | ||||
190 | update "clang" $clang | ||||
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 191 | |
192 | if [ "$add" != "" ]; then | ||||
193 | add="-a $add" | ||||
194 | fi | ||||
195 | |||||
196 | if [ "$remove" != "" ]; then | ||||
197 | remove="-r $remove" | ||||
198 | fi | ||||
199 | |||||
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 200 | safe_run python3 $llvmtool projects --source-dir $source_dir --repos $repos $add $remove |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 201 | |
202 | if [ -d $env/build ]; then | ||||
203 | echo "Updating $env/build" | ||||
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 204 | safe_run python3 $llvmtool configure --source-dir $source_dir --build-dir $env/build |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 205 | fi |
206 | |||||
207 | if [ -d $env/debug ]; then | ||||
208 | echo "Updating $env/debug" | ||||
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 209 | safe_run python3 $llvmtool configure --source-dir $source_dir --build-dir $env/debug |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 210 | fi |