binutils-apple-8.2.1.ebuild 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="6"
  4. inherit eutils flag-o-matic toolchain-funcs
  5. LD64=ld64-274.2
  6. CCTOOLS_VERSION=895
  7. CCTOOLS=cctools-${CCTOOLS_VERSION}
  8. DYLD=dyld-421.2
  9. DESCRIPTION="Darwin assembler as(1) and static linker ld(1), Xcode Tools ${PV}"
  10. HOMEPAGE="http://www.opensource.apple.com/darwinsource/"
  11. SRC_URI="http://www.opensource.apple.com/tarballs/ld64/${LD64}.tar.gz
  12. http://www.opensource.apple.com/tarballs/cctools/${CCTOOLS}.tar.gz
  13. http://www.opensource.apple.com/tarballs/dyld/${DYLD}.tar.gz
  14. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-4.3-r1.tar.bz2
  15. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-5.1-r2.tar.bz2
  16. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-7.0-r2.tar.bz2
  17. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-7.3-r1.tar.bz2
  18. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-8.2-r0.tar.bz2"
  19. LICENSE="APSL-2"
  20. KEYWORDS="~x64-macos ~x86-macos"
  21. IUSE="lto tapi classic test"
  22. # ld64 can now only be compiled using llvm and libc++ since it massively uses
  23. # C++11 language features. *But additionally* the as driver now defaults to
  24. # calling clang as the assembler on many platforms. This can be disabled using
  25. # -Wa,-Q but since it's default we make llvm a static runtime dependency.
  26. RDEPEND="sys-devel/binutils-config
  27. lto? ( app-arch/xar )
  28. tapi? ( sys-libs/tapi )
  29. sys-devel/llvm
  30. sys-libs/libcxx"
  31. DEPEND="${RDEPEND}
  32. test? ( >=dev-lang/perl-5.8.8 )"
  33. SLOT="8"
  34. S=${WORKDIR}
  35. is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
  36. src_prepare() {
  37. cd "${S}"/${LD64}/src
  38. cp "${S}"/ld64-136-compile_stubs.h ld/compile_stubs.h
  39. cp "${S}"/ld64-274.1-Makefile Makefile
  40. epatch "${S}"/ld64-274.1-nolto.patch
  41. epatch "${S}"/ld64-236.3-crashreporter.patch
  42. epatch "${S}"/ld64-264.3.102-bitcode-case.patch
  43. epatch "${S}"/ld64-274.1-unknown-fixup.patch
  44. epatch "${S}"/ld64-274.1-notapi.patch
  45. # workound llvm-3.9.{0,1} issue
  46. # https://bugs.gentoo.org/show_bug.cgi?id=603580
  47. # https://groups.google.com/forum/#!topic/llvm-dev/JY6nuKE__sU
  48. # http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160829/169553.html
  49. sed -i -e '/COMPILE_TIME_ASSERT/d' ld/parsers/libunwind/*.hpp || die
  50. # provide missing headers from libunwind and dyld
  51. mkdir -p include/{mach,mach-o/arm} || die
  52. # never present because it's private
  53. cp ../../${DYLD}/include/mach-o/dyld_priv.h include/mach-o || die
  54. # use copies from cctools because they're otherwise hidden in some SDK
  55. cp ../../${CCTOOLS}/include/mach-o/arm/reloc.h include/mach-o/arm || die
  56. # provide all required CPU_TYPEs on all platforms
  57. cp ../../${CCTOOLS}/include/mach/machine.h include/mach/machine.h
  58. # add alias for newer identifiers, because ld64 uses both but cctools
  59. # header only defines the older
  60. epatch "${S}"/ld64-236.3-missing-cputypes.patch
  61. local VER_STR="\"@(#)PROGRAM:ld PROJECT:${LD64} (Gentoo ${PN}-${PVR})\\n\""
  62. echo "char ldVersionString[] = ${VER_STR};" > version.cpp
  63. epatch "${S}"/ld64-123.2-debug-backtrace.patch
  64. cd "${S}"/${CCTOOLS}
  65. epatch "${S}"/${PN}-4.5-as.patch
  66. epatch "${S}"/${PN}-5.1-as-dir.patch
  67. epatch "${S}"/${PN}-5.1-ranlib.patch
  68. epatch "${S}"/${PN}-3.1.1-libtool-ranlib.patch
  69. epatch "${S}"/${PN}-3.1.1-no-headers.patch
  70. epatch "${S}"/${PN}-4.0-no-oss-dir.patch
  71. epatch "${S}"/cctools-839-intel-retf.patch
  72. epatch "${S}"/${PN}-5.1-extraneous-includes.patch
  73. epatch "${S}"/${PN}-5.1-strnlen.patch
  74. epatch "${S}"/${PN}-7.3-make-j.patch
  75. epatch "${S}"/${PN}-7.0-lto-prefix-2.patch
  76. epatch "${S}"/${PN}-7.0-clang-as.patch
  77. epatch "${S}"/${PN}-8.1-nolto.patch
  78. epatch "${S}"/${PN}-7.3-nollvm.patch
  79. epatch "${S}"/${PN}-7.3-no-developertools-dir.patch
  80. epatch "${S}"/${PN}-8.1-llvm-tools.patch
  81. cp ../${LD64}/src/other/prune_trie.h include/mach-o/ || die
  82. # do not build profileable libstuff to save compile time
  83. sed -i -e "/^all:/s, profile , ," libstuff/Makefile
  84. # cctools version is provided to make via RC_ProjectSourceVersion which
  85. # generates and compiles it as apple_version[] into libstuff. From
  86. # there it's picked up by the individual tools. Since
  87. # RC_ProjectSourceVersion is also used as library version, we can't
  88. # just append our local version info. So we hack the libstuff Makefile
  89. # to include our Gentoo version.
  90. sed -i -e "/cctools-.*(RC_ProjectSourceVersion).*OFILE_DIR/s,Version),Version) (Gentoo ${PN}-${PVR})," \
  91. libstuff/Makefile
  92. eapply_user
  93. # clean up test suite
  94. cd "${S}"/${LD64}/unit-tests/test-cases
  95. local c
  96. # we don't have llvm
  97. ((++c)); rm -rf llvm-integration;
  98. # we don't have dtrace
  99. ((++c)); rm -rf dtrace-static-probes-coalescing;
  100. ((++c)); rm -rf dtrace-static-probes;
  101. # a file is missing
  102. ((++c)); rm -rf eh-coalescing-r
  103. # we don't do universal binaries
  104. ((++c)); rm -rf blank-stubs;
  105. # looks like a problem with apple's result-filter.pl
  106. ((++c)); rm -rf implicit-common3;
  107. ((++c)); rm -rf order_file-ans;
  108. # TODO no idea what goes wrong here
  109. ((++c)); rm -rf dwarf-debug-notes;
  110. einfo "Deleted $c tests that were bound to fail"
  111. cd "${S}"
  112. ebegin "cleaning Makefiles from unwanted CFLAGS"
  113. find . -name "Makefile" -print0 | xargs -0 sed \
  114. -i \
  115. -e 's/ -g / /g' \
  116. -e 's/^G =.*$/G =/' \
  117. -e 's/^OFLAG =.*$/OFLAG =/' \
  118. -e 's/install -c -s/install/g'
  119. eend $?
  120. }
  121. src_configure() {
  122. ENABLE_LTO=0
  123. use lto && ENABLE_LTO=1
  124. export CTARGET=${CTARGET:-${CHOST}}
  125. if [[ ${CTARGET} == ${CHOST} ]] ; then
  126. if [[ ${CATEGORY} == cross-* ]] ; then
  127. export CTARGET=${CATEGORY#cross-}
  128. fi
  129. fi
  130. LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
  131. INCPATH=${LIBPATH}/include
  132. DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
  133. if is_cross ; then
  134. BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${PV}
  135. else
  136. BINPATH=/usr/${CTARGET}/binutils-bin/${PV}
  137. fi
  138. # CPPFLAGS only affects ld64, cctools don't use 'em (which currently is
  139. # what we want)
  140. append-cppflags -DNDEBUG
  141. # Create configure.h for ld64 with SUPPORT_ARCH_<arch> defines in it.
  142. DERIVED_FILE_DIR=${LD64}/src \
  143. ${LD64}/src/create_configure
  144. }
  145. compile_ld64() {
  146. einfo "building ${LD64}"
  147. cd "${S}"/${LD64}/src
  148. emake \
  149. LTO=${ENABLE_LTO} \
  150. TAPI=$(use tapi && echo 1 || echo 0) \
  151. || die "emake failed for ld64"
  152. use test && emake build_test
  153. }
  154. compile_cctools() {
  155. einfo "building ${CCTOOLS}"
  156. cd "${S}"/${CCTOOLS}
  157. # Suppress running dsymutil because it will warn about missing debug
  158. # info which is expected when compiling without -g as we normally do.
  159. # This might need some more thought if anyone ever wanted to build us
  160. # for debugging with Apple's tools.
  161. emake \
  162. LIB_PRUNETRIE="-L../../${LD64}/src -lprunetrie" \
  163. EFITOOLS= \
  164. LTO="${ENABLE_LTO}" \
  165. LTO_LIBDIR=../../../lib \
  166. COMMON_SUBDIRS='libstuff ar misc otool' \
  167. SUBDIRS_32= \
  168. LEGACY= \
  169. RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
  170. RC_CFLAGS="${CFLAGS}" \
  171. OFLAG="${CCTOOLS_OFLAG}" \
  172. DSYMUTIL=": disabled: dsymutil" \
  173. || die "emake failed for the cctools"
  174. cd "${S}"/${CCTOOLS}/as
  175. emake \
  176. BUILD_OBSOLETE_ARCH= \
  177. RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
  178. RC_CFLAGS="-DASLIBEXECDIR=\"\\\"${EPREFIX}${LIBPATH}/\\\"\" -DCLANGDIR=\"\\\"${EPREFIX}/usr/bin/\\\"\" ${CFLAGS}" \
  179. OFLAG="${CCTOOLS_OFLAG}" \
  180. DSYMUTIL=": disabled: dsymutil" \
  181. || die "emake failed for as"
  182. }
  183. src_compile() {
  184. compile_ld64
  185. compile_cctools
  186. }
  187. install_ld64() {
  188. exeinto ${BINPATH}
  189. doexe "${S}"/${LD64}/src/{ld64,rebase,dyldinfo,unwinddump,ObjectDump}
  190. dosym ld64 ${BINPATH}/ld
  191. insinto ${DATAPATH}/man/man1
  192. doins "${S}"/${LD64}/doc/man/man1/{ld,ld64,rebase}.1
  193. }
  194. install_cctools() {
  195. cd "${S}"/${CCTOOLS}
  196. emake install_all_but_headers \
  197. EFITOOLS= \
  198. COMMON_SUBDIRS='ar misc otool' \
  199. SUBDIRS_32= \
  200. DSTROOT=\"${D}\" \
  201. BINDIR=\"${EPREFIX}\"${BINPATH} \
  202. LOCBINDIR=\"${EPREFIX}\"${BINPATH} \
  203. USRBINDIR=\"${EPREFIX}\"${BINPATH} \
  204. LOCLIBDIR=\"${EPREFIX}\"${LIBPATH} \
  205. MANDIR=\"${EPREFIX}\"${DATAPATH}/man/
  206. cd "${S}"/${CCTOOLS}/as
  207. emake install \
  208. BUILD_OBSOLETE_ARCH= \
  209. DSTROOT=\"${D}\" \
  210. USRBINDIR=\"${EPREFIX}\"${BINPATH} \
  211. LIBDIR=\"${EPREFIX}\"${LIBPATH} \
  212. LOCLIBDIR=\"${EPREFIX}\"${LIBPATH}
  213. # upstream is starting to replace classic binutils with llvm-integrated
  214. # ones. nm and size are now symlinks to llvm-{nm,size} while the classic
  215. # version is preserved as {nm,size}-classic.
  216. # Since our binutils do not live in the same directory as the llvm
  217. # installation, we have to rewrite the symlinks to the llvm tools.
  218. # This also means, that these tools still appear to be versioned via
  219. # binutils-config but actually always run the currently installed llvm
  220. # tool.
  221. budir=${D}/${EPREFIX}/${BINPATH}
  222. for tool in nm size ; do
  223. # ${EPREFIX}/usr/x86_64-apple-darwin15/binutils-bin/7.3/$tool
  224. # -> ${EPREFIX}/bin/llvm-$tool
  225. use classic && \
  226. ln -sfn ${tool}-classic "${budir}/${tool}" || \
  227. ln -sfn ../../../bin/llvm-${tool} "${budir}/${tool}"
  228. done
  229. # Also, otool is now based on llvm-objdump. But a small wrapper installed
  230. # as llvm-otool remains, providing command line compatibility.
  231. use classic && \
  232. ln -sfn otool-classic "${budir}/otool" || \
  233. ln -sfn llvm-otool "${budir}/otool"
  234. cd "${ED}"${BINPATH}
  235. insinto ${DATAPATH}/man/man1
  236. local skips manpage
  237. # ar brings an up-to-date manpage with it
  238. skips=( ar )
  239. for bin in *; do
  240. for skip in ${skips[@]}; do
  241. if [[ ${bin} == ${skip} ]]; then
  242. continue 2;
  243. fi
  244. done
  245. manpage=${S}/${CCTOOLS}/man/${bin}.1
  246. if [[ -f "${manpage}" ]]; then
  247. doins "${manpage}"
  248. fi
  249. done
  250. insinto ${DATAPATH}/man/man5
  251. doins "${S}"/${CCTOOLS}/man/*.5
  252. }
  253. src_test() {
  254. if ! [ "${EPREFIX}"/usr/bin/clang ] ; then
  255. einfo "Test suite only works properly with clang - please install"
  256. return
  257. fi
  258. einfo "Running unit tests"
  259. cd "${S}"/${LD64}/unit-tests/test-cases
  260. # provide the new ld as a symlink to clang so that -ccc-install-dir
  261. # will pick it up
  262. ln -sfn ../../src/ld64 ld
  263. # use our arch command because the System's will report i386 even for an
  264. # x86_64 prefix
  265. perl ../bin/make-recursive.pl \
  266. BUILT_PRODUCTS_DIR="${S}"/${LD64}/src \
  267. ARCH="$(arch)" \
  268. LD="${S}"/${LD64}/src/ld64 \
  269. CC="${CC} -ccc-install-dir $PWD" \
  270. CXX="${CXX} -ccc-install-dir $PWD" \
  271. OTOOL="${S}"/${CCTOOLS}/otool/otool.NEW \
  272. | perl ../bin/result-filter.pl
  273. }
  274. src_install() {
  275. install_ld64
  276. install_cctools
  277. cd "${S}"
  278. insinto /etc/env.d/binutils
  279. cat <<-EOF > env.d
  280. TARGET="${CHOST}"
  281. VER="${PV}"
  282. FAKE_TARGETS="${CHOST}"
  283. EOF
  284. newins env.d ${CHOST}-${PV}
  285. }
  286. pkg_postinst() {
  287. binutils-config ${CHOST}-${PV}
  288. }