/[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 1171 - (show annotations) (download)
Sun Mar 26 23:01:39 2006 UTC (13 years ago) by kito
File size: 10879 byte(s)
fix DESTDIR target
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.57 2006/03/18 22:30:10 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
49 DESCRIPTION="Tools necessary to build programs"
50 HOMEPAGE="http://sources.redhat.com/binutils/"
51
52 case ${BTYPE} in
53 cvs) SRC_URI="";;
54 snap) SRC_URI="ftp://gcc.gnu.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2";;
55 rel)
56 SRC_URI="mirror://kernel/linux/devel/binutils/binutils-${PV}.tar.bz2
57 mirror://kernel/linux/devel/binutils/test/binutils-${PV}.tar.bz2
58 mirror://gnu/binutils/binutils-${PV}.tar.bz2"
59 esac
60 [[ -n ${PATCHVER} ]] && \
61 SRC_URI="${SRC_URI} mirror://gentoo/binutils-${PV}-patches-${PATCHVER}.tar.bz2"
62 [[ -n ${UCLIBC_PATCHVER} ]] && \
63 SRC_URI="${SRC_URI} mirror://gentoo/binutils-${PV}-uclibc-patches-${UCLIBC_PATCHVER}.tar.bz2"
64 [[ -n ${ELF2FLT_VER} ]] && \
65 SRC_URI="${SRC_URI} mirror://gentoo/elf2flt-${ELF2FLT_VER}.tar.bz2"
66
67 LICENSE="|| ( GPL-2 LGPL-2 )"
68 IUSE="nls multitarget multislot test vanilla"
69 if use multislot ; then
70 SLOT="${CTARGET}-${BVER}"
71 elif [[ ${CTARGET} != ${CHOST} ]] ; then
72 SLOT="${CTARGET}"
73 else
74 SLOT="0"
75 fi
76
77 RDEPEND=">=sys-devel/binutils-config-1.8-r6"
78 DEPEND="${RDEPEND}
79 test? ( dev-util/dejagnu )
80 nls? ( sys-devel/gettext )"
81
82 S=${WORKDIR}/binutils
83 [[ ${BVER} != "cvs" ]] && S=${S}-${BVER}
84
85 LIBPATH=${EPREFIX}/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
86 INCPATH=${LIBPATH}/include
87 BINPATH=${EPREFIX}/usr/${CTARGET}/binutils-bin/${BVER}
88 DATAPATH=${EPREFIX}/usr/share/binutils-data/${CTARGET}/${BVER}
89 MY_BUILDDIR=${WORKDIR}/build
90
91 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
92
93 tc-binutils_unpack() {
94 unpack ${A}
95 mkdir -p "${MY_BUILDDIR}"
96 [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
97 }
98
99 tc-binutils_apply_patches() {
100 cd "${S}"
101
102 if ! use vanilla && [[ -n ${PATCHVER} ]] ; then
103 EPATCH_SOURCE=${WORKDIR}/patch
104 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
105 && EPATCH_SUFFIX="patch.bz2" \
106 || EPATCH_SUFFIX="patch"
107 epatch
108 fi
109 if ! use vanilla && [[ -n ${UCLIBC_PATCHVER} ]] ; then
110 EPATCH_SOURCE=${WORKDIR}/uclibc-patches
111 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
112 && EPATCH_SUFFIX="patch.bz2" \
113 || EPATCH_SUFFIX="patch"
114 EPATCH_MULTI_MSG="Applying uClibc fixes ..." \
115 epatch
116 elif [[ ${CTARGET} == *-uclibc ]] ; then
117 die "sorry, but this binutils doesn't yet support uClibc :("
118 fi
119
120 # Fix po Makefile generators
121 sed -i \
122 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
123 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
124 */po/Make-in || die "sed po's failed"
125
126 # Run misc portage update scripts
127 gnuconfig_update
128 elibtoolize --portage --no-uclibc
129
130 # make sure we filter $LINGUAS so that only ones that
131 # actually work make it through #42033
132 strip-linguas -u */po
133 }
134
135 toolchain-binutils_src_unpack() {
136 tc-binutils_unpack
137 tc-binutils_apply_patches
138 }
139
140 toolchain-binutils_src_compile() {
141 strip-flags && replace-flags -O3 -O2 #47581
142
143 local x
144 echo
145 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
146 einfo "$(printf '%10s' ${x}:) ${!x}"
147 done
148 echo
149
150 cd "${MY_BUILDDIR}"
151 local myconf=""
152 use nls \
153 && myconf="${myconf} --without-included-gettext" \
154 || myconf="${myconf} --disable-nls"
155 use multitarget && myconf="${myconf} --enable-targets=all"
156 [[ -n ${CBUILD} ]] && myconf="${myconf} --build=${CBUILD}"
157 is_cross && myconf="${myconf} --with-sysroot=${EPREFIX}/usr/${CTARGET}"
158 myconf="--prefix=${EPREFIX}/usr \
159 --host=${CHOST} \
160 --target=${CTARGET} \
161 --datadir=${DATAPATH} \
162 --infodir=${DATAPATH}/info \
163 --mandir=${DATAPATH}/man \
164 --bindir=${BINPATH} \
165 --libdir=${LIBPATH} \
166 --libexecdir=${LIBPATH} \
167 --includedir=${INCPATH} \
168 --enable-64-bit-bfd \
169 --enable-shared \
170 --disable-werror \
171 ${myconf} ${EXTRA_ECONF}"
172 echo ./configure ${myconf}
173 "${S}"/configure ${myconf} || die "configure failed"
174
175 # binutils' build system is a bit broken with internal
176 # dependencies, so we manually run these first two bfd
177 # targets so that we can than use -j# and have it work
178 emake -j1 configure-bfd || die "make configure-bfd failed"
179 emake -j1 headers -C bfd || die "make headers-bfd failed"
180 emake all || die "emake failed"
181
182 # only build info pages if we user wants them, and if
183 # we have makeinfo (may not exist when we bootstrap)
184 if ! has noinfo ${FEATURES} ; then
185 if type -p makeinfo ; then
186 make info || die "make info failed"
187 fi
188 fi
189 # we nuke the manpages when we're left with junk
190 # (like when we bootstrap, no perl -> no manpages)
191 find . -name '*.1' -a -size 0 | xargs rm -f
192
193 # elf2flt only works on some arches / targets
194 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
195 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
196
197 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
198 for x in ${supported_arches} UNSUPPORTED ; do
199 [[ ${CTARGET} == ${x}* ]] && break
200 done
201
202 if [[ ${x} != "UNSUPPORTED" ]] ; then
203 append-flags -I"${S}"/include
204 myconf="--with-bfd-include-dir=${MY_BUILDDIR}/bfd \
205 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a \
206 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a \
207 --with-binutils-ldscript-dir=${LIBPATH}/ldscripts \
208 ${myconf}"
209 echo ./configure ${myconf}
210 ./configure ${myconf} || die "configure elf2flt failed"
211 emake || die "make elf2flt failed"
212 fi
213 fi
214 }
215
216 toolchain-binutils_src_test() {
217 cd "${MY_BUILDDIR}"
218 make check || die "check failed :("
219 }
220
221 toolchain-binutils_src_install() {
222 local x d
223
224 cd "${MY_BUILDDIR}"
225 make DESTDIR="${EDEST}" tooldir="${LIBPATH}" install || die
226 rm -rf "${D}"/${LIBPATH}/bin
227
228 # Now we collect everything intp the proper SLOT-ed dirs
229 # When something is built to cross-compile, it installs into
230 # /usr/$CHOST/ by default ... we have to 'fix' that :)
231 if is_cross ; then
232 cd "${D}"/${BINPATH}
233 for x in * ; do
234 mv ${x} ${x/${CTARGET}-}
235 done
236
237 if [[ -d ${D}/usr/${CHOST}/${CTARGET} ]] ; then
238 mv "${D}"/usr/${CHOST}/${CTARGET}/include "${D}"/${INCPATH}
239 mv "${D}"/usr/${CHOST}/${CTARGET}/lib/* "${D}"/${LIBPATH}/
240 rm -r "${D}"/usr/${CHOST}
241 fi
242 else
243 insinto ${INCPATH}
244 doins "${S}/include/libiberty.h"
245 fi
246 if [[ -d ${D}/${LIBPATH}/lib ]] ; then
247 mv "${D}"/${LIBPATH}/lib/* "${D}"/${LIBPATH}/
248 rm -r "${D}"/${LIBPATH}/lib
249 fi
250 dodir /usr/${CTARGET}/{bin,include,lib}
251 prepman ${DATAPATH}
252
253 # Insert elf2flt where appropriate
254 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
255 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
256 insinto ${LIBPATH}/ldscripts
257 doins elf2flt.ld || die "doins elf2flt.ld failed"
258 exeinto ${BINPATH}
259 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
260 mv "${D}"/${BINPATH}/{ld,ld.real} || die
261 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
262 newdoc README README.elf2flt
263 fi
264
265 # Now, some binutils are tricky and actually provide
266 # for multiple TARGETS. Really, we're talking just
267 # 32bit/64bit support (like mips/ppc/sparc). Here
268 # we want to tell binutils-config that it's cool if
269 # it generates multiple sets of binutil symlinks.
270 # e.g. sparc gets {sparc,sparc64}-unknown-linux-gnu
271 local targ=${CTARGET/-*} src="" dst=""
272 local FAKE_TARGETS=${CTARGET}
273 case ${targ} in
274 mips*) src="mips" dst="mips64";;
275 powerpc*) src="powerpc" dst="powerpc64";;
276 s390*) src="s390" dst="s390x";;
277 sparc*) src="sparc" dst="sparc64";;
278 esac
279 case ${targ} in
280 mips64*|powerpc64*|s390x*|sparc64*) targ=${src} src=${dst} dst=${targ};;
281 esac
282 [[ -n ${src}${dst} ]] && FAKE_TARGETS="${FAKE_TARGETS} ${CTARGET/${src}/${dst}}"
283
284 # Generate an env.d entry for this binutils
285 cd "${S}"
286 insinto /etc/env.d/binutils
287 cat <<-EOF > env.d
288 TARGET="${CTARGET}"
289 VER="${BVER}"
290 LIBPATH="${LIBPATH}"
291 FAKE_TARGETS="${FAKE_TARGETS}"
292 EOF
293 newins env.d ${CTARGET}-${BVER}
294
295 # Handle documentation
296 if ! is_cross ; then
297 cd "${S}"
298 dodoc README
299 docinto bfd
300 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
301 docinto binutils
302 dodoc binutils/ChangeLog binutils/NEWS binutils/README
303 docinto gas
304 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
305 docinto gprof
306 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
307 docinto ld
308 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
309 docinto libiberty
310 dodoc libiberty/ChangeLog* libiberty/README
311 docinto opcodes
312 dodoc opcodes/ChangeLog*
313 fi
314 # Punt all the fun stuff if user doesn't want it :)
315 has noinfo ${FEATURES} && rm -r "${D}"/${DATAPATH}/info
316 has noman ${FEATURES} && rm -r "${D}"/${DATAPATH}/man
317 # Remove shared info pages
318 rm -f "${D}"/${DATAPATH}/info/{dir,configure.info,standards.info}
319 }
320
321 toolchain-binutils_pkg_postinst() {
322 # Make sure this ${CTARGET} has a binutils version selected
323 [[ -e ${ROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
324 binutils-config ${CTARGET}-${BVER}
325 }
326
327 toolchain-binutils_pkg_postrm() {
328 local current_profile=$(binutils-config -c ${CTARGET})
329
330 # If no other versions exist, then uninstall for this
331 # target ... otherwise, switch to the newest version
332 # Note: only do this if this version is unmerged. We
333 # rerun binutils-config if this is a remerge, as
334 # we want the mtimes on the symlinks updated (if
335 # it is the same as the current selected profile)
336 if [[ ! -e ${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
337 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
338 choice=${choice//$'\n'/ }
339 choice=${choice/* }
340 if [[ -z ${choice} ]] ; then
341 env -i binutils-config -u ${CTARGET}
342 else
343 binutils-config ${choice}
344 fi
345 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
346 binutils-config ${CTARGET}-${BVER}
347 fi
348 }

  ViewVC Help
Powered by ViewVC 1.1.20