binutils-apple-7.1.ebuild 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="5"
  4. inherit eutils flag-o-matic toolchain-funcs
  5. LD64=ld64-253.6
  6. CCTOOLS_VERSION=877.7
  7. CCTOOLS=cctools-${CCTOOLS_VERSION}
  8. LIBUNWIND=libunwind-35.3
  9. DYLD=dyld-360.17
  10. DESCRIPTION="Darwin assembler as(1) and static linker ld(1), Xcode Tools ${PV}"
  11. HOMEPAGE="http://www.opensource.apple.com/darwinsource/"
  12. SRC_URI="http://www.opensource.apple.com/tarballs/ld64/${LD64}.tar.gz
  13. http://www.opensource.apple.com/tarballs/cctools/${CCTOOLS}.tar.gz
  14. http://www.opensource.apple.com/tarballs/dyld/${DYLD}.tar.gz
  15. http://www.opensource.apple.com/tarballs/libunwind/${LIBUNWIND}.tar.gz
  16. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-4.3-r1.tar.bz2
  17. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-5.1-r2.tar.bz2
  18. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-6.1-r1.tar.bz2
  19. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-6.3-r1.tar.bz2
  20. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-7.0-r1.tar.bz2"
  21. LICENSE="APSL-2"
  22. KEYWORDS="~ppc-macos ~x64-macos ~x86-macos"
  23. IUSE="test multitarget"
  24. # ld64 can now only be compiled using llvm and libc++ since it massivley uses
  25. # C++11 language fatures. *But additionally* the as driver now defaults to
  26. # calling clang as the assembler on many platforms. This can be disabled using
  27. # -Wa,-Q but since it's default we make llvm a static runtime dependency.
  28. # Also, llvm lto and disassembler interfaces are now widely used in cctools.
  29. # Since we cannot compile with gcc any more and every llvm since 3.4 has
  30. # provided those interfaces, we no longer support disabling them. That
  31. # indirectly makes xar a static runtime dependency.
  32. RDEPEND="sys-devel/binutils-config
  33. app-arch/xar
  34. sys-devel/llvm
  35. sys-libs/libcxx"
  36. DEPEND="${RDEPEND}
  37. test? ( >=dev-lang/perl-5.8.8 )"
  38. SLOT="7"
  39. S=${WORKDIR}
  40. is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
  41. src_prepare() {
  42. if use multitarget ; then
  43. ewarn "You have enabled support for non-standard target architectures"
  44. ewarn "using USE=multitarget. This includes experimental support for"
  45. ewarn "ppc and ppc64 which is a community forward-port from the last"
  46. ewarn "version of ld64 to officially support PPC."
  47. if [[ ${CHOST} == powerpc*-darwin* ]] ; then
  48. ewarn "HERE BE DRAGONS! Your system seems to be PPC which means that"
  49. ewarn "the actual usability of your Gentoo programs will depend on the"
  50. ewarn "above-mentioned experimental PPC support in the linker. Be"
  51. ewarn "sure to keep a known-to-work version like ${PN}-3.2.6 around!"
  52. fi
  53. fi
  54. cd "${S}"/${LD64}/src
  55. cp "${S}"/ld64-136-compile_stubs.h ld/compile_stubs.h
  56. cp "${S}"/ld64-253.3-Makefile-2 Makefile
  57. epatch "${S}"/ld64-241.9-extraneous-includes.patch
  58. epatch "${S}"/ld64-241.9-osatomic.patch
  59. epatch "${S}"/ld64-236.3-crashreporter.patch
  60. epatch "${S}"/ld64-253.3-nosnapshots.patch
  61. epatch "${S}"/ld64-253.3-ppc.patch
  62. epatch "${S}"/ld64-236.3-constant-types-2.patch
  63. epatch "${S}"/ld64-241.9-register-names.patch
  64. epatch "${S}"/ld64-241.9-get-comm-align.patch
  65. epatch "${S}"/ld64-241.9-cc_md5.patch
  66. epatch "${S}"/ld64-253.3-make_pair.patch
  67. epatch "${S}"/ld64-253.3-delete-warning.patch
  68. # provide missing headers from libunwind and dyld
  69. mkdir -p include/{mach,mach-o/arm} || die
  70. # never present because it's private
  71. cp ../../${DYLD}/include/mach-o/dyld_priv.h include/mach-o || die
  72. # missing on <= 10.5
  73. cp ../../${LIBUNWIND}/include/libunwind.h include/ || die
  74. cp ../../${LIBUNWIND}/include/mach-o/compact_unwind_encoding.h include/mach-o || die
  75. # missing on <= 10.4
  76. cp ../../${DYLD}/include/mach-o/dyld_images.h include/mach-o || die
  77. cp ../../${CCTOOLS}/include/mach-o/loader.h include/mach-o || die
  78. # use copies from cctools because they're otherwise hidden in some SDK
  79. cp ../../${CCTOOLS}/include/mach-o/arm/reloc.h include/mach-o/arm || die
  80. # provide all required CPU_TYPEs on all platforms
  81. cp ../../${CCTOOLS}/include/mach/machine.h include/mach/machine.h
  82. # add alias for newer identifiers, because ld64 uses both but cctools
  83. # header only defines the older
  84. epatch "${S}"/ld64-236.3-missing-cputypes.patch
  85. # mimic OS X Leopard-style Availability.h macros for libunwind.h on
  86. # older systems
  87. [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -le 8 ]] && \
  88. echo "#define __OSX_AVAILABLE_STARTING(x,y) " > include/Availability.h
  89. local VER_STR="\"@(#)PROGRAM:ld PROJECT:${LD64} (Gentoo ${PN}-${PVR})\\n\""
  90. echo "char ldVersionString[] = ${VER_STR};" > version.cpp
  91. epatch "${S}"/ld64-123.2-debug-backtrace.patch
  92. if [[ ${CHOST} == powerpc*-darwin* ]] ; then
  93. epatch "${S}"/ld64-123.2-darwin8-no-mlong-branch-warning.patch
  94. epatch "${S}"/ld64-127.2-thread_state.patch
  95. fi
  96. cd "${S}"/${CCTOOLS}
  97. epatch "${S}"/${PN}-4.5-as.patch
  98. epatch "${S}"/${PN}-5.1-as-dir.patch
  99. epatch "${S}"/${PN}-5.1-ranlib.patch
  100. epatch "${S}"/${PN}-3.1.1-libtool-ranlib.patch
  101. epatch "${S}"/${PN}-3.1.1-no-headers.patch
  102. epatch "${S}"/${PN}-4.0-no-oss-dir.patch
  103. epatch "${S}"/cctools-839-intel-retf.patch
  104. epatch "${S}"/${PN}-5.1-extraneous-includes.patch
  105. #epatch "${S}"/${PN}-5.1-otool-stdc.patch
  106. epatch "${S}"/${PN}-5.1-constant-types.patch
  107. epatch "${S}"/${PN}-5.1-strnlen.patch
  108. epatch "${S}"/${PN}-5.1-ppc.patch
  109. epatch "${S}"/${PN}-5.1-thread-state-redefined.patch
  110. epatch "${S}"/${PN}-5.1-makefile-target-warning.patch
  111. epatch "${S}"/${PN}-7.0-lto-prefix.patch
  112. epatch "${S}"/${PN}-7.0-clang-as.patch
  113. cp ../${LD64}/src/other/prune_trie.h include/mach-o/ || die
  114. # do not build profileable libstuff to save compile time
  115. sed -i -e "/^all:/s, profile , ," libstuff/Makefile
  116. # cctools version is provided to make via RC_ProjectSourceVersion which
  117. # generates and compiles it as apple_version[] into libstuff. From
  118. # there it's picked up by the individual tools. Since
  119. # RC_ProjectSourceVersion is also used as library version, we can't
  120. # just append our local version info. So we hack the libstuff Makefile
  121. # to include our Gentoo version.
  122. sed -i -e "/cctools-.*(RC_ProjectSourceVersion).*OFILE_DIR/s,Version),Version) (Gentoo ${PN}-${PVR})," \
  123. libstuff/Makefile
  124. # clean up test suite
  125. cd "${S}"/${LD64}/unit-tests/test-cases
  126. local c
  127. # we don't have llvm
  128. ((++c)); rm -rf llvm-integration;
  129. # we don't have dtrace
  130. ((++c)); rm -rf dtrace-static-probes-coalescing;
  131. ((++c)); rm -rf dtrace-static-probes;
  132. # a file is missing
  133. ((++c)); rm -rf eh-coalescing-r
  134. # we don't do universal binaries
  135. ((++c)); rm -rf blank-stubs;
  136. # looks like a problem with apple's result-filter.pl
  137. ((++c)); rm -rf implicit-common3;
  138. ((++c)); rm -rf order_file-ans;
  139. # TODO no idea what goes wrong here
  140. ((++c)); rm -rf dwarf-debug-notes;
  141. einfo "Deleted $c tests that were bound to fail"
  142. cd "${S}"
  143. ebegin "cleaning Makefiles from unwanted CFLAGS"
  144. find . -name "Makefile" -print0 | xargs -0 sed \
  145. -i \
  146. -e 's/ -g / /g' \
  147. -e 's/^G =.*$/G =/' \
  148. -e 's/^OFLAG =.*$/OFLAG =/' \
  149. -e 's/install -c -s/install/g'
  150. eend $?
  151. }
  152. src_configure() {
  153. # CPPFLAGS only affects ld64, cctools don't use 'em (which currently is
  154. # what we want)
  155. append-cppflags -DNDEBUG
  156. export CTARGET=${CTARGET:-${CHOST}}
  157. if [[ ${CTARGET} == ${CHOST} ]] ; then
  158. if [[ ${CATEGORY} == cross-* ]] ; then
  159. export CTARGET=${CATEGORY#cross-}
  160. fi
  161. fi
  162. LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
  163. INCPATH=${LIBPATH}/include
  164. DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
  165. if is_cross ; then
  166. BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${PV}
  167. else
  168. BINPATH=/usr/${CTARGET}/binutils-bin/${PV}
  169. fi
  170. # Block API and thus snapshots supported on >= 10.6
  171. [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -ge 10 ]] && \
  172. append-cppflags -DSUPPORT_SNAPSHOTS
  173. CCTOOLS_OFLAG=
  174. if [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -le 8 ]] ; then
  175. # cctools expect to use UNIX03 struct member names.
  176. # This is default on > 10.4. Activate it on <= 10.4 by defining
  177. # __DARWIN_UNIX03 explicitly.
  178. CCTOOLS_OFLAG="-D__DARWIN_UNIX03=1"
  179. fi
  180. # if compiling with USE multitarget, extract all the known arches from
  181. # create_configure and pass them back to it
  182. creco=${LD64}/src/create_configure
  183. ARCHS_TO_SUPPORT=""
  184. if use multitarget ; then
  185. ARCHS_TO_SUPPORT="$(grep KNOWN_ARCHS= $creco | \
  186. cut -d\" -f2 | tr ',' ' ')"
  187. fi
  188. # Create configure.h for ld64 with SUPPORT_ARCH_<arch> defines in it.
  189. DERIVED_FILE_DIR=${LD64}/src \
  190. RC_SUPPORTED_ARCHS="$ARCHS_TO_SUPPORT" \
  191. $creco
  192. # do not depend on MachOFileAbstraction.hpp to define
  193. # SUPPORT_ARCH_arm_any because that's not included by every file where
  194. # our ppc/arm-optional patch uses it, ld.hpp in particular
  195. grep "SUPPORT_ARCH_armv[0-9]" ${LD64}/src/configure.h >/dev/null && \
  196. echo "#define SUPPORT_ARCH_arm_any 1" >> ${LD64}/src/configure.h
  197. }
  198. compile_ld64() {
  199. einfo "building ${LD64}"
  200. cd "${S}"/${LD64}/src
  201. emake || die "emake failed for ld64"
  202. use test && emake build_test
  203. }
  204. compile_cctools() {
  205. einfo "building ${CCTOOLS}"
  206. cd "${S}"/${CCTOOLS}
  207. # -j1 because it fails too often with weird errors
  208. # Suppress running dsymutil because it will warn about missing debug
  209. # info which is expected when compiling without -g as we normally do.
  210. # This might need some more thought if anyone ever wanted to build us
  211. # for debugging with Apple's tools.
  212. emake \
  213. LIB_PRUNETRIE="-L../../${LD64}/src -lprunetrie" \
  214. EFITOOLS= \
  215. COMMON_SUBDIRS='libstuff ar misc otool' \
  216. SUBDIRS_32= \
  217. LEGACY= \
  218. RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
  219. RC_CFLAGS="${CFLAGS}" \
  220. OFLAG="${CCTOOLS_OFLAG}" \
  221. DSYMUTIL=": disabled: dsymutil" \
  222. -j1 \
  223. || die "emake failed for the cctools"
  224. cd "${S}"/${CCTOOLS}/as
  225. emake \
  226. BUILD_OBSOLETE_ARCH= \
  227. RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
  228. RC_CFLAGS="-DASLIBEXECDIR=\"\\\"${EPREFIX}${LIBPATH}/\\\"\" -DCLANGDIR=\"\\\"${EPREFIX}/usr/bin/\\\"\" ${CFLAGS}" \
  229. OFLAG="${CCTOOLS_OFLAG}" \
  230. DSYMUTIL=": disabled: dsymutil" \
  231. || die "emake failed for as"
  232. }
  233. src_compile() {
  234. compile_ld64
  235. compile_cctools
  236. }
  237. install_ld64() {
  238. exeinto ${BINPATH}
  239. doexe "${S}"/${LD64}/src/{ld64,rebase,dyldinfo,unwinddump,ObjectDump}
  240. dosym ld64 ${BINPATH}/ld
  241. insinto ${DATAPATH}/man/man1
  242. doins "${S}"/${LD64}/doc/man/man1/{ld,ld64,rebase}.1
  243. }
  244. install_cctools() {
  245. cd "${S}"/${CCTOOLS}
  246. emake install_all_but_headers \
  247. EFITOOLS= \
  248. COMMON_SUBDIRS='ar misc otool' \
  249. SUBDIRS_32= \
  250. DSTROOT=\"${D}\" \
  251. BINDIR=\"${EPREFIX}\"${BINPATH} \
  252. LOCBINDIR=\"${EPREFIX}\"${BINPATH} \
  253. USRBINDIR=\"${EPREFIX}\"${BINPATH} \
  254. LOCLIBDIR=\"${EPREFIX}\"${LIBPATH} \
  255. MANDIR=\"${EPREFIX}\"${DATAPATH}/man/
  256. cd "${S}"/${CCTOOLS}/as
  257. emake install \
  258. BUILD_OBSOLETE_ARCH= \
  259. DSTROOT=\"${D}\" \
  260. USRBINDIR=\"${EPREFIX}\"${BINPATH} \
  261. LIBDIR=\"${EPREFIX}\"${LIBPATH} \
  262. LOCLIBDIR=\"${EPREFIX}\"${LIBPATH}
  263. cd "${ED}"${BINPATH}
  264. insinto ${DATAPATH}/man/man1
  265. local skips manpage
  266. # ar brings an up-to-date manpage with it
  267. skips=( ar )
  268. for bin in *; do
  269. for skip in ${skips[@]}; do
  270. if [[ ${bin} == ${skip} ]]; then
  271. continue 2;
  272. fi
  273. done
  274. manpage=${S}/${CCTOOLS}/man/${bin}.1
  275. if [[ -f "${manpage}" ]]; then
  276. doins "${manpage}"
  277. fi
  278. done
  279. insinto ${DATAPATH}/man/man5
  280. doins "${S}"/${CCTOOLS}/man/*.5
  281. }
  282. src_test() {
  283. if ! [ "${EPREFIX}"/usr/bin/clang ] ; then
  284. einfo "Test suite only works properly with clang - please install"
  285. return
  286. fi
  287. einfo "Running unit tests"
  288. cd "${S}"/${LD64}/unit-tests/test-cases
  289. # provide the new ld as a symlink to clang so that -ccc-install-dir
  290. # will pick it up
  291. ln -sfn ../../src/ld64 ld
  292. # use our arch command because the System's will report i386 even for an
  293. # x86_64 prefix
  294. perl ../bin/make-recursive.pl \
  295. BUILT_PRODUCTS_DIR="${S}"/${LD64}/src \
  296. ARCH="$(arch)" \
  297. LD="${S}"/${LD64}/src/ld64 \
  298. CC="${CC} -ccc-install-dir $PWD" \
  299. CXX="${CXX} -ccc-install-dir $PWD" \
  300. OTOOL="${S}"/${CCTOOLS}/otool/otool.NEW \
  301. | perl ../bin/result-filter.pl
  302. }
  303. src_install() {
  304. install_ld64
  305. install_cctools
  306. cd "${S}"
  307. insinto /etc/env.d/binutils
  308. cat <<-EOF > env.d
  309. TARGET="${CHOST}"
  310. VER="${PV}"
  311. FAKE_TARGETS="${CHOST}"
  312. EOF
  313. newins env.d ${CHOST}-${PV}
  314. }
  315. pkg_postinst() {
  316. binutils-config ${CHOST}-${PV}
  317. }