| 1 | # Copyright 1999-2007 Gentoo Foundation |
1 | # Copyright 1999-2011 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.106 2011/09/09 19:14:19 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.112 2012/06/14 03:38:51 vapier Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: toolchain-funcs.eclass |
5 | # @ECLASS: toolchain-funcs.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Toolchain Ninjas <toolchain@gentoo.org> |
7 | # Toolchain Ninjas <toolchain@gentoo.org> |
| 8 | # @BLURB: functions to query common info about the toolchain |
8 | # @BLURB: functions to query common info about the toolchain |
| … | |
… | |
| 11 | # for gleaning useful information about the toolchain and to simplify |
11 | # for gleaning useful information about the toolchain and to simplify |
| 12 | # ugly things like cross-compiling and multilib. All of this is done |
12 | # ugly things like cross-compiling and multilib. All of this is done |
| 13 | # in such a way that you can rely on the function always returning |
13 | # in such a way that you can rely on the function always returning |
| 14 | # something sane. |
14 | # something sane. |
| 15 | |
15 | |
| 16 | ___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes" |
16 | if [[ ${___ECLASS_ONCE_TOOLCHAIN_FUNCS} != "recur -_+^+_- spank" ]] ; then |
| 17 | [[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib |
17 | ___ECLASS_ONCE_TOOLCHAIN_FUNCS="recur -_+^+_- spank" |
|
|
18 | |
|
|
19 | inherit multilib |
| 18 | |
20 | |
| 19 | DESCRIPTION="Based on the ${ECLASS} eclass" |
21 | DESCRIPTION="Based on the ${ECLASS} eclass" |
| 20 | |
22 | |
| 21 | # tc-getPROG <VAR [search vars]> <default> [tuple] |
23 | # tc-getPROG <VAR [search vars]> <default> [tuple] |
| 22 | _tc-getPROG() { |
24 | _tc-getPROG() { |
| … | |
… | |
| 39 | [[ -n ${search} ]] && prog=${search##*/} |
41 | [[ -n ${search} ]] && prog=${search##*/} |
| 40 | |
42 | |
| 41 | export ${var}=${prog} |
43 | export ${var}=${prog} |
| 42 | echo "${!var}" |
44 | echo "${!var}" |
| 43 | } |
45 | } |
| 44 | tc-getBUILD_PROG() { _tc-getPROG CBUILD "$@"; } |
46 | tc-getBUILD_PROG() { _tc-getPROG CBUILD "BUILD_$1 $1_FOR_BUILD HOST$1" "${@:2}"; } |
| 45 | tc-getPROG() { _tc-getPROG CHOST "$@"; } |
47 | tc-getPROG() { _tc-getPROG CHOST "$@"; } |
| 46 | |
48 | |
| 47 | # @FUNCTION: tc-getAR |
49 | # @FUNCTION: tc-getAR |
| 48 | # @USAGE: [toolchain prefix] |
50 | # @USAGE: [toolchain prefix] |
| 49 | # @RETURN: name of the archiver |
51 | # @RETURN: name of the archiver |
| … | |
… | |
| 107 | # @FUNCTION: tc-getDLLWRAP |
109 | # @FUNCTION: tc-getDLLWRAP |
| 108 | # @USAGE: [toolchain prefix] |
110 | # @USAGE: [toolchain prefix] |
| 109 | # @RETURN: name of the Windows dllwrap utility |
111 | # @RETURN: name of the Windows dllwrap utility |
| 110 | tc-getDLLWRAP() { tc-getPROG DLLWRAP dllwrap "$@"; } |
112 | tc-getDLLWRAP() { tc-getPROG DLLWRAP dllwrap "$@"; } |
| 111 | |
113 | |
|
|
114 | # @FUNCTION: tc-getBUILD_AR |
|
|
115 | # @USAGE: [toolchain prefix] |
|
|
116 | # @RETURN: name of the archiver for building binaries to run on the build machine |
|
|
117 | tc-getBUILD_AR() { tc-getBUILD_PROG AR ar "$@"; } |
|
|
118 | # @FUNCTION: tc-getBUILD_AS |
|
|
119 | # @USAGE: [toolchain prefix] |
|
|
120 | # @RETURN: name of the assembler for building binaries to run on the build machine |
|
|
121 | tc-getBUILD_AS() { tc-getBUILD_PROG AS as "$@"; } |
| 112 | # @FUNCTION: tc-getBUILD_CC |
122 | # @FUNCTION: tc-getBUILD_CC |
| 113 | # @USAGE: [toolchain prefix] |
123 | # @USAGE: [toolchain prefix] |
| 114 | # @RETURN: name of the C compiler for building binaries to run on the build machine |
124 | # @RETURN: name of the C compiler for building binaries to run on the build machine |
| 115 | tc-getBUILD_CC() { tc-getBUILD_PROG "BUILD_CC CC_FOR_BUILD HOSTCC" gcc "$@"; } |
125 | tc-getBUILD_CC() { tc-getBUILD_PROG CC gcc "$@"; } |
| 116 | # @FUNCTION: tc-getBUILD_CPP |
126 | # @FUNCTION: tc-getBUILD_CPP |
| 117 | # @USAGE: [toolchain prefix] |
127 | # @USAGE: [toolchain prefix] |
| 118 | # @RETURN: name of the C preprocessor for building binaries to run on the build machine |
128 | # @RETURN: name of the C preprocessor for building binaries to run on the build machine |
| 119 | tc-getBUILD_CPP() { tc-getBUILD_PROG "BUILD_CPP CPP_FOR_BUILD HOSTCPP" cpp "$@"; } |
129 | tc-getBUILD_CPP() { tc-getBUILD_PROG CPP cpp "$@"; } |
| 120 | # @FUNCTION: tc-getBUILD_CXX |
130 | # @FUNCTION: tc-getBUILD_CXX |
| 121 | # @USAGE: [toolchain prefix] |
131 | # @USAGE: [toolchain prefix] |
| 122 | # @RETURN: name of the C++ compiler for building binaries to run on the build machine |
132 | # @RETURN: name of the C++ compiler for building binaries to run on the build machine |
| 123 | tc-getBUILD_CXX() { tc-getBUILD_PROG "BUILD_CXX CXX_FOR_BUILD HOSTCXX" g++ "$@"; } |
133 | tc-getBUILD_CXX() { tc-getBUILD_PROG CXX g++ "$@"; } |
|
|
134 | # @FUNCTION: tc-getBUILD_LD |
|
|
135 | # @USAGE: [toolchain prefix] |
|
|
136 | # @RETURN: name of the linker for building binaries to run on the build machine |
|
|
137 | tc-getBUILD_LD() { tc-getBUILD_PROG LD ld "$@"; } |
|
|
138 | # @FUNCTION: tc-getBUILD_STRIP |
|
|
139 | # @USAGE: [toolchain prefix] |
|
|
140 | # @RETURN: name of the strip program for building binaries to run on the build machine |
|
|
141 | tc-getBUILD_STRIP() { tc-getBUILD_PROG STRIP strip "$@"; } |
|
|
142 | # @FUNCTION: tc-getBUILD_NM |
|
|
143 | # @USAGE: [toolchain prefix] |
|
|
144 | # @RETURN: name of the symbol/object thingy for building binaries to run on the build machine |
|
|
145 | tc-getBUILD_NM() { tc-getBUILD_PROG NM nm "$@"; } |
|
|
146 | # @FUNCTION: tc-getBUILD_RANLIB |
|
|
147 | # @USAGE: [toolchain prefix] |
|
|
148 | # @RETURN: name of the archiver indexer for building binaries to run on the build machine |
|
|
149 | tc-getBUILD_RANLIB() { tc-getBUILD_PROG RANLIB ranlib "$@"; } |
|
|
150 | # @FUNCTION: tc-getBUILD_OBJCOPY |
|
|
151 | # @USAGE: [toolchain prefix] |
|
|
152 | # @RETURN: name of the object copier for building binaries to run on the build machine |
|
|
153 | tc-getBUILD_OBJCOPY() { tc-getBUILD_PROG OBJCOPY objcopy "$@"; } |
|
|
154 | # @FUNCTION: tc-getBUILD_PKG_CONFIG |
|
|
155 | # @USAGE: [toolchain prefix] |
|
|
156 | # @RETURN: name of the pkg-config tool for building binaries to run on the build machine |
|
|
157 | tc-getBUILD_PKG_CONFIG() { tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"; } |
| 124 | |
158 | |
| 125 | # @FUNCTION: tc-export |
159 | # @FUNCTION: tc-export |
| 126 | # @USAGE: <list of toolchain variables> |
160 | # @USAGE: <list of toolchain variables> |
| 127 | # @DESCRIPTION: |
161 | # @DESCRIPTION: |
| 128 | # Quick way to export a bunch of compiler vars at once. |
162 | # Quick way to export a bunch of compiler vars at once. |
| … | |
… | |
| 143 | # @FUNCTION: tc-is-softfloat |
177 | # @FUNCTION: tc-is-softfloat |
| 144 | # @DESCRIPTION: |
178 | # @DESCRIPTION: |
| 145 | # See if this toolchain is a softfloat based one. |
179 | # See if this toolchain is a softfloat based one. |
| 146 | # @CODE |
180 | # @CODE |
| 147 | # The possible return values: |
181 | # The possible return values: |
| 148 | # - only: the target is always softfloat (never had fpu) |
182 | # - only: the target is always softfloat (never had fpu) |
| 149 | # - yes: the target should support softfloat |
183 | # - yes: the target should support softfloat |
|
|
184 | # - softfp: (arm specific) the target should use hardfloat insns, but softfloat calling convention |
| 150 | # - no: the target doesn't support softfloat |
185 | # - no: the target doesn't support softfloat |
| 151 | # @CODE |
186 | # @CODE |
| 152 | # This allows us to react differently where packages accept |
187 | # This allows us to react differently where packages accept |
| 153 | # softfloat flags in the case where support is optional, but |
188 | # softfloat flags in the case where support is optional, but |
| 154 | # rejects softfloat flags where the target always lacks an fpu. |
189 | # rejects softfloat flags where the target always lacks an fpu. |
| 155 | tc-is-softfloat() { |
190 | tc-is-softfloat() { |
|
|
191 | local CTARGET=${CTARGET:-${CHOST}} |
| 156 | case ${CTARGET} in |
192 | case ${CTARGET} in |
| 157 | bfin*|h8300*) |
193 | bfin*|h8300*) |
| 158 | echo "only" ;; |
194 | echo "only" ;; |
| 159 | *) |
195 | *) |
| 160 | [[ ${CTARGET//_/-} == *-softfloat-* ]] \ |
196 | if [[ ${CTARGET//_/-} == *-softfloat-* ]] ; then |
| 161 | && echo "yes" \ |
197 | echo "yes" |
|
|
198 | elif [[ ${CTARGET//_/-} == *-softfp-* ]] ; then |
|
|
199 | echo "softfp" |
|
|
200 | else |
| 162 | || echo "no" |
201 | echo "no" |
|
|
202 | fi |
| 163 | ;; |
203 | ;; |
| 164 | esac |
204 | esac |
| 165 | } |
|
|
| 166 | |
|
|
| 167 | # @FUNCTION: tc-is-hardfloat |
|
|
| 168 | # @DESCRIPTION: |
|
|
| 169 | # See if this toolchain is a hardfloat based one. |
|
|
| 170 | # @CODE |
|
|
| 171 | # The possible return values: |
|
|
| 172 | # - yes: the target should support hardfloat |
|
|
| 173 | # - no: the target doesn't support hardfloat |
|
|
| 174 | tc-is-hardfloat() { |
|
|
| 175 | [[ ${CTARGET//_/-} == *-hardfloat-* ]] \ |
|
|
| 176 | && echo "yes" \ |
|
|
| 177 | || echo "no" |
|
|
| 178 | } |
205 | } |
| 179 | |
206 | |
| 180 | # @FUNCTION: tc-is-static-only |
207 | # @FUNCTION: tc-is-static-only |
| 181 | # @DESCRIPTION: |
208 | # @DESCRIPTION: |
| 182 | # Return shell true if the target does not support shared libs, shell false |
209 | # Return shell true if the target does not support shared libs, shell false |
| … | |
… | |
| 184 | tc-is-static-only() { |
211 | tc-is-static-only() { |
| 185 | local host=${CTARGET:-${CHOST}} |
212 | local host=${CTARGET:-${CHOST}} |
| 186 | |
213 | |
| 187 | # *MiNT doesn't have shared libraries, only platform so far |
214 | # *MiNT doesn't have shared libraries, only platform so far |
| 188 | return $([[ ${host} == *-mint* ]]) |
215 | return $([[ ${host} == *-mint* ]]) |
|
|
216 | } |
|
|
217 | |
|
|
218 | # @FUNCTION: tc-export_build_env |
|
|
219 | # @USAGE: [compiler variables] |
|
|
220 | # @DESCRIPTION: |
|
|
221 | # Export common build related compiler settings. |
|
|
222 | tc-export_build_env() { |
|
|
223 | tc-export "$@" |
|
|
224 | : ${BUILD_CFLAGS:=-O1 -pipe} |
|
|
225 | : ${BUILD_CXXFLAGS:=-O1 -pipe} |
|
|
226 | : ${BUILD_CPPFLAGS:=} |
|
|
227 | : ${BUILD_LDFLAGS:=} |
|
|
228 | export BUILD_{C,CXX,CPP,LD}FLAGS |
|
|
229 | } |
|
|
230 | |
|
|
231 | # @FUNCTION: tc-env_build |
|
|
232 | # @USAGE: <command> [command args] |
|
|
233 | # @INTERNAL |
|
|
234 | # @DESCRIPTION: |
|
|
235 | # Setup the compile environment to the build tools and then execute the |
|
|
236 | # specified command. We use tc-getBUILD_XX here so that we work with |
|
|
237 | # all of the semi-[non-]standard env vars like $BUILD_CC which often |
|
|
238 | # the target build system does not check. |
|
|
239 | tc-env_build() { |
|
|
240 | tc-export_build_env |
|
|
241 | CFLAGS=${BUILD_CFLAGS} \ |
|
|
242 | CXXFLAGS=${BUILD_CXXFLAGS} \ |
|
|
243 | CPPFLAGS=${BUILD_CPPFLAGS} \ |
|
|
244 | LDFLAGS=${BUILD_LDFLAGS} \ |
|
|
245 | AR=$(tc-getBUILD_AR) \ |
|
|
246 | AS=$(tc-getBUILD_AS) \ |
|
|
247 | CC=$(tc-getBUILD_CC) \ |
|
|
248 | CPP=$(tc-getBUILD_CPP) \ |
|
|
249 | CXX=$(tc-getBUILD_CXX) \ |
|
|
250 | LD=$(tc-getBUILD_LD) \ |
|
|
251 | NM=$(tc-getBUILD_NM) \ |
|
|
252 | PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) \ |
|
|
253 | RANLIB=$(tc-getBUILD_RANLIB) \ |
|
|
254 | "$@" |
|
|
255 | } |
|
|
256 | |
|
|
257 | # @FUNCTION: econf_build |
|
|
258 | # @USAGE: [econf flags] |
|
|
259 | # @DESCRIPTION: |
|
|
260 | # Sometimes we need to locally build up some tools to run on CBUILD because |
|
|
261 | # the package has helper utils which are compiled+executed when compiling. |
|
|
262 | # This won't work when cross-compiling as the CHOST is set to a target which |
|
|
263 | # we cannot natively execute. |
|
|
264 | # |
|
|
265 | # For example, the python package will build up a local python binary using |
|
|
266 | # a portable build system (configure+make), but then use that binary to run |
|
|
267 | # local python scripts to build up other components of the overall python. |
|
|
268 | # We cannot rely on the python binary in $PATH as that often times will be |
|
|
269 | # a different version, or not even installed in the first place. Instead, |
|
|
270 | # we compile the code in a different directory to run on CBUILD, and then |
|
|
271 | # use that binary when compiling the main package to run on CHOST. |
|
|
272 | # |
|
|
273 | # For example, with newer EAPIs, you'd do something like: |
|
|
274 | # @CODE |
|
|
275 | # src_configure() { |
|
|
276 | # ECONF_SOURCE=${S} |
|
|
277 | # if tc-is-cross-compiler ; then |
|
|
278 | # mkdir "${WORKDIR}"/${CBUILD} |
|
|
279 | # pushd "${WORKDIR}"/${CBUILD} >/dev/null |
|
|
280 | # econf_build --disable-some-unused-stuff |
|
|
281 | # popd >/dev/null |
|
|
282 | # fi |
|
|
283 | # ... normal build paths ... |
|
|
284 | # } |
|
|
285 | # src_compile() { |
|
|
286 | # if tc-is-cross-compiler ; then |
|
|
287 | # pushd "${WORKDIR}"/${CBUILD} >/dev/null |
|
|
288 | # emake one-or-two-build-tools |
|
|
289 | # ln/mv build-tools to normal build paths in ${S}/ |
|
|
290 | # popd >/dev/null |
|
|
291 | # fi |
|
|
292 | # ... normal build paths ... |
|
|
293 | # } |
|
|
294 | # @CODE |
|
|
295 | econf_build() { |
|
|
296 | tc-env_build econf --build=${CBUILD:-${CHOST}} "$@" |
| 189 | } |
297 | } |
| 190 | |
298 | |
| 191 | # @FUNCTION: tc-has-openmp |
299 | # @FUNCTION: tc-has-openmp |
| 192 | # @USAGE: [toolchain prefix] |
300 | # @USAGE: [toolchain prefix] |
| 193 | # @DESCRIPTION: |
301 | # @DESCRIPTION: |
| … | |
… | |
| 658 | ;; |
766 | ;; |
| 659 | esac |
767 | esac |
| 660 | fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}" |
768 | fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}" |
| 661 | done |
769 | done |
| 662 | } |
770 | } |
|
|
771 | |
|
|
772 | fi |