summaryrefslogtreecommitdiff
blob: c1895b5e459a4447cdc4dde244bc723e2742db9a (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
98
99
100
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.9 2004/11/17 22:13:07 vapier Exp $
#
# Author: Toolchain Ninjas <ninjas@gentoo.org>
#
# This eclass contains (or should) functions to get common info 
# about the toolchain (libc/compiler/binutils/etc...)

inherit eutils

ECLASS=toolchain-funcs
INHERITED="$INHERITED $ECLASS"

DESCRIPTION="Based on the ${ECLASS} eclass"

tc-getPROG() {
	local var="$1"
	local prog="$2"
	local search=""

	if [ -n "${!var}" ] ; then
		echo "${!var}"
		return 0
	fi

	if [ -n "${CTARGET}" ] ; then
		search="$(type -p "${CTARGET}-${prog}")"
	elif [ -n "${CHOST}" ] ; then
		search="$(type -p "${CHOST}-${prog}")"
	fi

	if [ -n "${search}" ] ; then
		prog="${search##*/}"
	fi
	export ${var}="${prog}"
	echo "${!var}"
}

# Returns the name of the archiver
tc-getAR() { tc-getPROG AR ar; }
# Returns the name of the assembler
tc-getAS() { tc-getPROG AS as; }
# Returns the name of the C compiler
tc-getCC() { tc-getPROG CC gcc; }
# Returns the name of the C++ compiler
tc-getCXX() { tc-getPROG CXX g++; }
# Returns the name of the linker
tc-getLD() { tc-getPROG LD ld; }
# Returns the name of the symbol/object thingy
tc-getNM() { tc-getPROG NM nm; }
# Returns the name of the archiver indexer
tc-getRANLIB() { tc-getPROG RANLIB ranlib; }
# Returns the name of the fortran compiler
tc-getF77() { tc-getPROG F77 f77; }
# Returns the name of the java compiler
tc-getGCJ() { tc-getPROG GCJ gcj; }

# Returns the name of the C compiler for build
tc-getBUILD_CC() {
	if [ -n "${CC_FOR_BUILD}" ] ; then
		echo "${CC_FOR_BUILD}"
		return 0
	fi

	local search=
	if [ -n "${CTARGET}" ] ; then
		search="$(type -p "${CTARGET}-gcc")"
	elif [ -n "${CHOST}" ] ; then
		search="$(type -p "${CHOST}-gcc")"
	fi

	if [ -n "${search}" ] ; then
		echo "${search##*/}"
	else
		echo "gcc"
	fi
}


# Returns the version as by `$CC -dumpversion`
gcc-fullversion() {
	echo "$($(tc-getCC) -dumpversion)"
}
# Returns the version, but only the <major>.<minor>
gcc-version() {
	echo "$(gcc-fullversion | cut -f1,2 -d.)"
}
# Returns the Major version
gcc-major-version() {
	echo "$(gcc-version | cut -f1 -d.)"
}
# Returns the Minor version
gcc-minor-version() {
	echo "$(gcc-version | cut -f2 -d.)"
}
# Returns the Micro version
gcc-micro-version() {
	echo "$(gcc-fullversion | cut -f3 -d.)"
}