toolchain-binutils.eclass 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. #
  4. # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
  5. #
  6. # We install binutils into CTARGET-VERSION specific directories. This lets
  7. # us easily merge multiple versions for multiple targets (if we wish) and
  8. # then switch the versions on the fly (with `binutils-config`).
  9. #
  10. # binutils-9999 -> live git
  11. # binutils-9999_preYYMMDD -> nightly snapshot date YYMMDD
  12. # binutils-# -> normal release
  13. if [[ -n ${BINUTILS_TYPE} ]] ; then
  14. BTYPE=${BINUTILS_TYPE}
  15. else
  16. case ${PV} in
  17. 9999) BTYPE="git";;
  18. 9999_pre*) BTYPE="snap";;
  19. *.*.90) BTYPE="snap";;
  20. *.*.*.*.*) BTYPE="hjlu";;
  21. *) BTYPE="rel";;
  22. esac
  23. fi
  24. case ${BTYPE} in
  25. git)
  26. BVER="git"
  27. EGIT_REPO_URI="git://sourceware.org/git/binutils-gdb.git"
  28. inherit git-2
  29. ;;
  30. snap)
  31. BVER=${PV/9999_pre}
  32. ;;
  33. *)
  34. BVER=${BINUTILS_VER:-${PV}}
  35. ;;
  36. esac
  37. inherit eutils libtool flag-o-matic gnuconfig multilib versionator unpacker
  38. case ${EAPI:-0} in
  39. 0|1)
  40. EXPORT_FUNCTIONS src_unpack src_compile src_test src_install pkg_postinst pkg_postrm ;;
  41. 2|3|4|5)
  42. EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_postinst pkg_postrm ;;
  43. *) die "unsupported EAPI ${EAPI}" ;;
  44. esac
  45. export CTARGET=${CTARGET:-${CHOST}}
  46. if [[ ${CTARGET} == ${CHOST} ]] ; then
  47. if [[ ${CATEGORY} == cross-* ]] ; then
  48. export CTARGET=${CATEGORY#cross-}
  49. fi
  50. fi
  51. is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
  52. DESCRIPTION="Tools necessary to build programs"
  53. HOMEPAGE="https://sourceware.org/binutils/"
  54. case ${BTYPE} in
  55. git) SRC_URI="" ;;
  56. snap)
  57. SRC_URI="ftp://gcc.gnu.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2
  58. ftp://sourceware.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2" ;;
  59. hjlu)
  60. SRC_URI="mirror://kernel/linux/devel/binutils/binutils-${BVER}.tar."
  61. version_is_at_least 2.21.51.0.5 && SRC_URI+="xz" || SRC_URI+="bz2" ;;
  62. rel) SRC_URI="mirror://gnu/binutils/binutils-${BVER}.tar.bz2" ;;
  63. esac
  64. add_src_uri() {
  65. [[ -z $2 ]] && return
  66. local a=$1
  67. if version_is_at_least 2.22.52.0.2 ; then
  68. a+=".xz"
  69. else
  70. a+=".bz2"
  71. fi
  72. set -- mirror://gentoo https://dev.gentoo.org/~vapier/dist
  73. SRC_URI="${SRC_URI} ${@/%//${a}}"
  74. }
  75. add_src_uri binutils-${BVER}-patches-${PATCHVER}.tar ${PATCHVER}
  76. add_src_uri binutils-${BVER}-uclibc-patches-${UCLIBC_PATCHVER}.tar ${UCLIBC_PATCHVER}
  77. add_src_uri elf2flt-${ELF2FLT_VER}.tar ${ELF2FLT_VER}
  78. if version_is_at_least 2.18 ; then
  79. LICENSE="|| ( GPL-3 LGPL-3 )"
  80. else
  81. LICENSE="|| ( GPL-2 LGPL-2 )"
  82. fi
  83. IUSE="cxx multitarget nls static-libs test vanilla"
  84. if version_is_at_least 2.19 && ! version_is_at_least 2.26 ; then
  85. IUSE+=" zlib"
  86. fi
  87. SLOT="${BVER}"
  88. RDEPEND=">=sys-devel/binutils-config-3"
  89. if in_iuse zlib ; then
  90. RDEPEND+=" zlib? ( sys-libs/zlib )"
  91. elif version_is_at_least 2.26 ; then
  92. RDEPEND+=" sys-libs/zlib"
  93. fi
  94. DEPEND="${RDEPEND}
  95. test? ( dev-util/dejagnu )
  96. nls? ( sys-devel/gettext )
  97. sys-devel/flex
  98. virtual/yacc"
  99. if is_cross ; then
  100. # The build assumes the host has libiberty and such when cross-compiling
  101. # its build tools. We should probably make binutils itself build a local
  102. # copy to use, but until then, be lazy.
  103. DEPEND+=" >=sys-libs/binutils-libs-${PV}"
  104. fi
  105. S=${WORKDIR}/binutils
  106. case ${BVER} in
  107. git) ;;
  108. *) S=${S}-${BVER} ;;
  109. esac
  110. LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
  111. INCPATH=${LIBPATH}/include
  112. DATAPATH=/usr/share/binutils-data/${CTARGET}/${BVER}
  113. MY_BUILDDIR=${WORKDIR}/build
  114. if is_cross ; then
  115. BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
  116. else
  117. BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
  118. fi
  119. tc-binutils_unpack() {
  120. case ${BTYPE} in
  121. git) git-2_src_unpack ;;
  122. *) unpacker ${A} ;;
  123. esac
  124. mkdir -p "${MY_BUILDDIR}"
  125. [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
  126. }
  127. # In case the ebuild wants to add a few of their own.
  128. PATCHES=()
  129. tc-binutils_apply_patches() {
  130. cd "${S}"
  131. if ! use vanilla ; then
  132. if [[ -n ${PATCHVER} ]] ; then
  133. EPATCH_SOURCE=${WORKDIR}/patch
  134. if [[ ${CTARGET} == mips* ]] ; then
  135. # remove gnu-hash for mips (bug #233233)
  136. EPATCH_EXCLUDE+=" 77_all_generate-gnu-hash.patch"
  137. fi
  138. [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
  139. && EPATCH_SUFFIX="patch.bz2" \
  140. || EPATCH_SUFFIX="patch"
  141. epatch
  142. fi
  143. if [[ -n ${UCLIBC_PATCHVER} ]] ; then
  144. EPATCH_SOURCE=${WORKDIR}/uclibc-patches
  145. [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
  146. && EPATCH_SUFFIX="patch.bz2" \
  147. || EPATCH_SUFFIX="patch"
  148. EPATCH_MULTI_MSG="Applying uClibc fixes ..." \
  149. epatch
  150. elif [[ ${CTARGET} == *-uclibc* ]] ; then
  151. # starting with binutils-2.17.50.0.17, we no longer need
  152. # uClibc patchsets :D
  153. if grep -qs 'linux-gnu' "${S}"/ltconfig ; then
  154. die "sorry, but this binutils doesn't yet support uClibc :("
  155. fi
  156. fi
  157. [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
  158. # Make sure our explicit libdir paths don't get clobbered. #562460
  159. sed -i \
  160. -e 's:@bfdlibdir@:@libdir@:g' \
  161. -e 's:@bfdincludedir@:@includedir@:g' \
  162. {bfd,opcodes}/Makefile.in || die
  163. epatch_user
  164. fi
  165. # fix locale issues if possible #122216
  166. if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
  167. einfo "Fixing misc issues in configure files"
  168. for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
  169. ebegin " Updating ${f/${S}\/}"
  170. patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
  171. || eerror "Please file a bug about this"
  172. eend $?
  173. done
  174. fi
  175. # fix conflicts with newer glibc #272594
  176. if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
  177. sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
  178. fi
  179. # Fix po Makefile generators
  180. sed -i \
  181. -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
  182. -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
  183. */po/Make-in || die "sed po's failed"
  184. # Run misc portage update scripts
  185. gnuconfig_update
  186. elibtoolize --portage --no-uclibc
  187. }
  188. toolchain-binutils_src_unpack() {
  189. tc-binutils_unpack
  190. case ${EAPI:-0} in
  191. 0|1) toolchain-binutils_src_prepare ;;
  192. esac
  193. }
  194. toolchain-binutils_src_prepare() {
  195. tc-binutils_apply_patches
  196. }
  197. _eprefix_init() {
  198. has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
  199. }
  200. # Intended for ebuilds to override to set their own versioning information.
  201. toolchain-binutils_bugurl() {
  202. printf "https://bugs.gentoo.org/"
  203. }
  204. toolchain-binutils_pkgversion() {
  205. printf "Gentoo ${BVER}"
  206. [[ -n ${PATCHVER} ]] && printf " p${PATCHVER}"
  207. }
  208. toolchain-binutils_src_configure() {
  209. _eprefix_init
  210. # make sure we filter $LINGUAS so that only ones that
  211. # actually work make it through #42033
  212. strip-linguas -u */po
  213. # keep things sane
  214. strip-flags
  215. local x
  216. echo
  217. for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
  218. einfo "$(printf '%10s' ${x}:) ${!x}"
  219. done
  220. echo
  221. cd "${MY_BUILDDIR}"
  222. local myconf=()
  223. # enable gold if available (installed as ld.gold)
  224. if use cxx ; then
  225. if grep -q 'enable-gold=default' "${S}"/configure ; then
  226. myconf+=( --enable-gold )
  227. # old ways - remove when 2.21 is stable
  228. elif grep -q 'enable-gold=both/ld' "${S}"/configure ; then
  229. myconf+=( --enable-gold=both/ld )
  230. elif grep -q 'enable-gold=both/bfd' "${S}"/configure ; then
  231. myconf+=( --enable-gold=both/bfd )
  232. fi
  233. if grep -q -e '--enable-plugins' "${S}"/ld/configure ; then
  234. myconf+=( --enable-plugins )
  235. fi
  236. fi
  237. use nls \
  238. && myconf+=( --without-included-gettext ) \
  239. || myconf+=( --disable-nls )
  240. if in_iuse zlib ; then
  241. # older versions did not have an explicit configure flag
  242. export ac_cv_search_zlibVersion=$(usex zlib -lz no)
  243. myconf+=( $(use_with zlib) )
  244. elif version_is_at_least 2.26 ; then
  245. myconf+=( --with-system-zlib )
  246. fi
  247. # For bi-arch systems, enable a 64bit bfd. This matches
  248. # the bi-arch logic in toolchain.eclass. #446946
  249. # We used to do it for everyone, but it's slow on 32bit arches. #438522
  250. case $(tc-arch) in
  251. ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
  252. esac
  253. use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
  254. [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
  255. is_cross && myconf+=(
  256. --with-sysroot="${EPREFIX}"/usr/${CTARGET}
  257. --enable-poison-system-directories
  258. )
  259. # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
  260. # on everyone in alpha (for now), we'll just enable it when possible
  261. has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
  262. has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
  263. myconf+=(
  264. --prefix="${EPREFIX}"/usr
  265. --host=${CHOST}
  266. --target=${CTARGET}
  267. --datadir="${EPREFIX}"${DATAPATH}
  268. --infodir="${EPREFIX}"${DATAPATH}/info
  269. --mandir="${EPREFIX}"${DATAPATH}/man
  270. --bindir="${EPREFIX}"${BINPATH}
  271. --libdir="${EPREFIX}"${LIBPATH}
  272. --libexecdir="${EPREFIX}"${LIBPATH}
  273. --includedir="${EPREFIX}"${INCPATH}
  274. --enable-obsolete
  275. --enable-shared
  276. --enable-threads
  277. # Newer versions (>=2.27) offer a configure flag now.
  278. --enable-relro
  279. # Newer versions (>=2.24) make this an explicit option. #497268
  280. --enable-install-libiberty
  281. --disable-werror
  282. --with-bugurl="$(toolchain-binutils_bugurl)"
  283. --with-pkgversion="$(toolchain-binutils_pkgversion)"
  284. $(use_enable static-libs static)
  285. ${EXTRA_ECONF}
  286. # Disable modules that are in a combined binutils/gdb tree. #490566
  287. --disable-{gdb,libdecnumber,readline,sim}
  288. # Strip out broken static link flags.
  289. # https://gcc.gnu.org/PR56750
  290. --without-stage1-ldflags
  291. )
  292. echo ./configure "${myconf[@]}"
  293. "${S}"/configure "${myconf[@]}" || die
  294. # Prevent makeinfo from running in releases. It may not always be
  295. # installed, and older binutils may fail with newer texinfo.
  296. # Besides, we never patch the doc files anyways, so regenerating
  297. # in the first place is useless. #193364
  298. # For older versions, it means we don't get any info pages at all.
  299. # Oh well, tough luck. #294617
  300. if [[ -e ${S}/gas/doc/as.info ]] || ! version_is_at_least 2.24 ; then
  301. sed -i \
  302. -e '/^MAKEINFO/s:=.*:= true:' \
  303. Makefile || die
  304. fi
  305. }
  306. toolchain-binutils_src_compile() {
  307. _eprefix_init
  308. case ${EAPI:-0} in
  309. 0|1) toolchain-binutils_src_configure ;;
  310. esac
  311. cd "${MY_BUILDDIR}"
  312. emake all || die "emake failed"
  313. # only build info pages if we user wants them, and if
  314. # we have makeinfo (may not exist when we bootstrap)
  315. if type -p makeinfo > /dev/null ; then
  316. emake info || die "make info failed"
  317. fi
  318. # we nuke the manpages when we're left with junk
  319. # (like when we bootstrap, no perl -> no manpages)
  320. find . -name '*.1' -a -size 0 -delete
  321. # elf2flt only works on some arches / targets
  322. if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
  323. cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
  324. local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
  325. for x in ${supported_arches} UNSUPPORTED ; do
  326. [[ ${CTARGET} == ${x}* ]] && break
  327. done
  328. if [[ ${x} != "UNSUPPORTED" ]] ; then
  329. append-flags -I"${S}"/include
  330. myconf+=(
  331. --with-bfd-include-dir=${MY_BUILDDIR}/bfd
  332. --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a
  333. --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a
  334. --with-binutils-ldscript-dir="${EPREFIX}"${LIBPATH}/ldscripts
  335. )
  336. echo ./configure "${myconf[@]}"
  337. ./configure "${myconf[@]}" || die
  338. emake || die "make elf2flt failed"
  339. fi
  340. fi
  341. }
  342. toolchain-binutils_src_test() {
  343. cd "${MY_BUILDDIR}"
  344. emake -k check || die "check failed :("
  345. }
  346. toolchain-binutils_src_install() {
  347. _eprefix_init
  348. local x d
  349. cd "${MY_BUILDDIR}"
  350. emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install || die
  351. rm -rf "${ED}"/${LIBPATH}/bin
  352. use static-libs || find "${ED}" -name '*.la' -delete
  353. # Newer versions of binutils get fancy with ${LIBPATH} #171905
  354. cd "${ED}"/${LIBPATH}
  355. for d in ../* ; do
  356. [[ ${d} == ../${BVER} ]] && continue
  357. mv ${d}/* . || die
  358. rmdir ${d} || die
  359. done
  360. # Now we collect everything intp the proper SLOT-ed dirs
  361. # When something is built to cross-compile, it installs into
  362. # /usr/$CHOST/ by default ... we have to 'fix' that :)
  363. if is_cross ; then
  364. cd "${ED}"/${BINPATH}
  365. for x in * ; do
  366. mv ${x} ${x/${CTARGET}-}
  367. done
  368. if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
  369. mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
  370. mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
  371. rm -r "${ED}"/usr/${CHOST}/{include,lib}
  372. fi
  373. fi
  374. insinto ${INCPATH}
  375. local libiberty_headers=(
  376. # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
  377. demangle.h
  378. dyn-string.h
  379. fibheap.h
  380. hashtab.h
  381. libiberty.h
  382. objalloc.h
  383. splay-tree.h
  384. )
  385. doins "${libiberty_headers[@]/#/${S}/include/}" || die
  386. if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
  387. mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
  388. rm -r "${ED}"/${LIBPATH}/lib
  389. fi
  390. # Insert elf2flt where appropriate
  391. if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
  392. cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
  393. insinto ${LIBPATH}/ldscripts
  394. doins elf2flt.ld || die "doins elf2flt.ld failed"
  395. exeinto ${BINPATH}
  396. doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
  397. mv "${ED}"/${BINPATH}/{ld,ld.real} || die
  398. newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
  399. newdoc README README.elf2flt
  400. fi
  401. # Generate an env.d entry for this binutils
  402. insinto /etc/env.d/binutils
  403. cat <<-EOF > "${T}"/env.d
  404. TARGET="${CTARGET}"
  405. VER="${BVER}"
  406. LIBPATH="${EPREFIX}${LIBPATH}"
  407. EOF
  408. newins "${T}"/env.d ${CTARGET}-${BVER}
  409. # Handle documentation
  410. if ! is_cross ; then
  411. cd "${S}"
  412. dodoc README
  413. docinto bfd
  414. dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
  415. docinto binutils
  416. dodoc binutils/ChangeLog binutils/NEWS binutils/README
  417. docinto gas
  418. dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
  419. docinto gprof
  420. dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
  421. docinto ld
  422. dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
  423. docinto libiberty
  424. dodoc libiberty/ChangeLog* libiberty/README
  425. docinto opcodes
  426. dodoc opcodes/ChangeLog*
  427. fi
  428. # Remove shared info pages
  429. rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
  430. # Trim all empty dirs
  431. find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
  432. }
  433. toolchain-binutils_pkg_postinst() {
  434. _eprefix_init
  435. # Make sure this ${CTARGET} has a binutils version selected
  436. [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
  437. binutils-config ${CTARGET}-${BVER}
  438. }
  439. toolchain-binutils_pkg_postrm() {
  440. _eprefix_init
  441. local current_profile=$(binutils-config -c ${CTARGET})
  442. # If no other versions exist, then uninstall for this
  443. # target ... otherwise, switch to the newest version
  444. # Note: only do this if this version is unmerged. We
  445. # rerun binutils-config if this is a remerge, as
  446. # we want the mtimes on the symlinks updated (if
  447. # it is the same as the current selected profile)
  448. if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
  449. local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
  450. choice=${choice//$'\n'/ }
  451. choice=${choice/* }
  452. if [[ -z ${choice} ]] ; then
  453. env -i ROOT="${ROOT}" binutils-config -u ${CTARGET}
  454. else
  455. binutils-config ${choice}
  456. fi
  457. elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
  458. binutils-config ${CTARGET}-${BVER}
  459. fi
  460. }