blob: 1d10692f74e2a6ac7221b79a3a0a54f1b8ddd1d5 (
plain) (
blame)
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
|
#!/usr/bin/env bash
# Copyright (c) 2018 Egor Tensin <Egor.Tensin@gmail.com>
# This file is part of the "linux-home" project.
# For details, see https://github.com/egor-tensin/linux-home.
# Distributed under the MIT License.
alias update-my-alternatives='update-alternatives --quiet --altdir ~/.local/etc/alternatives --admindir ~/.local/var/lib/alternatives'
setup_alternatives_cc() (
set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit
gcc_cc="$( command -v gcc 2> /dev/null )" || return 0
gcc_cxx="$( command -v g++ 2> /dev/null )" || return 0
clang_cc="$( command -v clang 2> /dev/null )" || return 0
clang_cxx="$( command -v clang++ 2> /dev/null )" || return 0
mkdir -p -- ~/.local/bin
update-my-alternatives --remove-all cc || true
update-my-alternatives --install ~/.local/bin/cc cc "$clang_cc" 256 --slave ~/.local/bin/c++ c++ "$clang_cxx"
update-my-alternatives --install ~/.local/bin/cc cc "$gcc_cc" 512 --slave ~/.local/bin/c++ c++ "$gcc_cxx"
)
setup_alternatives() (
set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit
command -v update-alternatives > /dev/null 2>&1 || return 0
mkdir -p -- ~/.local/etc/alternatives ~/.local/var/lib/alternatives
setup_alternatives_cc
)
setup_alternatives
alt_gcc() (
set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit
gcc_cc="$( command -v gcc 2> /dev/null )"
update-my-alternatives --set cc "$gcc_cc"
)
alt_clang() (
set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit
clang_cc="$( command -v clang 2> /dev/null )"
update-my-alternatives --set cc "$clang_cc"
)
|