forked from ClangBuiltLinux/tc-build
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-tc.sh
executable file
·79 lines (70 loc) · 2.26 KB
/
build-tc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
set -eo pipefail
# Function to show an informational message
function msg() {
echo -e "\e[1;32m$@\e[0m"
}
rm -rf installTmp
# Build LLVM
msg "Building LLVM..."
./build-llvm.py \
--update \
--build-stage1-only \
--install-stage1-only \
--projects "clang;lld;polly" \
--targets "ARM;AArch64;X86" \
--install-folder "installTmp" \
--clang-vendor "Candy-$(date +%Y%m%d)" \
--additional-build-arguments "CLANG_REPOSITORY_STRING=GitHub.com/WLoot"
# Build binutils
msg "Building binutils..."
if [ $(which clang) ] && [ $(which clang++) ]; then
export CC=$(which ccache)" clang"
export CXX=$(which ccache)" clang++"
[ $(which llvm-strip) ] && stripBin=llvm-strip
else
export CC=$(which ccache)" gcc"
export CXX=$(which ccache)" g++"
[ $(which strip) ] && stripBin=strip
fi
./build-binutils.py \
--targets arm aarch64 x86_64 \
--install-folder "installTmp"
# Remove unused products
msg "Removing unused products..."
rm -f installTmp/lib/*.a installTmp/lib/*.la installTmp/lib/clang/*/lib/linux/*.a*
msg "Setting library load paths for portability and"
msg "Stripping remaining products..."
IFS=$'\n'
for f in $(find installTmp -type f -exec file {} \;); do
if [ -n "$(echo $f | grep 'ELF .* interpreter')" ]; then
i=$(echo $f | awk '{print $1}'); i=${i: : -1}
# Set executable rpaths so setting LD_LIBRARY_PATH isn't necessary
if [ -d $(dirname $i)/../lib/ldscripts ]; then
patchelf --set-rpath '$ORIGIN/../../lib:$ORIGIN/../lib' "$i"
else
if [ "$(patchelf --print-rpath $i)" != "\$ORIGIN/../../lib:\$ORIGIN/../lib" ]; then
patchelf --set-rpath '$ORIGIN/../lib' "$i"
fi
fi
# Strip remaining products
if [ -n "$(echo $f | grep 'not stripped')" ]; then
${stripBin} --strip-unneeded "$i"
fi
elif [ -n "$(echo $f | grep 'ELF .* relocatable')" ]; then
if [ -n "$(echo $f | grep 'not stripped')" ]; then
i=$(echo $f | awk '{print $1}');
${stripBin} --strip-unneeded "${i: : -1}"
fi
else
if [ -n "$(echo $f | grep 'not stripped')" ]; then
i=$(echo $f | awk '{print $1}');
${stripBin} --strip-all "${i: : -1}"
fi
fi
done
rm -rf ./install
mv installTmp/ install/
msg "build-tc HEAD: $(git rev-parse HEAD)"
msg "binutils HEAD: $(git -C binutils/ rev-parse HEAD)"
msg "llvm-project HEAD: $(git -C llvm-project/ rev-parse HEAD)"