binutils-apple-6.1-r1.ebuild 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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-241.9
  6. CCTOOLS_VERSION=862
  7. CCTOOLS=cctools-${CCTOOLS_VERSION}
  8. LIBUNWIND=libunwind-35.3
  9. DYLD=dyld-353.2.1
  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. LICENSE="APSL-2"
  20. KEYWORDS="~ppc-macos ~x64-macos ~x86-macos"
  21. IUSE="lto test libcxx multitarget"
  22. RDEPEND="sys-devel/binutils-config
  23. lto? ( sys-devel/llvm )
  24. libcxx? ( sys-libs/libcxx )"
  25. DEPEND="${RDEPEND}
  26. test? ( >=dev-lang/perl-5.8.8 )
  27. || ( >=sys-devel/gcc-apple-4.2.1 sys-devel/llvm )
  28. libcxx? ( sys-devel/llvm )"
  29. SLOT="6"
  30. S=${WORKDIR}
  31. is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
  32. src_prepare() {
  33. if use multitarget ; then
  34. ewarn "You have enabled support for non-standard target architectures"
  35. ewarn "using USE=multitarget. This includes experimental support for"
  36. ewarn "ppc and ppc64 which is a community forward-port from the last"
  37. ewarn "version of ld64 to officially support PPC."
  38. if [[ ${CHOST} == powerpc*-darwin* ]] ; then
  39. ewarn "HERE BE DRAGONS! Your system seems to be PPC which means that"
  40. ewarn "the actual usability of your Gentoo programs will depend on the"
  41. ewarn "above-mentioned experimental PPC support in the linker. Be"
  42. ewarn "sure to keep a known-to-work version like ${PN}-3.2.6 around!"
  43. fi
  44. fi
  45. cd "${S}"/${LD64}/src
  46. cp "${S}"/ld64-136-compile_stubs.h ld/compile_stubs.h
  47. cp "${S}"/ld64-236.3-Makefile-2 Makefile
  48. epatch "${S}"/ld64-236.3-nolto.patch
  49. epatch "${S}"/ld64-241.9-extraneous-includes.patch
  50. epatch "${S}"/ld64-241.9-osatomic.patch
  51. epatch "${S}"/ld64-241.9-arm64-cputype.patch
  52. epatch "${S}"/ld64-236.3-crashreporter.patch
  53. epatch "${S}"/ld64-241.9-nosnapshots.patch
  54. epatch "${S}"/ld64-241.9-ppc.patch
  55. epatch "${S}"/ld64-236.3-constant-types-2.patch
  56. epatch "${S}"/ld64-241.9-gcc-2.patch
  57. epatch "${S}"/ld64-241.9-register-names.patch
  58. epatch "${S}"/ld64-241.9-get-comm-align.patch
  59. epatch "${S}"/ld64-241.9-cc_md5.patch
  60. epatch "${S}"/ld64-241.9-lto-noremarks.patch
  61. epatch "${S}"/ld64-253.3-delete-warning.patch
  62. # We used to use our own copy of lto.h, which doesn't require llvm
  63. # build-env. Current versions of llvm provide
  64. # $EPREFIX/usr/include/llvm-c/lto.h as well as
  65. # $EPREFIX/usr/lib/libLTO.{so,dylib}, so we just use these.
  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}"/${PN}-5.1-nolto.patch
  102. epatch "${S}"/cctools-839-intel-retf.patch
  103. epatch "${S}"/${PN}-5.1-extraneous-includes.patch
  104. epatch "${S}"/${PN}-5.1-otool-stdc.patch
  105. epatch "${S}"/${PN}-5.1-constant-types.patch
  106. epatch "${S}"/${PN}-5.1-strnlen.patch
  107. epatch "${S}"/${PN}-5.1-ppc.patch
  108. epatch "${S}"/${PN}-5.1-thread-state-redefined.patch
  109. epatch "${S}"/${PN}-5.1-makefile-target-warning.patch
  110. epatch "${S}"/${PN}-6.3-lto-prefix.patch
  111. cp ../${LD64}/src/other/prune_trie.h include/mach-o/ || die
  112. # do not build profileable libstuff to save compile time
  113. sed -i -e "/^all:/s, profile , ," libstuff/Makefile
  114. # cctools version is provided to make via RC_ProjectSourceVersion which
  115. # generates and compiles it as apple_version[] into libstuff. From
  116. # there it's picked up by the individual tools. Since
  117. # RC_ProjectSourceVersion is also used as library version, we can't
  118. # just append our local version info. So we hack the libstuff Makefile
  119. # to include our Gentoo version.
  120. sed -i -e "/cctools-.*(RC_ProjectSourceVersion).*OFILE_DIR/s,Version),Version) (Gentoo ${PN}-${PVR})," \
  121. libstuff/Makefile
  122. # clean up test suite
  123. cd "${S}"/${LD64}/unit-tests/test-cases
  124. local c
  125. # we don't have llvm
  126. ((++c)); rm -rf llvm-integration;
  127. # we don't have dtrace
  128. ((++c)); rm -rf dtrace-static-probes-coalescing;
  129. ((++c)); rm -rf dtrace-static-probes;
  130. # a file is missing
  131. ((++c)); rm -rf eh-coalescing-r
  132. # we don't do universal binaries
  133. ((++c)); rm -rf blank-stubs;
  134. # looks like a problem with apple's result-filter.pl
  135. ((++c)); rm -rf implicit-common3;
  136. ((++c)); rm -rf order_file-ans;
  137. # TODO no idea what goes wrong here
  138. ((++c)); rm -rf dwarf-debug-notes;
  139. einfo "Deleted $c tests that were bound to fail"
  140. cd "${S}"
  141. ebegin "cleaning Makefiles from unwanted CFLAGS"
  142. find . -name "Makefile" -print0 | xargs -0 sed \
  143. -i \
  144. -e 's/ -g / /g' \
  145. -e 's/^G =.*$/G =/' \
  146. -e 's/^OFLAG =.*$/OFLAG =/' \
  147. -e 's/install -c -s/install/g'
  148. eend $?
  149. }
  150. src_configure() {
  151. ENABLE_LTO=0
  152. use lto && ENABLE_LTO=1
  153. export CTARGET=${CTARGET:-${CHOST}}
  154. if [[ ${CTARGET} == ${CHOST} ]] ; then
  155. if [[ ${CATEGORY} == cross-* ]] ; then
  156. export CTARGET=${CATEGORY#cross-}
  157. fi
  158. fi
  159. LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
  160. INCPATH=${LIBPATH}/include
  161. DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
  162. if is_cross ; then
  163. BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${PV}
  164. else
  165. BINPATH=/usr/${CTARGET}/binutils-bin/${PV}
  166. fi
  167. if [ "${CXX/*clang*/yes}" = "yes" ] ; then
  168. if use libcxx ; then
  169. append-cxxflags -stdlib=libc++
  170. CXXLIB=-stdlib=libc++
  171. else
  172. # force libstdc++ for systems where libc++ is default (OS X 10.9+?)
  173. append-cxxflags -stdlib=libstdc++
  174. CXXLIB=-stdlib=libstdc++
  175. fi
  176. else
  177. use libcxx && \
  178. ewarn "libcxx only available with clang and your C++ compiler ($CXX) does not seem to be clang"
  179. fi
  180. # CPPFLAGS only affects ld64, cctools don't use 'em (which currently is
  181. # what we want)
  182. append-cppflags -DNDEBUG
  183. # Block API and thus snapshots supported on >= 10.6
  184. [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -ge 10 ]] && \
  185. append-cppflags -DSUPPORT_SNAPSHOTS
  186. CCTOOLS_OFLAG=
  187. if [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -le 8 ]] ; then
  188. # cctools expect to use UNIX03 struct member names.
  189. # This is default on > 10.4. Activate it on <= 10.4 by defining
  190. # __DARWIN_UNIX03 explicitly.
  191. CCTOOLS_OFLAG="-D__DARWIN_UNIX03=1"
  192. fi
  193. # if compiling with USE multitarget, extract all the known arches from
  194. # create_configure and pass them back to it
  195. creco=${LD64}/src/create_configure
  196. ARCHS_TO_SUPPORT=""
  197. if use multitarget ; then
  198. ARCHS_TO_SUPPORT="$(grep KNOWN_ARCHS= $creco | \
  199. cut -d\" -f2 | tr ',' ' ')"
  200. fi
  201. # Create configure.h for ld64 with SUPPORT_ARCH_<arch> defines in it.
  202. DERIVED_FILE_DIR=${LD64}/src \
  203. RC_SUPPORTED_ARCHS="$ARCHS_TO_SUPPORT" \
  204. $creco
  205. # do not depend on MachOFileAbstraction.hpp to define
  206. # SUPPORT_ARCH_arm_any because that's not included by every file where
  207. # our ppc/arm-optional patch uses it, ld.hpp in particular
  208. grep "SUPPORT_ARCH_armv[0-9]" ${LD64}/src/configure.h >/dev/null && \
  209. echo "#define SUPPORT_ARCH_arm_any 1" >> ${LD64}/src/configure.h
  210. }
  211. compile_ld64() {
  212. einfo "building ${LD64}"
  213. cd "${S}"/${LD64}/src
  214. emake \
  215. LTO=${ENABLE_LTO} \
  216. || die "emake failed for ld64"
  217. use test && emake build_test
  218. }
  219. compile_cctools() {
  220. einfo "building ${CCTOOLS}"
  221. cd "${S}"/${CCTOOLS}
  222. # -j1 because it fails too often with weird errors
  223. # Suppress running dsymutil because it will warn about missing debug
  224. # info which is expected when compiling without -g as we normally do.
  225. # This might need some more thought if anyone ever wanted to build us
  226. # for debugging with Apple's tools.
  227. emake \
  228. LIB_PRUNETRIE="-L../../${LD64}/src -lprunetrie" \
  229. EFITOOLS= \
  230. ENABLE_LTO=${ENABLE_LTO} \
  231. COMMON_SUBDIRS='libstuff ar misc otool' \
  232. SUBDIRS_32= \
  233. LEGACY= \
  234. RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
  235. RC_CFLAGS="${CFLAGS}" \
  236. OFLAG="${CCTOOLS_OFLAG}" \
  237. CXXLIB="${CXXLIB}" \
  238. DSYMUTIL=": disabled: dsymutil" \
  239. -j1 \
  240. || die "emake failed for the cctools"
  241. cd "${S}"/${CCTOOLS}/as
  242. emake \
  243. BUILD_OBSOLETE_ARCH= \
  244. RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
  245. RC_CFLAGS="-DASLIBEXECDIR=\"\\\"${EPREFIX}${LIBPATH}/\\\"\" ${CFLAGS}" \
  246. OFLAG="${CCTOOLS_OFLAG}" \
  247. DSYMUTIL=": disabled: dsymutil" \
  248. || die "emake failed for as"
  249. }
  250. src_compile() {
  251. compile_ld64
  252. compile_cctools
  253. }
  254. install_ld64() {
  255. exeinto ${BINPATH}
  256. doexe "${S}"/${LD64}/src/{ld64,rebase,dyldinfo,unwinddump,ObjectDump}
  257. dosym ld64 ${BINPATH}/ld
  258. insinto ${DATAPATH}/man/man1
  259. doins "${S}"/${LD64}/doc/man/man1/{ld,ld64,rebase}.1
  260. }
  261. install_cctools() {
  262. cd "${S}"/${CCTOOLS}
  263. emake install_all_but_headers \
  264. EFITOOLS= \
  265. COMMON_SUBDIRS='ar misc otool' \
  266. SUBDIRS_32= \
  267. DSTROOT=\"${D}\" \
  268. BINDIR=\"${EPREFIX}\"${BINPATH} \
  269. LOCBINDIR=\"${EPREFIX}\"${BINPATH} \
  270. USRBINDIR=\"${EPREFIX}\"${BINPATH} \
  271. LOCLIBDIR=\"${EPREFIX}\"${LIBPATH} \
  272. MANDIR=\"${EPREFIX}\"${DATAPATH}/man/
  273. cd "${S}"/${CCTOOLS}/as
  274. emake install \
  275. BUILD_OBSOLETE_ARCH= \
  276. DSTROOT=\"${D}\" \
  277. USRBINDIR=\"${EPREFIX}\"${BINPATH} \
  278. LIBDIR=\"${EPREFIX}\"${LIBPATH} \
  279. LOCLIBDIR=\"${EPREFIX}\"${LIBPATH}
  280. cd "${ED}"${BINPATH}
  281. insinto ${DATAPATH}/man/man1
  282. local skips manpage
  283. # ar brings an up-to-date manpage with it
  284. skips=( ar )
  285. for bin in *; do
  286. for skip in ${skips[@]}; do
  287. if [[ ${bin} == ${skip} ]]; then
  288. continue 2;
  289. fi
  290. done
  291. manpage=${S}/${CCTOOLS}/man/${bin}.1
  292. if [[ -f "${manpage}" ]]; then
  293. doins "${manpage}"
  294. fi
  295. done
  296. insinto ${DATAPATH}/man/man5
  297. doins "${S}"/${CCTOOLS}/man/*.5
  298. }
  299. src_test() {
  300. if ! [ "${EPREFIX}"/usr/bin/clang ] ; then
  301. einfo "Test suite only works properly with clang - please install"
  302. return
  303. fi
  304. einfo "Running unit tests"
  305. cd "${S}"/${LD64}/unit-tests/test-cases
  306. # provide the new ld as a symlink to clang so that -ccc-install-dir
  307. # will pick it up
  308. ln -sfn ../../src/ld64 ld
  309. # use our arch command because the System's will report i386 even for an
  310. # x86_64 prefix
  311. perl ../bin/make-recursive.pl \
  312. BUILT_PRODUCTS_DIR="${S}"/${LD64}/src \
  313. ARCH="$(arch)" \
  314. LD="${S}"/${LD64}/src/ld64 \
  315. CC="clang -ccc-install-dir $PWD" \
  316. CXX="clang++ -ccc-install-dir $PWD" \
  317. OTOOL="${S}"/${CCTOOLS}/otool/otool.NEW \
  318. | perl ../bin/result-filter.pl
  319. }
  320. src_install() {
  321. install_ld64
  322. install_cctools
  323. cd "${S}"
  324. insinto /etc/env.d/binutils
  325. cat <<-EOF > env.d
  326. TARGET="${CHOST}"
  327. VER="${PV}"
  328. FAKE_TARGETS="${CHOST}"
  329. EOF
  330. newins env.d ${CHOST}-${PV}
  331. }
  332. pkg_postinst() {
  333. binutils-config ${CHOST}-${PV}
  334. }