binutils-apple-7.2-r1.ebuild 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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.9
  6. CCTOOLS_VERSION=877.8
  7. CCTOOLS=cctools-${CCTOOLS_VERSION}
  8. LIBUNWIND=libunwind-35.3
  9. DYLD=dyld-360.18
  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-r2.tar.bz2
  21. http://dev.gentoo.org/~grobian/distfiles/${PN}-patches-7.2-r0.tar.bz2"
  22. LICENSE="APSL-2"
  23. KEYWORDS="~ppc-macos ~x64-macos ~x86-macos"
  24. IUSE="lto test multitarget"
  25. # ld64 can now only be compiled using llvm and libc++ since it massivley uses
  26. # C++11 language fatures. *But additionally* the as driver now defaults to
  27. # calling clang as the assembler on many platforms. This can be disabled using
  28. # -Wa,-Q but since it's default we make llvm a static runtime dependency.
  29. RDEPEND="sys-devel/binutils-config
  30. lto? ( app-arch/xar )
  31. sys-devel/llvm
  32. sys-libs/libcxx"
  33. DEPEND="${RDEPEND}
  34. test? ( >=dev-lang/perl-5.8.8 )"
  35. SLOT="7"
  36. S=${WORKDIR}
  37. is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
  38. src_prepare() {
  39. if use multitarget ; then
  40. ewarn "You have enabled support for non-standard target architectures"
  41. ewarn "using USE=multitarget. This includes experimental support for"
  42. ewarn "ppc and ppc64 which is a community forward-port from the last"
  43. ewarn "version of ld64 to officially support PPC."
  44. if [[ ${CHOST} == powerpc*-darwin* ]] ; then
  45. ewarn "HERE BE DRAGONS! Your system seems to be PPC which means that"
  46. ewarn "the actual usability of your Gentoo programs will depend on the"
  47. ewarn "above-mentioned experimental PPC support in the linker. Be"
  48. ewarn "sure to keep a known-to-work version like ${PN}-3.2.6 around!"
  49. fi
  50. fi
  51. cd "${S}"/${LD64}/src
  52. cp "${S}"/ld64-136-compile_stubs.h ld/compile_stubs.h
  53. cp "${S}"/ld64-253.3-Makefile-3 Makefile
  54. epatch "${S}"/ld64-253.9-nolto.patch
  55. epatch "${S}"/ld64-241.9-extraneous-includes.patch
  56. epatch "${S}"/ld64-241.9-osatomic.patch
  57. epatch "${S}"/ld64-236.3-crashreporter.patch
  58. epatch "${S}"/ld64-253.3-nosnapshots.patch
  59. epatch "${S}"/ld64-253.3-ppc.patch
  60. epatch "${S}"/ld64-236.3-constant-types-2.patch
  61. epatch "${S}"/ld64-241.9-register-names.patch
  62. epatch "${S}"/ld64-241.9-get-comm-align.patch
  63. epatch "${S}"/ld64-241.9-cc_md5.patch
  64. epatch "${S}"/ld64-253.3-make_pair.patch
  65. epatch "${S}"/ld64-253.3-delete-warning.patch
  66. # provide missing headers from libunwind and dyld
  67. mkdir -p include/{mach,mach-o/arm} || die
  68. # never present because it's private
  69. cp ../../${DYLD}/include/mach-o/dyld_priv.h include/mach-o || die
  70. # missing on <= 10.5
  71. cp ../../${LIBUNWIND}/include/libunwind.h include/ || die
  72. cp ../../${LIBUNWIND}/include/mach-o/compact_unwind_encoding.h include/mach-o || die
  73. # missing on <= 10.4
  74. cp ../../${DYLD}/include/mach-o/dyld_images.h include/mach-o || die
  75. cp ../../${CCTOOLS}/include/mach-o/loader.h include/mach-o || die
  76. # use copies from cctools because they're otherwise hidden in some SDK
  77. cp ../../${CCTOOLS}/include/mach-o/arm/reloc.h include/mach-o/arm || die
  78. # provide all required CPU_TYPEs on all platforms
  79. cp ../../${CCTOOLS}/include/mach/machine.h include/mach/machine.h
  80. # add alias for newer identifiers, because ld64 uses both but cctools
  81. # header only defines the older
  82. epatch "${S}"/ld64-236.3-missing-cputypes.patch
  83. # mimic OS X Leopard-style Availability.h macros for libunwind.h on
  84. # older systems
  85. [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -le 8 ]] && \
  86. echo "#define __OSX_AVAILABLE_STARTING(x,y) " > include/Availability.h
  87. local VER_STR="\"@(#)PROGRAM:ld PROJECT:${LD64} (Gentoo ${PN}-${PVR})\\n\""
  88. echo "char ldVersionString[] = ${VER_STR};" > version.cpp
  89. epatch "${S}"/ld64-123.2-debug-backtrace.patch
  90. if [[ ${CHOST} == powerpc*-darwin* ]] ; then
  91. epatch "${S}"/ld64-123.2-darwin8-no-mlong-branch-warning.patch
  92. epatch "${S}"/ld64-127.2-thread_state.patch
  93. fi
  94. cd "${S}"/${CCTOOLS}
  95. epatch "${S}"/${PN}-4.5-as.patch
  96. epatch "${S}"/${PN}-5.1-as-dir.patch
  97. epatch "${S}"/${PN}-5.1-ranlib.patch
  98. epatch "${S}"/${PN}-3.1.1-libtool-ranlib.patch
  99. epatch "${S}"/${PN}-3.1.1-no-headers.patch
  100. epatch "${S}"/${PN}-4.0-no-oss-dir.patch
  101. epatch "${S}"/cctools-839-intel-retf.patch
  102. epatch "${S}"/${PN}-5.1-extraneous-includes.patch
  103. #epatch "${S}"/${PN}-5.1-otool-stdc.patch
  104. epatch "${S}"/${PN}-5.1-constant-types.patch
  105. epatch "${S}"/${PN}-5.1-strnlen.patch
  106. epatch "${S}"/${PN}-5.1-ppc.patch
  107. epatch "${S}"/${PN}-5.1-thread-state-redefined.patch
  108. epatch "${S}"/${PN}-7.0-make-j.patch
  109. epatch "${S}"/${PN}-7.0-lto-prefix-2.patch
  110. epatch "${S}"/${PN}-7.0-clang-as.patch
  111. epatch "${S}"/${PN}-7.0-nolto.patch
  112. epatch "${S}"/${PN}-7.0-nollvm.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. ENABLE_LTO=0
  154. use lto && ENABLE_LTO=1
  155. export CTARGET=${CTARGET:-${CHOST}}
  156. if [[ ${CTARGET} == ${CHOST} ]] ; then
  157. if [[ ${CATEGORY} == cross-* ]] ; then
  158. export CTARGET=${CATEGORY#cross-}
  159. fi
  160. fi
  161. LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
  162. INCPATH=${LIBPATH}/include
  163. DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
  164. if is_cross ; then
  165. BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${PV}
  166. else
  167. BINPATH=/usr/${CTARGET}/binutils-bin/${PV}
  168. fi
  169. # CPPFLAGS only affects ld64, cctools don't use 'em (which currently is
  170. # what we want)
  171. append-cppflags -DNDEBUG
  172. # Block API and thus snapshots supported on >= 10.6
  173. [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -ge 10 ]] && \
  174. append-cppflags -DSUPPORT_SNAPSHOTS
  175. CCTOOLS_OFLAG=
  176. if [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -le 8 ]] ; then
  177. # cctools expect to use UNIX03 struct member names.
  178. # This is default on > 10.4. Activate it on <= 10.4 by defining
  179. # __DARWIN_UNIX03 explicitly.
  180. CCTOOLS_OFLAG="-D__DARWIN_UNIX03=1"
  181. fi
  182. # if compiling with USE multitarget, extract all the known arches from
  183. # create_configure and pass them back to it
  184. creco=${LD64}/src/create_configure
  185. ARCHS_TO_SUPPORT=""
  186. if use multitarget ; then
  187. ARCHS_TO_SUPPORT="$(grep KNOWN_ARCHS= $creco | \
  188. cut -d\" -f2 | tr ',' ' ')"
  189. fi
  190. # Create configure.h for ld64 with SUPPORT_ARCH_<arch> defines in it.
  191. DERIVED_FILE_DIR=${LD64}/src \
  192. RC_SUPPORTED_ARCHS="$ARCHS_TO_SUPPORT" \
  193. $creco
  194. # do not depend on MachOFileAbstraction.hpp to define
  195. # SUPPORT_ARCH_arm_any because that's not included by every file where
  196. # our ppc/arm-optional patch uses it, ld.hpp in particular
  197. grep "SUPPORT_ARCH_armv[0-9]" ${LD64}/src/configure.h >/dev/null && \
  198. echo "#define SUPPORT_ARCH_arm_any 1" >> ${LD64}/src/configure.h
  199. }
  200. compile_ld64() {
  201. einfo "building ${LD64}"
  202. cd "${S}"/${LD64}/src
  203. emake \
  204. LTO=${ENABLE_LTO} \
  205. || die "emake failed for ld64"
  206. use test && emake build_test
  207. }
  208. compile_cctools() {
  209. einfo "building ${CCTOOLS}"
  210. cd "${S}"/${CCTOOLS}
  211. # Suppress running dsymutil because it will warn about missing debug
  212. # info which is expected when compiling without -g as we normally do.
  213. # This might need some more thought if anyone ever wanted to build us
  214. # for debugging with Apple's tools.
  215. emake \
  216. LIB_PRUNETRIE="-L../../${LD64}/src -lprunetrie" \
  217. EFITOOLS= \
  218. LTO="${ENABLE_LTO}" \
  219. LTO_LIBDIR=../../../lib \
  220. COMMON_SUBDIRS='libstuff ar misc otool' \
  221. SUBDIRS_32= \
  222. LEGACY= \
  223. RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
  224. RC_CFLAGS="${CFLAGS}" \
  225. OFLAG="${CCTOOLS_OFLAG}" \
  226. DSYMUTIL=": disabled: dsymutil" \
  227. || die "emake failed for the cctools"
  228. cd "${S}"/${CCTOOLS}/as
  229. emake \
  230. BUILD_OBSOLETE_ARCH= \
  231. RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
  232. RC_CFLAGS="-DASLIBEXECDIR=\"\\\"${EPREFIX}${LIBPATH}/\\\"\" -DCLANGDIR=\"\\\"${EPREFIX}/usr/bin/\\\"\" ${CFLAGS}" \
  233. OFLAG="${CCTOOLS_OFLAG}" \
  234. DSYMUTIL=": disabled: dsymutil" \
  235. || die "emake failed for as"
  236. }
  237. src_compile() {
  238. compile_ld64
  239. compile_cctools
  240. }
  241. install_ld64() {
  242. exeinto ${BINPATH}
  243. doexe "${S}"/${LD64}/src/{ld64,rebase,dyldinfo,unwinddump,ObjectDump}
  244. dosym ld64 ${BINPATH}/ld
  245. insinto ${DATAPATH}/man/man1
  246. doins "${S}"/${LD64}/doc/man/man1/{ld,ld64,rebase}.1
  247. }
  248. install_cctools() {
  249. cd "${S}"/${CCTOOLS}
  250. emake install_all_but_headers \
  251. EFITOOLS= \
  252. COMMON_SUBDIRS='ar misc otool' \
  253. SUBDIRS_32= \
  254. DSTROOT=\"${D}\" \
  255. BINDIR=\"${EPREFIX}\"${BINPATH} \
  256. LOCBINDIR=\"${EPREFIX}\"${BINPATH} \
  257. USRBINDIR=\"${EPREFIX}\"${BINPATH} \
  258. LOCLIBDIR=\"${EPREFIX}\"${LIBPATH} \
  259. MANDIR=\"${EPREFIX}\"${DATAPATH}/man/
  260. cd "${S}"/${CCTOOLS}/as
  261. emake install \
  262. BUILD_OBSOLETE_ARCH= \
  263. DSTROOT=\"${D}\" \
  264. USRBINDIR=\"${EPREFIX}\"${BINPATH} \
  265. LIBDIR=\"${EPREFIX}\"${LIBPATH} \
  266. LOCLIBDIR=\"${EPREFIX}\"${LIBPATH}
  267. cd "${ED}"${BINPATH}
  268. insinto ${DATAPATH}/man/man1
  269. local skips manpage
  270. # ar brings an up-to-date manpage with it
  271. skips=( ar )
  272. for bin in *; do
  273. for skip in ${skips[@]}; do
  274. if [[ ${bin} == ${skip} ]]; then
  275. continue 2;
  276. fi
  277. done
  278. manpage=${S}/${CCTOOLS}/man/${bin}.1
  279. if [[ -f "${manpage}" ]]; then
  280. doins "${manpage}"
  281. fi
  282. done
  283. insinto ${DATAPATH}/man/man5
  284. doins "${S}"/${CCTOOLS}/man/*.5
  285. }
  286. src_test() {
  287. if ! [ "${EPREFIX}"/usr/bin/clang ] ; then
  288. einfo "Test suite only works properly with clang - please install"
  289. return
  290. fi
  291. einfo "Running unit tests"
  292. cd "${S}"/${LD64}/unit-tests/test-cases
  293. # provide the new ld as a symlink to clang so that -ccc-install-dir
  294. # will pick it up
  295. ln -sfn ../../src/ld64 ld
  296. # use our arch command because the System's will report i386 even for an
  297. # x86_64 prefix
  298. perl ../bin/make-recursive.pl \
  299. BUILT_PRODUCTS_DIR="${S}"/${LD64}/src \
  300. ARCH="$(arch)" \
  301. LD="${S}"/${LD64}/src/ld64 \
  302. CC="${CC} -ccc-install-dir $PWD" \
  303. CXX="${CXX} -ccc-install-dir $PWD" \
  304. OTOOL="${S}"/${CCTOOLS}/otool/otool.NEW \
  305. | perl ../bin/result-filter.pl
  306. }
  307. src_install() {
  308. install_ld64
  309. install_cctools
  310. cd "${S}"
  311. insinto /etc/env.d/binutils
  312. cat <<-EOF > env.d
  313. TARGET="${CHOST}"
  314. VER="${PV}"
  315. FAKE_TARGETS="${CHOST}"
  316. EOF
  317. newins env.d ${CHOST}-${PV}
  318. }
  319. pkg_postinst() {
  320. binutils-config ${CHOST}-${PV}
  321. }