-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldp
66 lines (54 loc) · 1.92 KB
/
ldp
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
#!/bin/bash
# Made for Gentoo. lld can be emerged from sys-devel/lld, Clang's linker.
# LLD is supported by GCC 9 as an alternative linker. When using -flto
# or -flto=thin, Clang will automatically multithread based on CPUs detected.
# Incompatible with Prefix and shells lacking GNU extensions.
if [[ "$(ld -v | awk '{print $2}')" == "ld" ]]; then
export DEFLD="bfd"
elif [[ "$(ld -v | awk '{print $2}')" == "gold" ]]; then
export DEFLD="gold";
else
export DEFLD=$(readlink /usr/bin/ld | cut -nc 13-)
fi
linkcheck()
{
if [[ $(grep -v "\#\|USE" /etc/portage/make.conf | grep -o '\-\fuse\-\linker\-\plugin') == '-fuse-linker-plugin' ]]; then
echo -e "\n-fuse-linker-plugin is being used in make.conf."
elif test -n $(grep -v "\#\|USE" /etc/portage/make.conf | grep -o '\-\fuse\-\ld'); then
echo -e "\nLinker in make.conf: $(grep -v "\#\|USE" /etc/portage/make.conf | grep -o "\-\fuse\-\ld\=.*d" | cut -nc 10-)";
else
exit 1
fi
}
help()
{
echo "Options to change the default system linker.
Usage: ldp ${DEFLD} -- switches linker; bfd, gold, and lld are supported.
ldp -- outputs the /usr/bin/ld symlink and linker in make.conf, if defined.
If -fuse-ld= is explicitly set in make.conf instead of
-fuse-linker-plugin, that will be replaced, too.
Note: Incompatible with Prefix and shells lacking GNU extensions."
}
for l in "${1}"
do
case "${1}" in
"-h" | "--help")
help
;;
"bfd" | "gold" | "lld")
if [ -f /usr/bin/ld.${1} ] && [[ $UID == "0" ]]; then
echo "Setting ${1} as the default linker." ;
ln -sf /usr/bin/ld.${l} /usr/bin/ld ;
sed -i "/^{\-\\|C\|f}/s/bfd\|gold\|lld/${1}/" /etc/portage/make.conf;
elif [[ $UID != "0" ]]; then
echo "Changing the linker requires root permissions. No changes were made.";
else
echo "${1} was not found in the standard directory. No changes were made."
exit 1
fi
;;
*)
echo -e "Symlink /usr/bin/ld: ${DEFLD}\c";
linkcheck
esac
done