blob: ae8ac22962bd9a1f29e4d1984b04a2451de87ea2 [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/usr/bin/env bash
2
Diana Picus3b2ef822016-10-13 16:53:18 +03003# 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 Golin94cc1042016-04-26 11:02:23 +01005
Diana Picus3b2ef822016-10-13 16:53:18 +03006prog=$(basename $0)
7progdir=$(dirname $0)
Renato Golin94cc1042016-04-26 11:02:23 +01008syntax() {
Diana Picusdf02ca02016-05-03 13:44:42 +03009 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 Golin94cc1042016-04-26 11:02:23 +010029}
30
Diana Picusdf02ca02016-05-03 13:44:42 +030031need_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 Picus3b2ef822016-10-13 16:53:18 +030044llvmtool=$progdir/../scripts/llvm.py
45
Diana Picus3d1a3012017-03-14 17:38:32 +010046# Grab the environment name from $LLVM_SRC
47. llvm-common
48verify_env
49env=$(basename $(dirname $LLVM_SRC))
50
Renato Golin94cc1042016-04-26 11:02:23 +010051# No args, list
52if [ "$1" = "" ]; then
53 echo "Use $prog -h for options"
54 echo
Diana Picus3d1a3012017-03-14 17:38:32 +010055 safe_run python3 $llvmtool $env projects
Renato Golin94cc1042016-04-26 11:02:23 +010056 exit
57fi
58
Diana Picus3b2ef822016-10-13 16:53:18 +030059need_all UNDEF
Renato Golin94cc1042016-04-26 11:02:23 +010060
Diana Picusdf02ca02016-05-03 13:44:42 +030061# See if the first option is one of the long options
62opt=$1
63case $opt in
64 clang)
Diana Picus72189fd2016-05-23 19:32:46 +030065 need_all OFF
66 clang=ON
67 clang_extra=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030068 shift
69 ;;
70 lldb)
Diana Picus72189fd2016-05-23 19:32:46 +030071 need_all OFF
72 clang=ON
73 lldb=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030074 shift
75 ;;
76 lld)
Diana Picus72189fd2016-05-23 19:32:46 +030077 need_all OFF
78 clang=ON
79 lld=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030080 shift
81 ;;
82 rt)
Diana Picus72189fd2016-05-23 19:32:46 +030083 need_all OFF
84 clang=ON
85 rt=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030086 shift
87 ;;
88 libs)
Diana Picus72189fd2016-05-23 19:32:46 +030089 need_all OFF
90 clang=ON
91 libcxx=ON
92 libcxxabi=ON
93 libunwind=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030094 shift
95 ;;
96 all)
Diana Picus72189fd2016-05-23 19:32:46 +030097 need_all ON
Diana Picusdf02ca02016-05-03 13:44:42 +030098 shift
99 ;;
100 none)
Diana Picus72189fd2016-05-23 19:32:46 +0300101 need_all OFF
Diana Picusdf02ca02016-05-03 13:44:42 +0300102 shift
103 ;;
104 list)
Diana Picus3b2ef822016-10-13 16:53:18 +0300105 python $llvmtool projects
Diana Picusdf02ca02016-05-03 13:44:42 +0300106 exit
107 ;;
108 -h)
109 syntax
110 exit
111 ;;
112esac
113
114# Parse short options, if any
Renato Golin94cc1042016-04-26 11:02:23 +0100115while ! test -z $1; do
116 opt=$1
Diana Picusdf02ca02016-05-03 13:44:42 +0300117
Renato Golin94cc1042016-04-26 11:02:23 +0100118 sign=${opt:0:1}
Diana Picus72189fd2016-05-23 19:32:46 +0300119 flag=ON
Renato Golin94cc1042016-04-26 11:02:23 +0100120 if [ "$sign" = "-" ]; then
Diana Picus72189fd2016-05-23 19:32:46 +0300121 flag=OFF
Renato Golin94cc1042016-04-26 11:02:23 +0100122 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300123 elif [ "$sign" = "+" ]; then
Renato Golin94cc1042016-04-26 11:02:23 +0100124 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300125 else
126 # Doesn't look like one of our short options
127 syntax
128 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100129 fi
130
131 case $opt in
Diana Picusdf02ca02016-05-03 13:44:42 +0300132 c)
Renato Golin94cc1042016-04-26 11:02:23 +0100133 clang=$flag
134 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300135 x)
Diana Picus3124fb82016-04-25 15:37:25 +0300136 clang_extra=$flag
137 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300138 r)
Renato Golin94cc1042016-04-26 11:02:23 +0100139 rt=$flag
140 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300141 k)
Renato Golin94cc1042016-04-26 11:02:23 +0100142 lld=$flag
Diana Picusdf02ca02016-05-03 13:44:42 +0300143 ;;
144 d)
Renato Golin94cc1042016-04-26 11:02:23 +0100145 lldb=$flag
146 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300147 l)
148 libcxx=$flag
149 ;;
150 a)
151 libcxxabi=$flag
152 ;;
153 u)
154 libunwind=$flag
155 ;;
156 t)
Renato Golin94cc1042016-04-26 11:02:23 +0100157 tests=$flag
158 ;;
Renato Golin94cc1042016-04-26 11:02:23 +0100159 *)
160 syntax
Diana Picusdf02ca02016-05-03 13:44:42 +0300161 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100162 esac
163 shift
164done
165
Diana Picusdf02ca02016-05-03 13:44:42 +0300166# 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 Picus72189fd2016-05-23 19:32:46 +0300169if [ "$clang_extra" = ON -a "$clang" = OFF ]; then
Diana Picusdf02ca02016-05-03 13:44:42 +0300170 echo "Can't have Clang Tools Extra without Clang! Try to add +c or -x"
171 exit
172fi
173
Diana Picus3b2ef822016-10-13 16:53:18 +0300174add=""
175remove=""
176
177update() {
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 Picusdf02ca02016-05-03 13:44:42 +0300193
Renato Golin94cc1042016-04-26 11:02:23 +0100194# Update links
Diana Picus3b2ef822016-10-13 16:53:18 +0300195update "test-suite" $tests
196update "lldb" $lldb
197update "lld" $lld
198update "libunwind" $libunwind
199update "libcxxabi" $libcxxabi
200update "libcxx" $libcxx
201update "compiler-rt" $rt
202update "clang" $clang
203update "clang-tools-extra" $clang_extra
204
205if [ "$add" != "" ]; then
206 add="-a $add"
207fi
208
209if [ "$remove" != "" ]; then
210 remove="-r $remove"
211fi
212
Diana Picus3d1a3012017-03-14 17:38:32 +0100213safe_run python3 $llvmtool $env projects $add $remove