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-bunnix-9999.ebuild (11778B)


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