Use https by default
[gentoo.git] / sys-devel / binutils-apple / binutils-apple-4.3.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI="3"
6
7 inherit eutils flag-o-matic toolchain-funcs
8
9 RESTRICT="test" # the test suite will test what's installed.
10
11 LD64=ld64-128.2
12 CCTOOLS=cctools-822
13 LIBUNWIND=libunwind-30
14 DYLD=dyld-195.6
15 # http://lists.apple.com/archives/Darwin-dev/2009/Sep/msg00025.html
16 UNWIND=binutils-apple-3.2-unwind-patches-5
17
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"
26
27 LICENSE="APSL-2"
28 KEYWORDS="~x64-macos ~x86-macos"
29 IUSE="lto test"
30
31 RDEPEND="sys-devel/binutils-config
32         lto? ( sys-devel/llvm )"
33 DEPEND="${RDEPEND}
34         test? ( >=dev-lang/perl-5.8.8 )
35         >=sys-devel/gcc-apple-4.2.1"
36
37 export CTARGET=${CTARGET:-${CHOST}}
38 if [[ ${CTARGET} == ${CHOST} ]] ; then
39         if [[ ${CATEGORY} == cross-* ]] ; then
40                 export CTARGET=${CATEGORY#cross-}
41         fi
42 fi
43 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
44
45 if is_cross ; then
46         SLOT="${CTARGET}-4"
47 else
48         SLOT="4"
49 fi
50
51 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
52 INCPATH=${LIBPATH}/include
53 DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
54 if is_cross ; then
55         BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${PV}
56 else
57         BINPATH=/usr/${CTARGET}/binutils-bin/${PV}
58 fi
59
60 S=${WORKDIR}
61
62 src_prepare() {
63         cd "${S}"/${LIBUNWIND}/src
64         cp "${FILESDIR}"/${LIBUNWIND}-Makefile Makefile
65
66         cd "${S}"/${LD64}/src
67         cp "${FILESDIR}"/ld64-128.2-Makefile Makefile
68         epatch "${FILESDIR}"/ld64-127.2-lto.patch
69         epatch "${FILESDIR}"/ld64-128.2-stdlib.patch
70
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
81                 {
82                         echo "#define __OSX_AVAILABLE_STARTING(x,y)  "
83                         echo "#define __OSX_AVAILABLE_BUT_DEPRECATED(a,b,c,d)  "
84                 } > include/Availability.h
85         fi
86
87         echo '' > configure.h
88         echo '' > linker_opts
89         local VER_STR="\"@(#)PROGRAM:ld  PROJECT:${LD64} (Gentoo ${PN}-${PVR})\\n\""
90         echo "char ldVersionString[] = ${VER_STR};" > version.cpp
91
92         epatch "${FILESDIR}"/ld64-123.2-debug-backtrace.patch
93         if use !lto ; then
94                 sed -i -e '/#define LTO_SUPPORT 1/d' other/ObjectDump.cpp || die
95         fi
96
97         cd "${S}"/${CCTOOLS}
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
106
107         local program
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");
113                 _EOF
114                 [[ ${program} != "libmacho" ]] && \
115                         echo '__IDSTRING(VERS_NUM,"apple");' >> ${program}/vers.c
116         done
117
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
127
128         # clean up test suite
129         cd "${S}"/${LD64}
130 #       epatch "${FILESDIR}"/${PN}-3.1.1-testsuite.patch
131
132         cd "${S}"/${LD64}/unit-tests/test-cases
133         local c
134
135         # we don't have llvm
136         ((++c)); rm -rf llvm-integration;
137
138         # we don't have dtrace
139         ((++c)); rm -rf dtrace-static-probes-coalescing;
140         ((++c)); rm -rf dtrace-static-probes;
141
142         # a file is missing
143         ((++c)); rm -rf eh-coalescing-r
144
145         # we don't do universal binaries
146         ((++c)); rm -rf blank-stubs;
147
148         # looks like a problem with apple's result-filter.pl
149         ((++c)); rm -rf implicit-common3;
150         ((++c)); rm -rf order_file-ans;
151
152         # TODO no idea what goes wrong here
153         ((++c)); rm -rf dwarf-debug-notes;
154
155         einfo "Deleted $c tests that were bound to fail"
156
157         cd "${S}"
158         ebegin "cleaning Makefiles from unwanted CFLAGS"
159         find . -name "Makefile" -print0 | xargs -0 sed \
160                 -i \
161                 -e 's/ -g / /g' \
162                 -e 's/^OFLAG =.*$/OFLAG =/' \
163                 -e 's/install -c -s/install/g'
164         eend $?
165
166         # -pg is used and the two are incompatible
167         filter-flags -fomit-frame-pointer
168 }
169
170 src_configure() {
171         tc-export CC CXX AR
172         if use lto ; then
173                 append-cppflags -DLTO_SUPPORT
174                 append-ldflags -L"${EPREFIX}"/usr/$(get_libdir)/llvm
175                 append-libs LTO
176                 LTO=1
177         else
178                 append-cppflags -ULTO_SUPPORT
179                 LTO=0
180         fi
181         append-cppflags -DNDEBUG
182         append-cppflags -I"${WORKDIR}"/libunwind/include
183 }
184
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
190 }
191
192 compile_ld64() {
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}
198         emake \
199                 LTO=${LTO} \
200                 CFLAGS="${CFLAGS}" \
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,}
207 }
208
209 compile_cctools() {
210         einfo "building ${CCTOOLS}"
211         cd "${S}"/${CCTOOLS}
212         # -j1 because it fails too often with weird errors
213         emake \
214                 LIB_PRUNETRIE="-L../../${LD64}/src -lprunetrie" \
215                 EFITOOLS= LTO= \
216                 COMMON_SUBDIRS='libstuff ar misc otool' \
217                 SUBDIRS_32= \
218                 RC_CFLAGS="${CFLAGS}" OFLAG="${CFLAGS}" \
219                 -j1 \
220                 || die "emake failed for the cctools"
221         cd "${S}"/${CCTOOLS}/as
222         emake \
223                 BUILD_OBSOLETE_ARCH= \
224                 RC_CFLAGS="-DASLIBEXECDIR=\"\\\"${EPREFIX}${LIBPATH}/\\\"\" ${CFLAGS}" \
225                 || die "emake failed for as"
226 }
227
228 src_compile() {
229         compile_ld64
230         compile_cctools
231 }
232
233 install_ld64() {
234         exeinto ${BINPATH}
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
239 }
240
241 install_cctools() {
242         cd "${S}"/${CCTOOLS}
243         emake install_all_but_headers \
244                 EFITOOLS= LTO= \
245                 COMMON_SUBDIRS='ar misc otool' \
246                 SUBDIRS_32= \
247                 RC_CFLAGS="${CFLAGS}" OFLAG="${CFLAGS}" \
248                 DSTROOT=\"${D}\" \
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
255         emake install \
256                 BUILD_OBSOLETE_ARCH= \
257                 DSTROOT=\"${D}\" \
258                 USRBINDIR=\"${EPREFIX}\"${BINPATH} \
259                 LIBDIR=\"${EPREFIX}\"${LIBPATH} \
260                 LOCLIBDIR=\"${EPREFIX}\"${LIBPATH}
261
262         cd "${ED}"${BINPATH}
263         insinto ${DATAPATH}/man/man1
264         local skips manpage
265         # ar brings an up-to-date manpage with it
266         skips=( ar )
267         for bin in *; do
268                 for skip in ${skips[@]}; do
269                         if [[ ${bin} == ${skip} ]]; then
270                                 continue 2;
271                         fi
272                 done
273                 manpage=${S}/${CCTOOLS}/man/${bin}.1
274                 if [[ -f "${manpage}" ]]; then
275                         doins "${manpage}"
276                 fi
277         done
278         insinto ${DATAPATH}/man/man5
279         doins "${S}"/${CCTOOLS}/man/*.5
280 }
281
282 src_test() {
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
286         tc-export CC CXX
287         perl ../bin/make-recursive.pl \
288                 ARCH="$(/usr/bin/arch)" \
289                 RELEASEDIR="${S}"/${LD64}/src \
290                 | perl ../bin/result-filter.pl
291 }
292
293 src_install() {
294         install_ld64
295         install_cctools
296
297         cd "${S}"
298         insinto /etc/env.d/binutils
299         cat <<-EOF > env.d
300                 TARGET="${CHOST}"
301                 VER="${PV}"
302                 FAKE_TARGETS="${CHOST}"
303         EOF
304         newins env.d ${CHOST}-${PV}
305 }
306
307 pkg_postinst() {
308         binutils-config ${CHOST}-${PV}
309 }