blob: e0ff2da368d3ae6286e92bb8c8272939f9771a80 [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() {
11 echo "Syntax: $prog {+/-}[clang|rt|libs|tools|test]"
12 echo " noarg: list linked projects"
13 echo " {+/-}: link / unlik projects (default: link)"
14}
15
16# Dirs and links into LLVM
17clang_dir=clang
18clang_link=tools/clang
19rt_dir=compiler-rt
20rt_link=projects/compiler-rt
21libcxx_dir=libcxx
22libcxx_link=projects/libcxx
23libcxxabi_dir=libcxxabi
24libcxxabi_link=projects/libcxxabi
25libunwind_dir=libunwind
26libunwind_link=projects/libunwind
27lld_dir=lld
28lld_link=tools/lld
29lldb_dir=lldb
30lldb_link=tools/lldb
31tests_dir=test-suite
32tests_link=projects/test-suite
33
34# Check if link exists
35has() {
36 link=$1
37 [ -s "$LLVM_SRC/$link" ]
38}
39
40# Initialise status
41init() {
42 link=$1
43 if has $link; then
44 echo "true";
45 else
46 echo "false"
47 fi
48}
49
50# Link/Unlink upon need
51update() {
52 dir=$1
53 link=$2
54 need=$3
55 if $need; then
56 ln -sf $LLVM_SRC/../$dir $LLVM_SRC/$link
57 else
58 rm -f $LLVM_SRC/$link
59 fi
60}
61
62# Lists linked projects and quit
63list_all() {
64 echo "Projects linked:"
65 has $clang_link && echo " + Clang"
66 has $rt_link && echo " + Compiler-RT"
67 has $libcxx_link && echo " + LibC++"
68 has $libcxxabi_link && echo " + LibC++abi"
69 has $libunwind_link && echo " + LibUnwind"
70 has $lld_link && echo " + LLD"
71 has $lldb_link && echo " + LLDB"
72 has $tests_link && echo " + Test-Suite"
73 echo
74}
75
76# No args, list
77if [ "$1" = "" ]; then
78 echo "Use $prog -h for options"
79 echo
80 list_all
81 exit
82fi
83
84# Need/not need
85clang=`init $clang_link`
86rt=`init $rt_link`
87libcxx=`init $libcxx_link`
88libcxxabi=`init $libcxxabi_link`
89libunwind=`init $libunwind_link`
90lld=`init $lld_link`
91lldb=`init $lldb_link`
92tests=`init $tests_link`
93
94# Check all needed projects
95while ! test -z $1; do
96 opt=$1
97 sign=${opt:0:1}
98 flag=true
99 if [ "$sign" = "-" ]; then
100 flag=false
101 opt=${opt:1}
102 fi
103 if [ "$sign" = "+" ]; then
104 opt=${opt:1}
105 fi
106
107 case $opt in
108 clang)
109 clang=$flag
110 ;;
111 rt)
112 rt=$flag
113 ;;
114 libs)
115 libcxx=$flag
116 libcxxabi=$flag
117 libunwind=$flag
118 ;;
119 tools)
120 lld=$flag
121 lldb=$flag
122 ;;
123 test)
124 tests=$flag
125 ;;
126 list)
127 list_all
128 exit
129 ;;
130 -h)
131 syntax
132 exit
133 ;;
134 *)
135 syntax
136 exit 1
137 esac
138 shift
139done
140
141# Update links
142update $tests_dir $tests_link $tests
143update $lldb_dir $lldb_link $lldb
144update $lld_dir $lld_link $lld
145update $libunwind_dir $libunwind_link $libunwind
146update $libcxxabi_dir $libcxxabi_link $libcxxabi
147update $libcxx_dir $libcxx_link $libcxx
148update $rt_dir $rt_link $rt
149update $clang_dir $clang_link $clang
150list_all