1 # Copyright 1999-2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
11 DESCRIPTION
="Apple branch of the GNU Compiler Collection, Xcode 2.4"
12 HOMEPAGE
="http://gcc.gnu.org"
13 SRC_URI
="http://www.opensource.apple.com/darwinsource/tarballs/other/gcc-${APPLE_VERS}.tar.gz"
15 # Magic from toolchain.eclass
16 export CTARGET
=${CTARGET:-${CHOST}}
17 if [[ ${CTARGET} = ${CHOST} ]] ; then
18 if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
19 export CTARGET
=${CATEGORY/cross-}
23 [[ ${CHOST} != ${CTARGET} ]]
26 # TPREFIX is the prefix of the CTARGET installation
27 export TPREFIX
=${TPREFIX:-${EPREFIX}}
29 LICENSE
="APSL-2 GPL-2"
30 if is_crosscompile
; then
36 KEYWORDS
="~ppc-macos ~x86-macos ~x86-solaris"
38 IUSE
="nls objc objc++ nocxx"
40 RDEPEND
=">=sys-libs/zlib-1.1.4
41 >=sys-libs/ncurses-5.2-r2
42 nls? ( sys-devel/gettext )
43 >=sys-devel/gcc-config-1.3.12-r4"
45 >=sys-apps/texinfo-4.2-r4
46 >=sys-devel/bison-1.875
47 ${CATEGORY}/binutils-apple"
49 S
=${WORKDIR}/gcc-
${APPLE_VERS}
51 if is_crosscompile
; then
52 BINPATH
=${EPREFIX}/usr/${CHOST}/${CTARGET}/gcc-bin/${GCC_VERS}
54 BINPATH
=${EPREFIX}/usr/${CTARGET}/gcc-bin/${GCC_VERS}
61 sed -i -e "s:/usr/bin/libtool:${EPREFIX}/usr/bin/${CTARGET}-libtool:" \
62 gcc
/config
/darwin.h || die
"sed gcc/config/darwin.h failed"
63 # add prefixed Frameworks to default search paths (may want to change this
65 sed -i -e "/\"\/System\/Library\/Frameworks\"\,/i\ \ \"${EPREFIX}/Frameworks\"\, " \
66 gcc
/config
/darwin-c.c || die
"sed gcc/config/darwin-c.c failed"
68 # Workaround deprecated "+Nc" syntax for GNU tail(1)
69 sed -i -e "s:tail +16c:tail -c +16:g" \
70 gcc
/Makefile.
in || die
"sed gcc/Makefile.in failed."
75 use nocxx || langs
="${langs},c++"
76 # use fortran && langs="${langs},f95"
77 use objc
&& langs
="${langs},objc"
78 use objc
++ && langs
="${langs/,objc/},objc,obj-c++" # need objc with objc++
79 # use gcj && langs="${langs},java"
81 local myconf
="${myconf} \
82 --prefix=${EPREFIX}/usr \
84 --includedir=${EPREFIX}/usr/lib/gcc/${CTARGET}/${GCC_VERS}/include \
85 --datadir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS} \
86 --mandir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS}/man \
87 --infodir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS}/info \
88 --with-gxx-include-dir=${EPREFIX}/usr/lib/gcc/${CTARGET}/${GCC_VERS}/include/g++-v${GCC_VERS/\.*/} \
90 --enable-version-specific-runtime-libs"
92 if is_crosscompile
; then
93 # Straight from the GCC install doc:
94 # "GCC has code to correctly determine the correct value for target
95 # for nearly all native systems. Therefore, we highly recommend you
96 # not provide a configure target when configuring a native compiler."
97 myconf
="${myconf} --target=${CTARGET}"
99 # Tell compiler where to find what it needs
100 myconf
="${myconf} --with-sysroot=${EPREFIX}/usr/${CTARGET}"
102 # Set this to something sane for both native and target
105 local VAR
="CFLAGS_"${CTARGET//-/_}
108 [[ -n ${CBUILD} ]] && myconf="${myconf} --build=${CBUILD}"
110 # Native Language Support
112 myconf="${myconf} --enable-nls --without-included-gettext"
114 myconf="${myconf} --disable-nls"
117 # reasonably sane globals (hopefully)
118 # --disable-libunwind-exceptions needed till unwind sections get fixed. see ps.m for details
123 --disable-libunwind-exceptions"
126 myconf="${myconf} --enable-languages=${langs}"
129 myconf="${myconf} --enable-shared --enable-threads=posix
"
131 # make clear we're in an offset
132 use prefix && myconf="${myconf} --with-local-prefix=${TPREFIX}/usr
"
134 # we don't use a GNU linker, so tell GCC where to find the linker stuff we
137 --with-as=${EPREFIX}/usr
/bin
/${CTARGET}-as \
138 --with-ld=${EPREFIX}/usr
/bin
/${CTARGET}-ld"
140 # <grobian@gentoo.org> - 2006-09-19:
141 # figure out whether the CPU we're on is 64-bits capable using a
142 # simple C program and requesting the compiler to compile it with
143 # 64-bits if possible. Since Apple ships multilib compilers, it
144 # will always compile 64-bits code, but might fail running,
145 # depending on the CPU, so the resulting program might fail. Thanks
146 # Tobias Hahn for working that out.
147 if [[ ${CHOST} == powerpc-apple-darwin* ]] && ! is_crosscompile ; then
153 printf("%d
\n", sizeof(size_t) * 8);
156 # native gcc doesn't come in a ${CHOST}-gcc fashion if on older Xcode
157 gcc -m64 -o bits bits.c
158 if [[ $(./bits) != 64 ]] ; then
159 myconf="${myconf} --disable-multilib"
162 # ld64 doesn't compile on non-Darwin hosts, 64-bits building is broken
164 myconf="${myconf} --disable-multilib"
167 mkdir -p "${WORKDIR}"/build
168 cd "${WORKDIR}"/build
169 einfo "Configuring GCC with
: ${myconf//--/\n\t--}"
170 "${S}"/configure ${myconf} || die "conf failed
"
171 make -j1 bootstrap || die "emake failed
"
175 cd "${WORKDIR}"/build
177 make DESTDIR="${D}" install || die
179 use build && rm -rf "${ED}"/usr/{man,share}
180 find "${ED}" -name libiberty.a -exec rm -f {} \;
182 # create gcc-config entry
184 local gcc_envd_base="/etc
/env.d
/gcc
/${CHOST}-${GCC_VERS}"
186 gcc_envd_file="${ED}${gcc_envd_base}"
188 echo "PATH
=\"${EPREFIX}/usr/${CHOST}/gcc-bin/${GCC_VERS}\"" > ${gcc_envd_file}
189 echo "ROOTPATH=\"${EPREFIX}/usr/${CHOST}/gcc-bin/${GCC_VERS}\"" >> ${gcc_envd_file}
191 LDPATH="${EPREFIX}/usr/lib/gcc/${CHOST}/${GCC_VERS}"
192 echo "LDPATH
=\"${LDPATH}\"" >> ${gcc_envd_file}
194 BITS=$(${ED}/usr/${CHOST}/gcc-bin/${GCC_VERS}/gcc -dumpspecs | grep -A1 multilib: | tail -n1 | grep -o 64 | head -n1)
198 echo "GCCBITS
=\"${BITS}\"" >> ${gcc_envd_file}
200 echo "MANPATH
=\"${EPREFIX}/usr/share/gcc-data/${CHOST}/${GCC_VERS}/man\"" >> ${gcc_envd_file}
201 echo "INFOPATH=\"${EPREFIX}/usr/share/gcc-data/${CHOST}/${GCC_VERS}/info\"" >> ${gcc_envd_file}
202 echo "STDCXX_INCDIR
=\"g
++-v${GCC_VERS/\.*/}\"" >> ${gcc_envd_file}
203 is_crosscompile && echo "CTARGET
=${CTARGET}" >> ${gcc_envd_file}
207 # beware this also switches when it's on another branch version of GCC
208 gcc-config ${CTARGET}-${GCC_VERS}
212 # clean up the cruft left behind by cross-compilers
213 if is_crosscompile ; then
214 if [[ -z $(ls "${EROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
215 rm -f "${EROOT}"/etc/env.d/gcc/config-${CTARGET}
216 rm -f "${EROOT}"/etc/env.d/??gcc-${CTARGET}
217 rm -f "${EROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}