blob: e0ff2da368d3ae6286e92bb8c8272939f9771a80 [file] [log] [blame]
#!/usr/bin/env bash
# This script keeps track of all projects that are linked to the llvm src
# directory. It can detect, enable, disable and map to specific projects,
# so different builds get to see the source dir as they saw originally.
. llvm-common
prog=`basename $0`
syntax() {
echo "Syntax: $prog {+/-}[clang|rt|libs|tools|test]"
echo " noarg: list linked projects"
echo " {+/-}: link / unlik projects (default: link)"
}
# Dirs and links into LLVM
clang_dir=clang
clang_link=tools/clang
rt_dir=compiler-rt
rt_link=projects/compiler-rt
libcxx_dir=libcxx
libcxx_link=projects/libcxx
libcxxabi_dir=libcxxabi
libcxxabi_link=projects/libcxxabi
libunwind_dir=libunwind
libunwind_link=projects/libunwind
lld_dir=lld
lld_link=tools/lld
lldb_dir=lldb
lldb_link=tools/lldb
tests_dir=test-suite
tests_link=projects/test-suite
# Check if link exists
has() {
link=$1
[ -s "$LLVM_SRC/$link" ]
}
# Initialise status
init() {
link=$1
if has $link; then
echo "true";
else
echo "false"
fi
}
# Link/Unlink upon need
update() {
dir=$1
link=$2
need=$3
if $need; then
ln -sf $LLVM_SRC/../$dir $LLVM_SRC/$link
else
rm -f $LLVM_SRC/$link
fi
}
# Lists linked projects and quit
list_all() {
echo "Projects linked:"
has $clang_link && echo " + Clang"
has $rt_link && echo " + Compiler-RT"
has $libcxx_link && echo " + LibC++"
has $libcxxabi_link && echo " + LibC++abi"
has $libunwind_link && echo " + LibUnwind"
has $lld_link && echo " + LLD"
has $lldb_link && echo " + LLDB"
has $tests_link && echo " + Test-Suite"
echo
}
# No args, list
if [ "$1" = "" ]; then
echo "Use $prog -h for options"
echo
list_all
exit
fi
# Need/not need
clang=`init $clang_link`
rt=`init $rt_link`
libcxx=`init $libcxx_link`
libcxxabi=`init $libcxxabi_link`
libunwind=`init $libunwind_link`
lld=`init $lld_link`
lldb=`init $lldb_link`
tests=`init $tests_link`
# Check all needed projects
while ! test -z $1; do
opt=$1
sign=${opt:0:1}
flag=true
if [ "$sign" = "-" ]; then
flag=false
opt=${opt:1}
fi
if [ "$sign" = "+" ]; then
opt=${opt:1}
fi
case $opt in
clang)
clang=$flag
;;
rt)
rt=$flag
;;
libs)
libcxx=$flag
libcxxabi=$flag
libunwind=$flag
;;
tools)
lld=$flag
lldb=$flag
;;
test)
tests=$flag
;;
list)
list_all
exit
;;
-h)
syntax
exit
;;
*)
syntax
exit 1
esac
shift
done
# Update links
update $tests_dir $tests_link $tests
update $lldb_dir $lldb_link $lldb
update $lld_dir $lld_link $lld
update $libunwind_dir $libunwind_link $libunwind
update $libcxxabi_dir $libcxxabi_link $libcxxabi
update $libcxx_dir $libcxx_link $libcxx
update $rt_dir $rt_link $rt
update $clang_dir $clang_link $clang
list_all