/[gentoo-alt]/trunk/prefix/eclass/toolchain-binutils.eclass
Gentoo

Contents of /trunk/prefix/eclass/toolchain-binutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1410 - (show annotations) (download)
Sat Sep 9 17:19:59 2006 UTC (7 years, 10 months ago) by grobian
File size: 11465 byte(s)
typo:wq



1 # Copyright 1999-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-binutils.eclass,v 1.65 2006/08/31 18:22:08 vapier Exp $
4
5 # We install binutils into CTARGET-VERSION specific directories. This lets
6 # us easily merge multiple versions for multiple targets (if we wish) and
7 # then switch the versions on the fly (with `binutils-config`).
8 #
9 # binutils-9999 -> live cvs
10 # binutils-9999_preYYMMDD -> nightly snapshot date YYMMDD
11 # binutils-# -> normal release
12
13 extra_eclass=""
14 if [[ -n ${BINUTILS_TYPE} ]] ; then
15 BTYPE=${BINUTILS_TYPE}
16 else
17 case ${PV} in
18 9999) BTYPE="cvs";;
19 9999_pre*) BTYPE="snap";;
20 *) BTYPE="rel";;
21 esac
22 fi
23
24 if [[ ${BTYPE} == "cvs" ]] ; then
25 extra_eclass="cvs"
26 ECVS_SERVER="sourceware.org:/cvs/src"
27 ECVS_MODULE="binutils"
28 ECVS_USER="anoncvs"
29 ECVS_PASS="anoncvs"
30 BVER="cvs"
31 elif [[ ${BTYPE} == "snap" ]] ; then
32 BVER=${PV/9999_pre}
33 elif [[ ${BTYPE} == "rel" ]] ; then
34 BVER=${PV}
35 else
36 BVER=${BINUTILS_VER}
37 fi
38
39 inherit eutils libtool flag-o-matic gnuconfig multilib ${extra_eclass}
40 EXPORT_FUNCTIONS src_unpack src_compile src_test src_install pkg_postinst pkg_postrm
41
42 export CTARGET=${CTARGET:-${CHOST}}
43 if [[ ${CTARGET} == ${CHOST} ]] ; then
44 if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
45 export CTARGET=${CATEGORY/cross-}
46 fi
47 fi
48 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
49
50 DESCRIPTION="Tools necessary to build programs"
51 HOMEPAGE="http://sources.redhat.com/binutils/"
52
53 case ${BTYPE} in
54 cvs) SRC_URI="";;
55 snap) SRC_URI="ftp://gcc.gnu.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2";;
56 rel)
57 SRC_URI="mirror://kernel/linux/devel/binutils/binutils-${PV}.tar.bz2
58 mirror://kernel/linux/devel/binutils/test/binutils-${PV}.tar.bz2
59 mirror://gnu/binutils/binutils-${PV}.tar.bz2"
60 esac
61 [[ -n ${PATCHVER} ]] && \
62 SRC_URI="${SRC_URI} mirror://gentoo/binutils-${PV}-patches-${PATCHVER}.tar.bz2"
63 [[ -n ${UCLIBC_PATCHVER} ]] && \
64 SRC_URI="${SRC_URI} mirror://gentoo/binutils-${PV}-uclibc-patches-${UCLIBC_PATCHVER}.tar.bz2"
65 [[ -n ${ELF2FLT_VER} ]] && \
66 SRC_URI="${SRC_URI} mirror://gentoo/elf2flt-${ELF2FLT_VER}.tar.bz2"
67
68 LICENSE="|| ( GPL-2 LGPL-2 )"
69 IUSE="nls multitarget multislot test vanilla"
70 if use multislot ; then
71 SLOT="${CTARGET}-${BVER}"
72 elif is_cross ; then
73 SLOT="${CTARGET}"
74 else
75 SLOT="0"
76 fi
77
78 if is_cross ; then
79 RDEPEND=">=sys-devel/binutils-config-1.9"
80 else
81 RDEPEND=">=sys-devel/binutils-config-1.8-r6"
82 fi
83 DEPEND="${RDEPEND}
84 test? ( dev-util/dejagnu )
85 nls? ( sys-devel/gettext )"
86
87 S=${WORKDIR}/binutils
88 [[ ${BVER} != "cvs" ]] && S=${S}-${BVER}
89
90 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
91 INCPATH=${LIBPATH}/include
92 DATAPATH=/usr/share/binutils-data/${CTARGET}/${BVER}
93 MY_BUILDDIR=${WORKDIR}/build
94 if is_cross ; then
95 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
96 else
97 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
98 fi
99
100 tc-binutils_unpack() {
101 unpack ${A}
102 mkdir -p "${MY_BUILDDIR}"
103 [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
104 }
105
106 tc-binutils_apply_patches() {
107 cd "${S}"
108
109 if ! use vanilla && [[ -n ${PATCHVER} ]] ; then
110 EPATCH_SOURCE=${WORKDIR}/patch
111 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
112 && EPATCH_SUFFIX="patch.bz2" \
113 || EPATCH_SUFFIX="patch"
114 epatch
115 fi
116 if ! use vanilla && [[ -n ${UCLIBC_PATCHVER} ]] ; then
117 EPATCH_SOURCE=${WORKDIR}/uclibc-patches
118 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
119 && EPATCH_SUFFIX="patch.bz2" \
120 || EPATCH_SUFFIX="patch"
121 EPATCH_MULTI_MSG="Applying uClibc fixes ..." \
122 epatch
123 elif [[ ${CTARGET} == *-uclibc ]] ; then
124 die "sorry, but this binutils doesn't yet support uClibc :("
125 fi
126
127 # fix locale issues if possible #122216
128 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
129 einfo "Fixing misc issues in configure files"
130 for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
131 ebegin " Updating ${f/${S}\/}"
132 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
133 || eerror "Please file a bug about this"
134 eend $?
135 done
136 fi
137
138 # Fix po Makefile generators
139 sed -i \
140 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
141 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
142 */po/Make-in || die "sed po's failed"
143
144 # Run misc portage update scripts
145 gnuconfig_update
146 elibtoolize --portage --no-uclibc
147 }
148
149 toolchain-binutils_src_unpack() {
150 is_cross && [[ $(binutils-config -V) != binutils-config-1.9* ]] \
151 && die "You need to upgrade your binutils-config to 1.9 or newer"
152
153 tc-binutils_unpack
154 tc-binutils_apply_patches
155 }
156
157 toolchain-binutils_src_compile() {
158 # make sure we filter $LINGUAS so that only ones that
159 # actually work make it through #42033
160 strip-linguas -u */po
161
162 # keep things sane
163 strip-flags
164
165 local x
166 echo
167 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
168 einfo "$(printf '%10s' ${x}:) ${!x}"
169 done
170 echo
171
172 cd "${MY_BUILDDIR}"
173 local myconf=""
174 use nls \
175 && myconf="${myconf} --without-included-gettext" \
176 || myconf="${myconf} --disable-nls"
177 use multitarget && myconf="${myconf} --enable-targets=all"
178 [[ -n ${CBUILD} ]] && myconf="${myconf} --build=${CBUILD}"
179 is_cross && myconf="${myconf} --with-sysroot=${EPREFIX}/usr/${CTARGET}"
180 is_cross || myconf="${myconf} --with-sysroot=${EPREFIX}"
181 myconf="--prefix=${EPREFIX}/usr \
182 --host=${CHOST} \
183 --target=${CTARGET} \
184 --datadir=${EPREFIX}/${DATAPATH} \
185 --infodir=${EPREFIX}/${DATAPATH}/info \
186 --mandir=${EPREFIX}/${DATAPATH}/man \
187 --bindir=${EPREFIX}/${BINPATH} \
188 --libdir=${EPREFIX}/${LIBPATH} \
189 --libexecdir=${EPREFIX}/${LIBPATH} \
190 --includedir=${EPREFIX}/${INCPATH} \
191 --enable-64-bit-bfd \
192 --enable-shared \
193 --disable-werror \
194 ${myconf} ${EXTRA_ECONF}"
195 echo ./configure ${myconf}
196 "${S}"/configure ${myconf} || die "configure failed"
197
198 emake all || die "emake failed"
199
200 # only build info pages if we user wants them, and if
201 # we have makeinfo (may not exist when we bootstrap)
202 if ! has noinfo ${FEATURES} ; then
203 if type -p makeinfo > /dev/null ; then
204 make info || die "make info failed"
205 fi
206 fi
207 # we nuke the manpages when we're left with junk
208 # (like when we bootstrap, no perl -> no manpages)
209 find . -name '*.1' -a -size 0 | xargs rm -f
210
211 # elf2flt only works on some arches / targets
212 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
213 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
214
215 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
216 for x in ${supported_arches} UNSUPPORTED ; do
217 [[ ${CTARGET} == ${x}* ]] && break
218 done
219
220 if [[ ${x} != "UNSUPPORTED" ]] ; then
221 append-flags -I"${S}"/include
222 myconf="--with-bfd-include-dir=${MY_BUILDDIR}/bfd \
223 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a \
224 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a \
225 --with-binutils-ldscript-dir=${EPREFIX}/${LIBPATH}/ldscripts \
226 ${myconf}"
227 echo ./configure ${myconf}
228 ./configure ${myconf} || die "configure elf2flt failed"
229 emake || die "make elf2flt failed"
230 fi
231 fi
232 }
233
234 toolchain-binutils_src_test() {
235 cd "${MY_BUILDDIR}"
236 make check || die "check failed :("
237 }
238
239 toolchain-binutils_src_install() {
240 local x d
241
242 cd "${MY_BUILDDIR}"
243 make DESTDIR="${EDEST}" tooldir="${D}/${LIBPATH}" install || die
244 rm -rf "${D}"/${LIBPATH}/bin
245
246 # Now we collect everything intp the proper SLOT-ed dirs
247 # When something is built to cross-compile, it installs into
248 # /usr/$CHOST/ by default ... we have to 'fix' that :)
249 if is_cross ; then
250 cd "${D}"/${BINPATH}
251 for x in * ; do
252 mv ${x} ${x/${CTARGET}-}
253 done
254
255 if [[ -d ${D}/usr/${CHOST}/${CTARGET} ]] ; then
256 mv "${D}"/usr/${CHOST}/${CTARGET}/include "${D}"/${INCPATH}
257 mv "${D}"/usr/${CHOST}/${CTARGET}/lib/* "${D}"/${LIBPATH}/
258 rm -r "${D}"/usr/${CHOST}/{include,lib}
259 fi
260 else
261 insinto ${INCPATH}
262 doins "${S}/include/libiberty.h"
263 fi
264 if [[ -d ${D}/${LIBPATH}/lib ]] ; then
265 mv "${D}"/${LIBPATH}/lib/* "${D}"/${LIBPATH}/
266 rm -r "${D}"/${LIBPATH}/lib
267 fi
268 prepman ${DATAPATH}
269
270 # Insert elf2flt where appropriate
271 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
272 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
273 insinto ${LIBPATH}/ldscripts
274 doins elf2flt.ld || die "doins elf2flt.ld failed"
275 exeinto ${BINPATH}
276 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
277 mv "${D}"/${BINPATH}/{ld,ld.real} || die
278 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
279 newdoc README README.elf2flt
280 fi
281
282 # Now, some binutils are tricky and actually provide
283 # for multiple TARGETS. Really, we're talking just
284 # 32bit/64bit support (like mips/ppc/sparc). Here
285 # we want to tell binutils-config that it's cool if
286 # it generates multiple sets of binutil symlinks.
287 # e.g. sparc gets {sparc,sparc64}-unknown-linux-gnu
288 local targ=${CTARGET/-*} src="" dst=""
289 local FAKE_TARGETS=${CTARGET}
290 case ${targ} in
291 mips*) src="mips" dst="mips64";;
292 powerpc*) src="powerpc" dst="powerpc64";;
293 s390*) src="s390" dst="s390x";;
294 sparc*) src="sparc" dst="sparc64";;
295 esac
296 case ${targ} in
297 mips64*|powerpc64*|s390x*|sparc64*) targ=${src} src=${dst} dst=${targ};;
298 esac
299 [[ -n ${src}${dst} ]] && FAKE_TARGETS="${FAKE_TARGETS} ${CTARGET/${src}/${dst}}"
300
301 # Generate an env.d entry for this binutils
302 cd "${S}"
303 insinto /etc/env.d/binutils
304 cat <<-EOF > env.d
305 TARGET="${CTARGET}"
306 VER="${BVER}"
307 LIBPATH="${EPREFIX}/${LIBPATH}"
308 FAKE_TARGETS="${FAKE_TARGETS}"
309 EOF
310 newins env.d ${CTARGET}-${BVER}
311
312 # Handle documentation
313 if ! is_cross ; then
314 cd "${S}"
315 dodoc README
316 docinto bfd
317 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
318 docinto binutils
319 dodoc binutils/ChangeLog binutils/NEWS binutils/README
320 docinto gas
321 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
322 docinto gprof
323 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
324 docinto ld
325 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
326 docinto libiberty
327 dodoc libiberty/ChangeLog* libiberty/README
328 docinto opcodes
329 dodoc opcodes/ChangeLog*
330 fi
331 # Punt all the fun stuff if user doesn't want it :)
332 has noinfo ${FEATURES} && rm -r "${D}"/${DATAPATH}/info
333 has noman ${FEATURES} && rm -r "${D}"/${DATAPATH}/man
334 # Remove shared info pages
335 rm -f "${D}"/${DATAPATH}/info/{dir,configure.info,standards.info}
336 # Trim all empty dirs
337 find "${D}" -type d | xargs rmdir >& /dev/null
338 }
339
340 toolchain-binutils_pkg_postinst() {
341 # Make sure this ${CTARGET} has a binutils version selected
342 [[ -e ${ROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
343 binutils-config ${CTARGET}-${BVER}
344 }
345
346 toolchain-binutils_pkg_postrm() {
347 local current_profile=$(binutils-config -c ${CTARGET})
348
349 # If no other versions exist, then uninstall for this
350 # target ... otherwise, switch to the newest version
351 # Note: only do this if this version is unmerged. We
352 # rerun binutils-config if this is a remerge, as
353 # we want the mtimes on the symlinks updated (if
354 # it is the same as the current selected profile)
355 if [[ ! -e ${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
356 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
357 choice=${choice//$'\n'/ }
358 choice=${choice/* }
359 if [[ -z ${choice} ]] ; then
360 env -i binutils-config -u ${CTARGET}
361 else
362 binutils-config ${choice}
363 fi
364 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
365 binutils-config ${CTARGET}-${BVER}
366 fi
367 }

  ViewVC Help
Powered by ViewVC 1.1.20