binutils-apple-6.3-r1.ebuild 12 KB

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