1 # Copyright 1999-2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
9 inherit eutils toolchain flag-o-matic autotools
13 LIBSTDCXX_APPLE_VERSION
=16
14 DESCRIPTION
="Apple branch of the GNU Compiler Collection, Xcode Tools 3.1"
15 HOMEPAGE
="http://gcc.gnu.org"
16 SRC_URI
="http://www.opensource.apple.com/darwinsource/tarballs/other/gcc_42-${APPLE_VERS}.tar.gz
17 http://www.opensource.apple.com/darwinsource/tarballs/other/libstdcxx-${LIBSTDCXX_APPLE_VERSION}.tar.gz"
18 LICENSE
="APSL-2 GPL-2"
20 if is_crosscompile
; then
26 KEYWORDS
="~ppc-macos ~x86-macos"
28 IUSE
="nls objc objc++ nocxx"
30 RDEPEND
=">=sys-libs/zlib-1.1.4
31 >=sys-libs/ncurses-5.2-r2
32 nls? ( sys-devel/gettext )
33 >=sys-devel/gcc-config-1.3.12-r4"
35 >=sys-apps/texinfo-4.2-r4
36 >=sys-devel/bison-1.875
37 ${CATEGORY}/binutils-apple
38 >=dev-libs/mpfr-2.2.0_p10"
40 S
=${WORKDIR}/gcc_42-
${APPLE_VERS}
42 # TPREFIX is the prefix of the CTARGET installation
43 export TPREFIX
=${TPREFIX:-${EPREFIX}}
45 LIBPATH
=${EPREFIX}/usr/lib/gcc/${CTARGET}/${GCC_VERS}
46 if is_crosscompile
; then
47 BINPATH
=${EPREFIX}/usr/${CHOST}/${CTARGET}/gcc-bin/${GCC_VERS}
49 BINPATH
=${EPREFIX}/usr/${CTARGET}/gcc-bin/${GCC_VERS}
51 STDCXX_INCDIR
=${LIBPATH}/include
/g
++-v${GCC_VERS/\.*/}
57 sed -i -e "s:/usr/bin/libtool:${EPREFIX}/usr/bin/${CTARGET}-libtool:" \
58 gcc
/config
/darwin.h || die
"sed gcc/config/darwin.h failed"
59 # add prefixed Frameworks to default search paths (may want to change this
61 sed -i -e "/\"\/System\/Library\/Frameworks\"\,/i\ \ \"${EPREFIX}/Frameworks\"\, " \
62 gcc
/config
/darwin-c.c || die
"sed gcc/config/darwin-c.c failed"
64 # Workaround deprecated "+Nc" syntax for GNU tail(1)
65 sed -i -e "s:tail +16c:tail -c +16:g" \
66 gcc
/Makefile.
in || die
"sed gcc/Makefile.in failed."
68 epatch
"${FILESDIR}"/${PN}-4.0
.1_p5465-default-altivec.
patch
70 # dsymutil stuff breaks on 10.4/x86, revert it
71 [[ ${CHOST} == *86*-apple-darwin8 ]] && \
72 epatch
"${FILESDIR}"/${PN}-${GCC_VERS}-dsymutil.patch
74 # bootstrapping might fail with host provided gcc on 10.4/x86
75 if ! is_crosscompile && ! echo "int main
(){return 0;}" | gcc -o /dev/null \
76 -mdynamic-no-pic -x c - >/dev/null 2>&1;
78 einfo "-mdynamic-no-pic doesn
't work - disabling..."
79 echo "BOOT_CFLAGS=-g -O2" > config/mh-x86-darwin
80 XD=gcc/config/i386/x-darwin
81 awk 'BEGIN
{x
=1}{if ($0 ~
"use -mdynamic-no-pic to build x86")
82 {x
=1-x} else if (x
) print
}' $XD > t && mv t $XD \
83 || die "Failed to rewrite $XD"
86 epatch "${FILESDIR}"/${PN}-${GCC_VERS}-texinfo.patch
87 cd "${S}"/gcc && eautoconf
88 cd "${S}"/libgomp && eautoconf
90 cd "${WORKDIR}"/libstdcxx-${LIBSTDCXX_APPLE_VERSION}/libstdcxx
91 epatch "${FILESDIR}"/libstdc++-${LIBSTDCXX_APPLE_VERSION}.patch
96 use nocxx || langs="${langs},c++"
97 use objc && langs="${langs},objc"
98 use objc++ && langs="${langs/,objc/},objc,obj-c++" # need objc with objc++
100 local myconf="${myconf} \
101 --prefix=${EPREFIX}/usr \
102 --bindir=${BINPATH} \
103 --includedir=${LIBPATH}/include \
104 --datadir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS} \
105 --mandir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS}/man \
106 --infodir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS}/info \
107 --libdir=${LIBPATH} \
108 --with-gxx-include-dir=${STDCXX_INCDIR} \
111 if is_crosscompile ; then
112 # Straight from the GCC install doc:
113 # "GCC has code to correctly determine the correct value for target
114 # for nearly all native systems. Therefore, we highly recommend you
115 # not provide a configure target when configuring a native compiler."
116 myconf="${myconf} --target=${CTARGET}"
118 # Tell compiler where to find what it needs
119 myconf="${myconf} --with-sysroot=${EPREFIX}/usr/${CTARGET}"
121 # Set this to something sane for both native and target
124 local VAR="CFLAGS_"${CTARGET//-/_}
127 [[ -n ${CBUILD} ]] && myconf="${myconf} --build=${CBUILD}"
129 # Native Language Support
131 myconf="${myconf} --enable-nls --without-included-gettext"
133 myconf="${myconf} --disable-nls"
136 # reasonably sane globals (hopefully)
143 myconf="${myconf} --enable-shared --enable-threads=posix"
145 # make clear we're
in an offset
146 use prefix
&& myconf
="${myconf} --with-local-prefix=${TPREFIX}/usr"
148 # we don't use a GNU linker, so tell GCC where to find the linker stuff we
151 --with-as=${EPREFIX}/usr/bin/${CTARGET}-as \
152 --with-ld=${EPREFIX}/usr/bin/${CTARGET}-ld"
154 # make sure we never do multilib stuff, for that we need a different Prefix
155 myconf
="${myconf} --disable-multilib"
157 #libstdcxx does not support this one
158 local gccconf
="${myconf} --enable-languages=${langs}"
160 # The produced libgcc_s.dylib is faulty if using a bit too much
161 # optimisation. Nail it down to something sane
165 # http://gcc.gnu.org/ml/gcc-patches/2006-11/msg00765.html
166 # (won't hurt if already 64-bits, but is essential when coming from a
167 # multilib compiler -- the default)
168 [[ ${CTARGET} == powerpc64-
* ||
${CTARGET} == x86_64-
* ]] && \
171 mkdir
-p "${WORKDIR}"/build
172 cd "${WORKDIR}"/build
173 einfo
"Configuring GCC with: ${gccconf//--/\n\t--}"
174 "${S}"/configure
${gccconf} || die
"conf failed"
175 emake bootstrap || die
"emake failed"
177 local libstdcxxconf
="${myconf} --disable-libstdcxx-debug"
178 mkdir
-p "${WORKDIR}"/build_libstdcxx || die
179 cd "${WORKDIR}"/build_libstdcxx
180 #the build requires the gcc built before, so link to it
181 ln -s "${WORKDIR}"/build
/gcc
"${WORKDIR}"/build_libstdcxx
/gcc || die
182 einfo
"Configuring libstdcxx with: ${libstdcxxconf//--/\n\t--}"
183 "${WORKDIR}"/libstdcxx-${LIBSTDCXX_APPLE_VERSION}/libstdcxx/configure ${libstdcxxconf} || die "conf failed
"
184 emake all || die "emake failed
"
188 cd "${WORKDIR}"/build
190 emake -j1 DESTDIR="${D}" install || die
192 cd "${WORKDIR}"/build_libstdcxx
193 emake -j1 DESTDIR="${D}" install || die
194 cd "${WORKDIR}"/build
197 if ! is_crosscompile ; then
199 eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log)
200 [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${ED}"
203 # create gcc-config entry
205 local gcc_envd_base
="/etc/env.d/gcc/${CHOST}-${GCC_VERS}"
207 gcc_envd_file
="${ED}${gcc_envd_base}"
209 # phase PATH/ROOTPATH out ...
210 echo "PATH=\"${BINPATH}\"" > ${gcc_envd_file}
211 echo "ROOTPATH=\"${BINPATH}\"" >> ${gcc_envd_file}
212 echo "GCC_PATH=\"${BINPATH}\"" >> ${gcc_envd_file}
214 # we don't do multilib
216 echo "LDPATH=\"${LDPATH}\"" >> ${gcc_envd_file}
217 echo "MANPATH=\"${EPREFIX}/usr/share/gcc-data/${CHOST}/${GCC_VERS}/man\"" >> ${gcc_envd_file}
218 echo "INFOPATH
=\"${EPREFIX}/usr/share/gcc-data/${CHOST}/${GCC_VERS}/info\"" >> ${gcc_envd_file}
219 echo "STDCXX_INCDIR=\"g++-v${GCC_VERS/\.*/}\"" >> ${gcc_envd_file}
220 is_crosscompile
&& echo "CTARGET=${CTARGET}" >> ${gcc_envd_file}
222 # Move <cxxabi.h> to compiler-specific directories
223 [[ -f ${D}${STDCXX_INCDIR}/cxxabi.h
]] && \
224 mv -f "${D}"${STDCXX_INCDIR}/cxxabi.h "${D}"${LIBPATH}/include/
226 # These should be symlinks
229 for x in cpp gcc g++ c++ g77 gcj gcjh gfortran ; do
230 # For some reason, g77 gets made instead of ${CTARGET}-g77...
231 # this should take care of that
232 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
234 if [[ -f ${CTARGET}-${x} ]] && ! is_crosscompile ; then
235 ln -sf ${CTARGET}-${x} ${x}
237 # Create version-ed symlinks
238 dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} \
239 /usr/bin/${CTARGET}-${x}-${GCC_VERS}
240 dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} \
241 /usr/bin/${x}-${GCC_VERS}
244 if [[ -f ${CTARGET}-${x}-${GCC_VERS} ]] ; then
245 rm -f ${CTARGET}-${x}-${GCC_VERS}
246 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_VERS}
250 # I do not know if this will break gcj stuff, so I'll only do it for
251 # objc for now; basically "ffi.h
" is the correct file to include,
252 # but it gets installed in .../GCCVER/include and yet it does
253 # "#include <ffitarget.h>" which (correctly, as it's an "extra" file)
254 # is installed in .../GCCVER/include/libffi; the following fixes
255 # ffi.'s include of ffitarget.h - Armando Di Cianno <fafhrd@gentoo.org>
256 if [[ -d ${D}${LIBPATH}/include
/libffi
]] ; then
257 mv -i "${D}"${LIBPATH}/include/libffi/* "${D}"${LIBPATH}/include || die
258 rm -r "${D}"${LIBPATH}/include/libffi || die
261 # Now do the fun stripping stuff
262 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}"
263 env RESTRICT
="" CHOST
=${CTARGET} prepstrip "${D}${LIBPATH}"
264 # gcc used to install helper binaries in lib/ but then moved to libexec/
265 [[ -d ${ED}/usr/libexec/gcc ]] && \
266 env RESTRICT="" CHOST=${CHOST} prepstrip "${ED}/usr/libexec/gcc/${CTARGET}/${GCC_VERS}"
268 # prune empty dirs left behind
269 find "${ED}" -type d |
xargs rmdir >& /dev
/null
273 # beware this also switches when it's on another branch version of GCC
274 gcc-config
${CTARGET}-${GCC_VERS}
278 # clean up the cruft left behind by cross-compilers
279 if is_crosscompile
; then
280 if [[ -z $
(ls "${EROOT}"/etc
/env.d
/gcc
/${CTARGET}* 2>/dev
/null
) ]] ; then
281 rm -f "${EROOT}"/etc
/env.d
/gcc
/config-
${CTARGET}
282 rm -f "${EROOT}"/etc
/env.d
/??gcc-
${CTARGET}
283 rm -f "${EROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}