#!/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|lldb|lld|rt|libs|all|none] {+/-}[c|x|r|k|d|l|a|u|t]" echo " no args: List linked projects" echo " clang: Clang + Clang Tools Extra" echo " lldb: Clang + lldb" echo " lld: Clang + lld" echo " rt: Clang + compiler-rt" echo " libs: Clang + libcxx + libcxxabi + libunwind" echo " all: Link all projects" echo " none: Unlink all projects" echo " {+/-}: link / unlink projects (default: link)" echo " c Clang" echo " x Clang Tools Extra" echo " r Compiler-rt" echo " k lld" echo " d lldb" echo " l libcxx" echo " a libcxxabi" echo " u libunwind" echo " t test-suite" echo " Long options unlink everything before proceeding. Use the short options for fine-tuning" } # Dirs and links into LLVM clang_dir=clang clang_link=tools/clang clang_extra_dir=clang-tools-extra clang_extra_link=tools/clang/tools/extra 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 $clang_extra_link && echo " + Clang Tools Extra" 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 } need_all() { need=$1 clang=$need clang_extra=$need rt=$need libcxx=$need libcxxabi=$need libunwind=$need lld=$need lldb=$need tests=$need } # No args, list if [ "$1" = "" ]; then echo "Use $prog -h for options" echo list_all exit fi # Need/not need clang=`init $clang_link` clang_extra=`init $clang_extra_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` # See if the first option is one of the long options opt=$1 case $opt in clang) need_all false clang=true clang_extra=true shift ;; lldb) need_all false clang=true lldb=true shift ;; lld) need_all false clang=true lld=true shift ;; rt) need_all false clang=true rt=true shift ;; libs) need_all false clang=true libcxx=true libcxxabi=true libunwind=true shift ;; all) need_all true shift ;; none) need_all false shift ;; list) list_all exit ;; -h) syntax exit ;; esac # Parse short options, if any while ! test -z $1; do opt=$1 sign=${opt:0:1} flag=true if [ "$sign" = "-" ]; then flag=false opt=${opt:1} elif [ "$sign" = "+" ]; then opt=${opt:1} else # Doesn't look like one of our short options syntax exit fi case $opt in c) clang=$flag ;; x) clang_extra=$flag ;; r) rt=$flag ;; k) lld=$flag ;; d) lldb=$flag ;; l) libcxx=$flag ;; a) libcxxabi=$flag ;; u) libunwind=$flag ;; t) tests=$flag ;; *) syntax exit esac shift done # clang and clang-tools-extra have a special relationship: we can't enable # clang-tools-extra without enabling clang, and we also can't disable clang # without also disabling clang-tools-extra if [ "$clang_extra" = true -a "$clang" = false ]; then echo "Can't have Clang Tools Extra without Clang! Try to add +c or -x" exit fi # 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 update $clang_extra_dir $clang_extra_link $clang_extra list_all