blob: 20a1fe62ab3a5abd1f2ec8f9624112b1a20269f6 [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 Picus36317e82017-10-31 15:35:24 +01009 echo "Syntax: $prog [clang|lldb|lld|rt|libs|all|none] {+/-}[c|r|k|d|l|a|u|t]"
Diana Picusdf02ca02016-05-03 13:44:42 +030010 echo " no args: List linked projects"
Diana Picus36317e82017-10-31 15:35:24 +010011 echo " clang: Clang"
Diana Picusdf02ca02016-05-03 13:44:42 +030012 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 Picus36317e82017-10-31 15:35:24 +010018 echo " {+/-}: enable / disable projects"
Diana Picusdf02ca02016-05-03 13:44:42 +030019 echo " c Clang"
Diana Picusdf02ca02016-05-03 13:44:42 +030020 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 Golin94cc1042016-04-26 11:02:23 +010028}
29
Diana Picusdf02ca02016-05-03 13:44:42 +030030need_all() {
31 need=$1
32 clang=$need
Diana Picusdf02ca02016-05-03 13:44:42 +030033 rt=$need
34 libcxx=$need
35 libcxxabi=$need
36 libunwind=$need
37 lld=$need
38 lldb=$need
39 tests=$need
40}
41
Diana Picus3b2ef822016-10-13 16:53:18 +030042llvmtool=$progdir/../scripts/llvm.py
43
Diana Picus3d1a3012017-03-14 17:38:32 +010044# Grab the environment name from $LLVM_SRC
45. llvm-common
46verify_env
Diana Picus81089db2017-05-05 22:26:49 +020047repos=$LLVM_ROOT/repos
Diana Picus9f756862017-12-20 10:35:08 +010048source_dir=$LLVM_SRC
49env=$(dirname $source_dir)
Diana Picus3d1a3012017-03-14 17:38:32 +010050
Renato Golin94cc1042016-04-26 11:02:23 +010051# No args, list
52if [ "$1" = "" ]; then
53 echo "Use $prog -h for options"
54 echo
Diana Picus9f756862017-12-20 10:35:08 +010055 safe_run python3 $llvmtool projects --source-dir $source_dir
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
Diana Picusdf02ca02016-05-03 13:44:42 +030067 shift
68 ;;
69 lldb)
Diana Picus72189fd2016-05-23 19:32:46 +030070 need_all OFF
71 clang=ON
72 lldb=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030073 shift
74 ;;
75 lld)
Diana Picus72189fd2016-05-23 19:32:46 +030076 need_all OFF
77 clang=ON
78 lld=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030079 shift
80 ;;
81 rt)
Diana Picus72189fd2016-05-23 19:32:46 +030082 need_all OFF
83 clang=ON
84 rt=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030085 shift
86 ;;
87 libs)
Diana Picus72189fd2016-05-23 19:32:46 +030088 need_all OFF
89 clang=ON
90 libcxx=ON
91 libcxxabi=ON
92 libunwind=ON
Diana Picusdf02ca02016-05-03 13:44:42 +030093 shift
94 ;;
95 all)
Diana Picus72189fd2016-05-23 19:32:46 +030096 need_all ON
Diana Picusdf02ca02016-05-03 13:44:42 +030097 shift
98 ;;
99 none)
Diana Picus72189fd2016-05-23 19:32:46 +0300100 need_all OFF
Diana Picusdf02ca02016-05-03 13:44:42 +0300101 shift
102 ;;
103 list)
Diana Picus9f756862017-12-20 10:35:08 +0100104 safe_run python3 $llvmtool projects --source-dir $source_dir
Diana Picusdf02ca02016-05-03 13:44:42 +0300105 exit
106 ;;
107 -h)
108 syntax
109 exit
110 ;;
111esac
112
113# Parse short options, if any
Renato Golin94cc1042016-04-26 11:02:23 +0100114while ! test -z $1; do
115 opt=$1
Diana Picusdf02ca02016-05-03 13:44:42 +0300116
Renato Golin94cc1042016-04-26 11:02:23 +0100117 sign=${opt:0:1}
Diana Picus72189fd2016-05-23 19:32:46 +0300118 flag=ON
Renato Golin94cc1042016-04-26 11:02:23 +0100119 if [ "$sign" = "-" ]; then
Diana Picus72189fd2016-05-23 19:32:46 +0300120 flag=OFF
Renato Golin94cc1042016-04-26 11:02:23 +0100121 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300122 elif [ "$sign" = "+" ]; then
Renato Golin94cc1042016-04-26 11:02:23 +0100123 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300124 else
125 # Doesn't look like one of our short options
126 syntax
127 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100128 fi
129
130 case $opt in
Diana Picusdf02ca02016-05-03 13:44:42 +0300131 c)
Renato Golin94cc1042016-04-26 11:02:23 +0100132 clang=$flag
133 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300134 r)
Renato Golin94cc1042016-04-26 11:02:23 +0100135 rt=$flag
136 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300137 k)
Renato Golin94cc1042016-04-26 11:02:23 +0100138 lld=$flag
Diana Picusdf02ca02016-05-03 13:44:42 +0300139 ;;
140 d)
Renato Golin94cc1042016-04-26 11:02:23 +0100141 lldb=$flag
142 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300143 l)
144 libcxx=$flag
145 ;;
146 a)
147 libcxxabi=$flag
148 ;;
149 u)
150 libunwind=$flag
151 ;;
152 t)
Renato Golin94cc1042016-04-26 11:02:23 +0100153 tests=$flag
154 ;;
Renato Golin94cc1042016-04-26 11:02:23 +0100155 *)
156 syntax
Diana Picusdf02ca02016-05-03 13:44:42 +0300157 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100158 esac
159 shift
160done
161
Diana Picus3b2ef822016-10-13 16:53:18 +0300162add=""
163remove=""
164
165update() {
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 Picusdf02ca02016-05-03 13:44:42 +0300181
Renato Golin94cc1042016-04-26 11:02:23 +0100182# Update links
Diana Picus3b2ef822016-10-13 16:53:18 +0300183update "test-suite" $tests
184update "lldb" $lldb
185update "lld" $lld
186update "libunwind" $libunwind
187update "libcxxabi" $libcxxabi
188update "libcxx" $libcxx
189update "compiler-rt" $rt
190update "clang" $clang
Diana Picus3b2ef822016-10-13 16:53:18 +0300191
192if [ "$add" != "" ]; then
193 add="-a $add"
194fi
195
196if [ "$remove" != "" ]; then
197 remove="-r $remove"
198fi
199
Diana Picus9f756862017-12-20 10:35:08 +0100200safe_run python3 $llvmtool projects --source-dir $source_dir --repos $repos $add $remove
Diana Picus052b7d32017-11-24 16:19:41 +0100201
202if [ -d $env/build ]; then
203 echo "Updating $env/build"
Diana Picus9f756862017-12-20 10:35:08 +0100204 safe_run python3 $llvmtool configure --source-dir $source_dir --build-dir $env/build
Diana Picus052b7d32017-11-24 16:19:41 +0100205fi
206
207if [ -d $env/debug ]; then
208 echo "Updating $env/debug"
Diana Picus9f756862017-12-20 10:35:08 +0100209 safe_run python3 $llvmtool configure --source-dir $source_dir --build-dir $env/debug
Diana Picus052b7d32017-11-24 16:19:41 +0100210fi