logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

binutils-x86_64-helios-9999.ebuild (11768B)


  1. # Copyright 1999-2023 Gentoo Authors
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=7
  4. inherit libtool flag-o-matic gnuconfig strip-linguas toolchain-funcs
  5. DESCRIPTION="Tools necessary to build programs"
  6. HOMEPAGE="https://git.sr.ht/~sircmpwn/binutils"
  7. EGIT_REPO_URI="https://git.sr.ht/~sircmpwn/binutils"
  8. LICENSE="GPL-3+"
  9. IUSE="cet gold gprofng hardened +plugins static-libs test vanilla"
  10. # Variables that can be set here (ignored for live ebuilds)
  11. # PATCH_VER - the patchset version
  12. # Default: empty, no patching
  13. # PATCH_BINUTILS_VER - the binutils version in the patchset name
  14. # - Default: PV
  15. # PATCH_DEV - Use download URI https://dev.gentoo.org/~{PATCH_DEV}/distfiles/...
  16. # for the patchsets
  17. if [[ ${PV} == 9999* ]]; then
  18. inherit git-r3
  19. SLOT=${PV}
  20. fi
  21. #
  22. # The cross-compile logic
  23. #
  24. export CTARGET="x86_64-helios"
  25. is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
  26. #
  27. # The dependencies
  28. #
  29. RDEPEND="
  30. >=sys-devel/binutils-config-3
  31. sys-libs/zlib
  32. "
  33. DEPEND="${RDEPEND}"
  34. BDEPEND="
  35. test? (
  36. dev-util/dejagnu
  37. sys-devel/bc
  38. )
  39. sys-devel/flex
  40. app-alternatives/yacc
  41. "
  42. RESTRICT="!test? ( test )"
  43. MY_BUILDDIR=${WORKDIR}/build
  44. src_unpack() {
  45. git-r3_src_unpack
  46. cd "${WORKDIR}" || die
  47. mkdir -p "${MY_BUILDDIR}" || die
  48. }
  49. src_prepare() {
  50. local patchsetname
  51. if [[ ${PV} == 9999* ]] ; then
  52. patchsetname="from git master"
  53. else
  54. patchsetname="${PATCH_BINUTILS_VER}-${PATCH_VER}"
  55. fi
  56. # Make sure our explicit libdir paths don't get clobbered, bug #562460
  57. sed -i \
  58. -e 's:@bfdlibdir@:@libdir@:g' \
  59. -e 's:@bfdincludedir@:@includedir@:g' \
  60. {bfd,opcodes}/Makefile.in || die
  61. # Apply things from PATCHES and user dirs
  62. default
  63. # Run misc portage update scripts
  64. gnuconfig_update
  65. elibtoolize --portage --no-uclibc
  66. }
  67. toolchain-binutils_bugurl() {
  68. printf "https://bugs.gentoo.org/"
  69. }
  70. toolchain-binutils_pkgversion() {
  71. printf "Gentoo ${PV}"
  72. [[ -n ${PATCH_VER} ]] && printf " p${PATCH_VER}"
  73. }
  74. src_configure() {
  75. # See https://www.gnu.org/software/make/manual/html_node/Parallel-Output.html
  76. # Avoid really confusing logs from subconfigure spam, makes logs far
  77. # more legible.
  78. MAKEOPTS="--output-sync=line ${MAKEOPTS}"
  79. # Setup some paths
  80. LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
  81. INCPATH=${LIBPATH}/include
  82. DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
  83. if is_cross ; then
  84. TOOLPATH=/usr/${CHOST}/${CTARGET}
  85. else
  86. TOOLPATH=/usr/${CTARGET}
  87. fi
  88. BINPATH=${TOOLPATH}/binutils-bin/${PV}
  89. # Make sure we filter $LINGUAS so that only ones that
  90. # actually work make it through, bug #42033
  91. strip-linguas -u */po
  92. # Keep things sane
  93. strip-flags
  94. use cet && filter-flags -mindirect-branch -mindirect-branch=*
  95. use elibc_musl && append-ldflags -Wl,-z,stack-size=2097152
  96. # ideally we want !tc-ld-is-bfd for best future-proofing, but it needs
  97. # https://github.com/gentoo/gentoo/pull/28355
  98. # mold needs this too but right now tc-ld-is-mold is also not available
  99. if tc-ld-is-lld; then
  100. append-ldflags -Wl,--undefined-version
  101. fi
  102. local x
  103. echo
  104. for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
  105. einfo "$(printf '%10s' ${x}:) ${!x}"
  106. done
  107. echo
  108. cd "${MY_BUILDDIR}" || die
  109. local myconf=()
  110. if use plugins ; then
  111. myconf+=( --enable-plugins )
  112. fi
  113. # enable gold (installed as ld.gold) and ld's plugin architecture
  114. if use gold ; then
  115. myconf+=( --enable-gold )
  116. fi
  117. myconf+=( --disable-nls )
  118. myconf+=( --with-system-zlib )
  119. # For bi-arch systems, enable a 64bit bfd. This matches the bi-arch
  120. # logic in toolchain.eclass. bug #446946
  121. #
  122. # We used to do it for everyone, but it's slow on 32bit arches. bug #438522
  123. case $(tc-arch) in
  124. ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
  125. esac
  126. [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
  127. is_cross && myconf+=(
  128. --with-sysroot="${EPREFIX}"/usr/${CTARGET}
  129. --enable-poison-system-directories
  130. )
  131. myconf+=( --enable-secureplt )
  132. # mips can't do hash-style=gnu ...
  133. if [[ $(tc-arch) != mips ]] ; then
  134. myconf+=( --enable-default-hash-style=gnu )
  135. fi
  136. myconf+=(
  137. --prefix="${EPREFIX}"/usr
  138. --host=${CHOST}
  139. --target=${CTARGET}
  140. --datadir="${EPREFIX}"${DATAPATH}
  141. --datarootdir="${EPREFIX}"${DATAPATH}
  142. --infodir="${EPREFIX}"${DATAPATH}/info
  143. --mandir="${EPREFIX}"${DATAPATH}/man
  144. --bindir="${EPREFIX}"${BINPATH}
  145. --libdir="${EPREFIX}"${LIBPATH}
  146. --libexecdir="${EPREFIX}"${LIBPATH}
  147. --includedir="${EPREFIX}"${INCPATH}
  148. # portage's econf() does not detect presence of --d-d-t
  149. # because it greps only top-level ./configure. But not
  150. # libiberty's or bfd's configure.
  151. --disable-dependency-tracking
  152. --disable-silent-rules
  153. --enable-obsolete
  154. --enable-shared
  155. --enable-threads
  156. --enable-relro
  157. --enable-install-libiberty
  158. --enable-textrel-check=$(usex hardened error warning)
  159. # Things to think about
  160. #--enable-deterministic-archives
  161. --enable-new-dtags
  162. --disable-jansson
  163. --disable-werror
  164. --with-bugurl="$(toolchain-binutils_bugurl)"
  165. --with-pkgversion="$(toolchain-binutils_pkgversion)"
  166. $(use_enable static-libs static)
  167. --without-zstd
  168. # Disable modules that are in a combined binutils/gdb tree, bug #490566
  169. --disable-{gdb,libdecnumber,readline,sim}
  170. # Strip out broken static link flags: https://gcc.gnu.org/PR56750
  171. --without-stage1-ldflags
  172. # Change SONAME to avoid conflict across {native,cross}/binutils, binutils-libs. bug #666100
  173. #--with-extra-soversion-suffix=gentoo-${CATEGORY}-${PN}-$(usex multitarget mt st)
  174. # Not going to be useful with Helios
  175. --without-debuginfod
  176. # Avoid automagic dev-libs/msgpack dep, bug #865875
  177. --without-msgpack
  178. # Allow user to opt into CET for host libraries.
  179. # Ideally we would like automagic-or-disabled here.
  180. # But the check does not quite work on i686: bug #760926.
  181. $(use_enable cet)
  182. # We can enable this by default in future, but it's brand new
  183. # in 2.39 with several bugs:
  184. # - Doesn't build on musl (https://sourceware.org/bugzilla/show_bug.cgi?id=29477)
  185. # - No man pages (https://sourceware.org/bugzilla/show_bug.cgi?id=29521)
  186. # - Broken at runtime without Java (https://sourceware.org/bugzilla/show_bug.cgi?id=29479)
  187. # - binutils-config (and this ebuild?) needs adaptation first (https://bugs.gentoo.org/865113)
  188. $(use_enable gprofng)
  189. )
  190. case ${CTARGET} in
  191. x86_64-*|aarch64*|arm64*|i[3456]*)
  192. # These hardening options are available from 2.39+ but
  193. # they unconditionally enable the behaviour even on arches
  194. # where e.g. execstacks can't be avoided.
  195. # See https://sourceware.org/bugzilla/show_bug.cgi?id=29592.
  196. #
  197. # TODO: Get the logic for this fixed upstream so it doesn't
  198. # create impossible broken combinations on some arches, like mips.
  199. #
  200. # TODO: Get the logic for this fixed upstream so --disable-* works
  201. # as expected.
  202. myconf+=(
  203. --enable-warn-execstack=yes
  204. --enable-warn-rwx-segments=yes
  205. )
  206. if use hardened ; then
  207. myconf+=(
  208. --enable-default-execstack=no
  209. )
  210. fi
  211. ;;
  212. *)
  213. ;;
  214. esac
  215. if use elibc_musl ; then
  216. # Override our earlier setting for musl, as textrels don't
  217. # work there at all. See bug #707660.
  218. myconf+=(
  219. --enable-textrel-check=error
  220. )
  221. fi
  222. ECONF_SOURCE="${S}" econf "${myconf[@]}"
  223. # Prevent makeinfo from running if doc is unset.
  224. sed -i \
  225. -e '/^MAKEINFO/s:=.*:= true:' \
  226. Makefile || die
  227. }
  228. src_compile() {
  229. cd "${MY_BUILDDIR}" || die
  230. # see Note [tooldir hack for ldscripts]
  231. emake tooldir="${EPREFIX}${TOOLPATH}" all
  232. # we nuke the manpages when we're left with junk
  233. # (like when we bootstrap, no perl -> no manpages)
  234. find . -name '*.1' -a -size 0 -delete
  235. }
  236. src_test() {
  237. cd "${MY_BUILDDIR}" || die
  238. # bug #637066
  239. filter-flags -Wall -Wreturn-type
  240. emake -k check
  241. }
  242. src_install() {
  243. local x d
  244. cd "${MY_BUILDDIR}" || die
  245. # see Note [tooldir hack for ldscripts]
  246. emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install
  247. rm -rf "${ED}"/${LIBPATH}/bin || die
  248. use static-libs || find "${ED}" -name '*.la' -delete
  249. # Newer versions of binutils get fancy with ${LIBPATH}, bug #171905
  250. cd "${ED}"/${LIBPATH} || die
  251. for d in ../* ; do
  252. [[ ${d} == ../${PV} ]] && continue
  253. mv ${d}/* . || die
  254. rmdir ${d} || die
  255. done
  256. # Now we collect everything intp the proper SLOT-ed dirs
  257. # When something is built to cross-compile, it installs into
  258. # /usr/$CHOST/ by default ... we have to 'fix' that :)
  259. if is_cross ; then
  260. cd "${ED}"/${BINPATH} || die
  261. for x in * ; do
  262. mv ${x} ${x/${CTARGET}-} || die
  263. done
  264. if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
  265. mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
  266. mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
  267. rm -r "${ED}"/usr/${CHOST}/{include,lib}
  268. fi
  269. fi
  270. insinto ${INCPATH}
  271. local libiberty_headers=(
  272. # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
  273. demangle.h
  274. dyn-string.h
  275. fibheap.h
  276. hashtab.h
  277. libiberty.h
  278. objalloc.h
  279. splay-tree.h
  280. )
  281. doins "${libiberty_headers[@]/#/${S}/include/}"
  282. if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
  283. mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/ || die
  284. rm -r "${ED}"/${LIBPATH}/lib || die
  285. fi
  286. # Generate an env.d entry for this binutils
  287. insinto /etc/env.d/binutils
  288. cat <<-EOF > "${T}"/env.d
  289. TARGET="${CTARGET}"
  290. VER="${PV}"
  291. LIBPATH="${EPREFIX}${LIBPATH}"
  292. EOF
  293. newins "${T}"/env.d ${CTARGET}-${PV}
  294. # Remove shared info pages
  295. rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
  296. # Trim all empty dirs
  297. find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
  298. }
  299. pkg_postinst() {
  300. # Make sure this ${CTARGET} has a binutils version selected
  301. [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
  302. binutils-config ${CTARGET}-${PV}
  303. }
  304. pkg_postrm() {
  305. local current_profile=$(binutils-config -c ${CTARGET})
  306. # If no other versions exist, then uninstall for this
  307. # target ... otherwise, switch to the newest version
  308. # Note: only do this if this version is unmerged. We
  309. # rerun binutils-config if this is a remerge, as
  310. # we want the mtimes on the symlinks updated (if
  311. # it is the same as the current selected profile)
  312. if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${PV} ]] ; then
  313. local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
  314. choice=${choice//$'\n'/ }
  315. choice=${choice/* }
  316. if [[ -z ${choice} ]] ; then
  317. binutils-config -u ${CTARGET}
  318. else
  319. binutils-config ${choice}
  320. fi
  321. elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${PV} ]] ; then
  322. binutils-config ${CTARGET}-${PV}
  323. fi
  324. }
  325. # Note [slotting support]
  326. # -----------------------
  327. # Gentoo's layout for binutils files is non-standard as Gentoo
  328. # supports slotted installation for binutils. Many tools
  329. # still expect binutils to reside in known locations.
  330. # binutils-config package restores symlinks into known locations,
  331. # like:
  332. # /usr/bin/${CTARGET}-<tool>
  333. # /usr/bin/${CHOST}/${CTARGET}/lib/ldscrips
  334. # /usr/include/
  335. #
  336. # Note [tooldir hack for ldscripts]
  337. # ---------------------------------
  338. # Build system does not allow ./configure to tweak every location
  339. # we need for slotting binutils hence all the shuffling in
  340. # src_install(). This note is about SCRIPTDIR define handling.
  341. #
  342. # SCRIPTDIR defines 'ldscripts/' directory location. SCRIPTDIR value
  343. # is set at build-time in ld/Makefile.am as: 'scriptdir = $(tooldir)/lib'
  344. # and hardcoded as -DSCRIPTDIR='"$(scriptdir)"' at compile time.
  345. # Thus we can't just move files around after compilation finished.
  346. #
  347. # Our goal is the following:
  348. # - at build-time set scriptdir to point to symlinked location:
  349. # ${TOOLPATH}: /usr/${CHOST} (or /usr/${CHOST}/${CTARGET} for cross-case)
  350. # - at install-time set scriptdir to point to slotted location:
  351. # ${LIBPATH}: /usr/$(get_libdir)/binutils/${CTARGET}/${PV}