aboutsummaryrefslogtreecommitdiff
blob: 444f2e5210c9fe125a38dc64c0d02d62760555b3 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
#
# ccache-config - helper script for ccache and its ebuild
#
# Copyright 2003-2012 Superlucidity Services, LLC
# This program licensed under the GNU GPL version 2.
#
# This script developed by Zachary T Welch at Superlucidity Services, LLC
#  it was cloned from the distcc-config script
#
# Additional features to come; this provides a starting point

EPREFIX=''

. "${EPREFIX}"/etc/init.d/functions.sh 2>/dev/null || {
	ebegin() { echo " * $* ..."; }
	eend() {
		local r=${1:-$?}
		[ ${r} -eq 0 ] && echo " [ OK ]" || echo " [ !! ]"
		return $r
	}
}

LIBDIR="lib"

# this should be getopt'd someday (override with CC_QUIET=1)
CC_VERBOSE=1
unset _CC_QUIET
c_quiet() {
	[ -n "${CC_QUIET:-${_CC_QUIET}}" ] || [ -z "${CC_VERBOSE}" ]
}

c_ebegin() { c_quiet || ebegin "$@" ; }
c_eend()   { c_quiet || eend "$@" ; }

###
# the following functions manage the ccache symlinks
#  they allow the user or other scripts (namely gcc-config) to
#  automatically update ccache's links when upgrading toolchains
#
cc_path() {
	echo ${ROOT%/}${EPREFIX}/usr/${LIBDIR}/ccache/bin/$1
}
cc_remove_link() {
	local t=$(cc_path "$1")
	if [ -L ${t} ]; then
		c_ebegin "Removing ${t}"
		rm -f "${t}"
		c_eend
	fi
}
cc_install_link() {
	# Search the PATH for the specified compiler
	#  then create shadow link in /usr/lib/ccache/bin to ccache

	if [ -n "$(type -p ${1})" ]; then
		# first be sure any old link is removed
		_CC_QUIET=1
		cc_remove_link "${1}"
		unset _CC_QUIET

		# then create the new link
		local t=$(cc_path "$1")
		c_ebegin "Creating ccache shadow link ${t}"
		mkdir -p -m 0755 "${t%/*}" && ln -s "${EPREFIX}"/usr/bin/ccache "${t}"
		c_eend
	fi
}
cc_links() {
	local a compilers="gcc cc c++ g++" 
	[ "${2}" = icc ] && compilers="icc icpc" && set -- "$1"
	[ "${2}" = clang ] && compilers="clang clang++" && set -- "$1"
	for a in ${compilers} ; do
		if [ -n "${2}" ] ; then
			# gcc-config doesnt install ${CHOST}-cc, so until
			# it does, don't install a ccache symlink for it
			[ "${a}" = "cc" ] && continue
			a="${2}-${a}"
		fi
		eval "cc_${1}_link" "${a}"
	done
}

###
# main routine

case "${1}" in
	--install-links )
		cc_links install "${2}"
		;;
	--remove-links )
		cc_links remove "${2}"
		;;
	* )
		echo "usage: ${0} {--install-links|--remove-links} [ CHOST|clang|icc ]"
		;;
esac