1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 inherit eutils flag-o-matic toolchain-funcs
9 RESTRICT="test" # the test suite will test what's installed.
13 LIBUNWIND=libunwind-30
15 # http://lists.apple.com/archives/Darwin-dev/2009/Sep/msg00025.html
16 UNWIND=binutils-apple-3.2-unwind-patches-5
18 DESCRIPTION="Darwin assembler as(1) and static linker ld(1), Xcode Tools ${PV}"
19 HOMEPAGE="http://www.opensource.apple.com/darwinsource/"
20 SRC_URI="http://www.opensource.apple.com/tarballs/ld64/${LD64}.tar.gz
21 http://www.opensource.apple.com/tarballs/cctools/${CCTOOLS}.tar.gz
22 http://www.opensource.apple.com/tarballs/libunwind/${LIBUNWIND}.tar.gz
23 http://www.opensource.apple.com/tarballs/dyld/${DYLD}.tar.gz
24 https://www.gentoo.org/~grobian/distfiles/${UNWIND}.tar.xz
25 https://www.gentoo.org/~grobian/distfiles/libunwind-llvm-115426.tar.bz2"
28 KEYWORDS="~x64-macos ~x86-macos"
31 RDEPEND="sys-devel/binutils-config
32 lto? ( sys-devel/llvm )"
34 test? ( >=dev-lang/perl-5.8.8 )
35 >=sys-devel/gcc-apple-4.2.1"
37 export CTARGET=${CTARGET:-${CHOST}}
38 if [[ ${CTARGET} == ${CHOST} ]] ; then
39 if [[ ${CATEGORY} == cross-* ]] ; then
40 export CTARGET=${CATEGORY#cross-}
43 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
51 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
52 INCPATH=${LIBPATH}/include
53 DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
55 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${PV}
57 BINPATH=/usr/${CTARGET}/binutils-bin/${PV}
63 cd "${S}"/${LIBUNWIND}/src
64 cp "${FILESDIR}"/${LIBUNWIND}-Makefile Makefile
67 cp "${FILESDIR}"/ld64-128.2-Makefile Makefile
68 epatch "${FILESDIR}"/ld64-127.2-lto.patch
69 epatch "${FILESDIR}"/ld64-128.2-stdlib.patch
71 ln -s ../../${CCTOOLS}/include
72 cp other/prune_trie.h include/mach-o/ || die
73 # use our own copy of lto.h, which doesn't require llvm build-env
74 mkdir -p include/llvm-c || die
75 cp "${WORKDIR}"/ld64-unwind/ld64-97.14-llvm-lto.h include/llvm-c/lto.h || die
76 # make libunwind sources known
77 ln -s ../../${LIBUNWIND}/src libunwind || die
78 cp ../../${LIBUNWIND}/include/*.h include/ || die
79 # mimic OS X Lion-style Availability.h macros
80 if [[ ${CHOST} == *darwin* && ${CHOST#*-darwin} -le 10 ]] ; then
82 echo "#define __OSX_AVAILABLE_STARTING(x,y) "
83 echo "#define __OSX_AVAILABLE_BUT_DEPRECATED(a,b,c,d) "
84 } > include/Availability.h
89 local VER_STR="\"@(#)PROGRAM:ld PROJECT:${LD64} (Gentoo ${PN}-${PVR})\\n\""
90 echo "char ldVersionString[] = ${VER_STR};" > version.cpp
92 epatch "${FILESDIR}"/ld64-123.2-debug-backtrace.patch
94 sed -i -e '/#define LTO_SUPPORT 1/d' other/ObjectDump.cpp || die
98 epatch "${FILESDIR}"/${PN}-4.0-as.patch
99 epatch "${FILESDIR}"/${PN}-4.2-as-dir.patch
100 epatch "${FILESDIR}"/${PN}-3.2.3-ranlib.patch
101 epatch "${FILESDIR}"/${PN}-3.1.1-libtool-ranlib.patch
102 epatch "${FILESDIR}"/${PN}-3.1.1-nmedit.patch
103 epatch "${FILESDIR}"/${PN}-3.1.1-no-headers.patch
104 epatch "${FILESDIR}"/${PN}-4.0-no-oss-dir.patch
105 epatch "${FILESDIR}"/${PN}-4.2-lto.patch
108 for program in ar efitools gprof libmacho misc otool ; do
109 VER_STR="@(#)PROGRAM:${program} PROJECT:${CCTOOLS} (Gentoo ${PN}-${PVR}) DEVELOPER:${PORTAGE_ROOT_USER} BUILT:$(date)"
110 cat > ${program}/vers.c <<- _EOF
111 #include <sys/cdefs.h>
112 __IDSTRING(SGS_VERS,"${VER_STR}\n");
114 [[ ${program} != "libmacho" ]] && \
115 echo '__IDSTRING(VERS_NUM,"apple");' >> ${program}/vers.c
118 VER_STR="${CCTOOLS} (Gentoo ${PN}-${PVR})"
119 echo "const char apple_version[] = \"${VER_STR}\";" \
120 >> as/apple_version.c || die
121 echo "const char apple_version[] = \"${VER_STR})\";" \
122 >> efitools/vers.c || die
123 echo "const char apple_version[] = \"${VER_STR})\";" \
124 >> ld/ld_vers.c || die
125 echo "const char apple_version[] = \"${VER_STR})\";" \
126 >> misc/vers.c || die
128 # clean up test suite
130 # epatch "${FILESDIR}"/${PN}-3.1.1-testsuite.patch
132 cd "${S}"/${LD64}/unit-tests/test-cases
136 ((++c)); rm -rf llvm-integration;
138 # we don't have dtrace
139 ((++c)); rm -rf dtrace-static-probes-coalescing;
140 ((++c)); rm -rf dtrace-static-probes;
143 ((++c)); rm -rf eh-coalescing-r
145 # we don't do universal binaries
146 ((++c)); rm -rf blank-stubs;
148 # looks like a problem with apple's result-filter.pl
149 ((++c)); rm -rf implicit-common3;
150 ((++c)); rm -rf order_file-ans;
152 # TODO no idea what goes wrong here
153 ((++c)); rm -rf dwarf-debug-notes;
155 einfo "Deleted $c tests that were bound to fail"
158 ebegin "cleaning Makefiles from unwanted CFLAGS"
159 find . -name "Makefile" -print0 | xargs -0 sed \
162 -e 's/^OFLAG =.*$/OFLAG =/' \
163 -e 's/install -c -s/install/g'
166 # -pg is used and the two are incompatible
167 filter-flags -fomit-frame-pointer
173 append-cppflags -DLTO_SUPPORT
174 append-ldflags -L"${EPREFIX}"/usr/$(get_libdir)/llvm
178 append-cppflags -ULTO_SUPPORT
181 append-cppflags -DNDEBUG
182 append-cppflags -I"${WORKDIR}"/libunwind/include
185 compile_libunwind() {
186 # not used, just for testing, and possible use in the future
187 einfo "building ${LIBUNWIND}"
188 cd "${S}"/${LIBUNWIND}/src
189 emake DYLDINCS=-I../../${DYLD}/include || die
193 einfo "building ${LD64}"
194 cd "${S}"/${LD64}/src
195 # remove antiquated copy that's available on any OSX system and
196 # breaks ld64 compilation
197 mv include/mach-o/dyld.h{,.disable}
201 CXXFLAGS="${CXXFLAGS} -I../../${DYLD}/include" \
202 LDFLAGS="${LDFLAGS} ${LIBS}" \
203 || die "emake failed for ld64"
204 use test && emake build_test
205 # restore, it's necessary for cctools' install
206 mv include/mach-o/dyld.h{.disable,}
210 einfo "building ${CCTOOLS}"
212 # -j1 because it fails too often with weird errors
214 LIB_PRUNETRIE="-L../../${LD64}/src -lprunetrie" \
216 COMMON_SUBDIRS='libstuff ar misc otool' \
218 RC_CFLAGS="${CFLAGS}" OFLAG="${CFLAGS}" \
220 || die "emake failed for the cctools"
221 cd "${S}"/${CCTOOLS}/as
223 BUILD_OBSOLETE_ARCH= \
224 RC_CFLAGS="-DASLIBEXECDIR=\"\\\"${EPREFIX}${LIBPATH}/\\\"\" ${CFLAGS}" \
225 || die "emake failed for as"
235 doexe "${S}"/${LD64}/src/{ld64,rebase,dyldinfo,unwinddump,ObjectDump}
236 dosym ld64 ${BINPATH}/ld
237 insinto ${DATAPATH}/man/man1
238 doins "${S}"/${LD64}/doc/man/man1/{ld,ld64,rebase}.1
243 emake install_all_but_headers \
245 COMMON_SUBDIRS='ar misc otool' \
247 RC_CFLAGS="${CFLAGS}" OFLAG="${CFLAGS}" \
249 BINDIR=\"${EPREFIX}\"${BINPATH} \
250 LOCBINDIR=\"${EPREFIX}\"${BINPATH} \
251 USRBINDIR=\"${EPREFIX}\"${BINPATH} \
252 LOCLIBDIR=\"${EPREFIX}\"${LIBPATH} \
253 MANDIR=\"${EPREFIX}\"${DATAPATH}/man/
254 cd "${S}"/${CCTOOLS}/as
256 BUILD_OBSOLETE_ARCH= \
258 USRBINDIR=\"${EPREFIX}\"${BINPATH} \
259 LIBDIR=\"${EPREFIX}\"${LIBPATH} \
260 LOCLIBDIR=\"${EPREFIX}\"${LIBPATH}
263 insinto ${DATAPATH}/man/man1
265 # ar brings an up-to-date manpage with it
268 for skip in ${skips[@]}; do
269 if [[ ${bin} == ${skip} ]]; then
273 manpage=${S}/${CCTOOLS}/man/${bin}.1
274 if [[ -f "${manpage}" ]]; then
278 insinto ${DATAPATH}/man/man5
279 doins "${S}"/${CCTOOLS}/man/*.5
283 einfo "Running unit tests"
284 cd "${S}"/${LD64}/unit-tests/test-cases
285 # need host arch, since GNU arch doesn't do what Apple's does
287 perl ../bin/make-recursive.pl \
288 ARCH="$(/usr/bin/arch)" \
289 RELEASEDIR="${S}"/${LD64}/src \
290 | perl ../bin/result-filter.pl
298 insinto /etc/env.d/binutils
302 FAKE_TARGETS="${CHOST}"
304 newins env.d ${CHOST}-${PV}
308 binutils-config ${CHOST}-${PV}