blob: f9cc70687fe5db8f23be6b3a339d6b57185f9d8d [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/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
9prog=`basename $0`
10syntax() {
Diana Picusdf02ca02016-05-03 13:44:42 +030011 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 Golin94cc1042016-04-26 11:02:23 +010031}
32
33# Dirs and links into LLVM
34clang_dir=clang
35clang_link=tools/clang
Diana Picus3124fb82016-04-25 15:37:25 +030036clang_extra_dir=clang-tools-extra
37clang_extra_link=tools/clang/tools/extra
Renato Golin94cc1042016-04-26 11:02:23 +010038rt_dir=compiler-rt
39rt_link=projects/compiler-rt
40libcxx_dir=libcxx
41libcxx_link=projects/libcxx
42libcxxabi_dir=libcxxabi
43libcxxabi_link=projects/libcxxabi
44libunwind_dir=libunwind
45libunwind_link=projects/libunwind
46lld_dir=lld
47lld_link=tools/lld
48lldb_dir=lldb
49lldb_link=tools/lldb
50tests_dir=test-suite
51tests_link=projects/test-suite
52
53# Check if link exists
54has() {
55 link=$1
56 [ -s "$LLVM_SRC/$link" ]
57}
58
59# Initialise status
60init() {
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
70update() {
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
82list_all() {
83 echo "Projects linked:"
84 has $clang_link && echo " + Clang"
Diana Picus3124fb82016-04-25 15:37:25 +030085 has $clang_extra_link && echo " + Clang Tools Extra"
Renato Golin94cc1042016-04-26 11:02:23 +010086 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 Picusdf02ca02016-05-03 13:44:42 +030096need_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 Golin94cc1042016-04-26 11:02:23 +0100109# No args, list
110if [ "$1" = "" ]; then
111 echo "Use $prog -h for options"
112 echo
113 list_all
114 exit
115fi
116
117# Need/not need
118clang=`init $clang_link`
Diana Picus3124fb82016-04-25 15:37:25 +0300119clang_extra=`init $clang_extra_link`
Renato Golin94cc1042016-04-26 11:02:23 +0100120rt=`init $rt_link`
121libcxx=`init $libcxx_link`
122libcxxabi=`init $libcxxabi_link`
123libunwind=`init $libunwind_link`
124lld=`init $lld_link`
125lldb=`init $lldb_link`
126tests=`init $tests_link`
127
Diana Picusdf02ca02016-05-03 13:44:42 +0300128# See if the first option is one of the long options
129opt=$1
130case $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 ;;
179esac
180
181# Parse short options, if any
Renato Golin94cc1042016-04-26 11:02:23 +0100182while ! test -z $1; do
183 opt=$1
Diana Picusdf02ca02016-05-03 13:44:42 +0300184
Renato Golin94cc1042016-04-26 11:02:23 +0100185 sign=${opt:0:1}
186 flag=true
187 if [ "$sign" = "-" ]; then
188 flag=false
189 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300190 elif [ "$sign" = "+" ]; then
Renato Golin94cc1042016-04-26 11:02:23 +0100191 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300192 else
193 # Doesn't look like one of our short options
194 syntax
195 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100196 fi
197
198 case $opt in
Diana Picusdf02ca02016-05-03 13:44:42 +0300199 c)
Renato Golin94cc1042016-04-26 11:02:23 +0100200 clang=$flag
201 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300202 x)
Diana Picus3124fb82016-04-25 15:37:25 +0300203 clang_extra=$flag
204 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300205 r)
Renato Golin94cc1042016-04-26 11:02:23 +0100206 rt=$flag
207 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300208 k)
Renato Golin94cc1042016-04-26 11:02:23 +0100209 lld=$flag
Diana Picusdf02ca02016-05-03 13:44:42 +0300210 ;;
211 d)
Renato Golin94cc1042016-04-26 11:02:23 +0100212 lldb=$flag
213 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300214 l)
215 libcxx=$flag
216 ;;
217 a)
218 libcxxabi=$flag
219 ;;
220 u)
221 libunwind=$flag
222 ;;
223 t)
Renato Golin94cc1042016-04-26 11:02:23 +0100224 tests=$flag
225 ;;
Renato Golin94cc1042016-04-26 11:02:23 +0100226 *)
227 syntax
Diana Picusdf02ca02016-05-03 13:44:42 +0300228 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100229 esac
230 shift
231done
232
Diana Picusdf02ca02016-05-03 13:44:42 +0300233# 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
236if [ "$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
239fi
240
241
Renato Golin94cc1042016-04-26 11:02:23 +0100242# Update links
243update $tests_dir $tests_link $tests
244update $lldb_dir $lldb_link $lldb
245update $lld_dir $lld_link $lld
246update $libunwind_dir $libunwind_link $libunwind
247update $libcxxabi_dir $libcxxabi_link $libcxxabi
248update $libcxx_dir $libcxx_link $libcxx
249update $rt_dir $rt_link $rt
250update $clang_dir $clang_link $clang
Diana Picus3124fb82016-04-25 15:37:25 +0300251update $clang_extra_dir $clang_extra_link $clang_extra
Renato Golin94cc1042016-04-26 11:02:23 +0100252list_all