x11-libs/libast: import
[portage-prefix-bleeding-edge-ebuilds.git] / sys-devel / gcc-apple / gcc-apple-4.0.1_p5363-r1.ebuild
blob519320bb8ee9c579d0f940cab9e7c20effa88e62
1 # Copyright 1999-2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
5 EAPI="prefix"
7 inherit eutils
9 GCC_VERS=${PV/_p*/}
10 APPLE_VERS=${PV/*_p/}
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-}
22 is_crosscompile() {
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
31 SLOT="${CTARGET}-40"
32 else
33 SLOT="40"
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"
44 DEPEND="${RDEPEND}
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}
53 else
54 BINPATH=${EPREFIX}/usr/${CTARGET}/gcc-bin/${GCC_VERS}
57 src_unpack() {
58 unpack ${A}
59 cd "${S}"
60 # we use our libtool
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
64 # in a cross-compile)
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."
73 src_compile() {
74 local langs="c"
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 \
83 --bindir=${BINPATH} \
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/\.*/} \
89 --host=${CHOST} \
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
103 CFLAGS="-O2 -pipe"
105 local VAR="CFLAGS_"${CTARGET//-/_}
106 CXXFLAGS=${!VAR}
108 [[ -n ${CBUILD} ]] && myconf="${myconf} --build=${CBUILD}"
110 # Native Language Support
111 if use nls ; then
112 myconf="${myconf} --enable-nls --without-included-gettext"
113 else
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
119 myconf="${myconf} \
120 --with-system-zlib \
121 --disable-checking \
122 --disable-werror \
123 --disable-libunwind-exceptions"
125 # languages to build
126 myconf="${myconf} --enable-languages=${langs}"
128 # ???
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
135 # want it to use
136 myconf="${myconf} \
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
148 cd "${T}"
149 echo '
150 #include <stdio.h>
152 int main() {
153 printf("%d\n", sizeof(size_t) * 8);
155 ' > bits.c
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"
161 else
162 # ld64 doesn't compile on non-Darwin hosts, 64-bits building is broken
163 # on x86_64-darwin
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"
174 src_install() {
175 cd "${WORKDIR}"/build
176 # -jX doesn't work
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
183 dodir /etc/env.d/gcc
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)
195 [[ -z ${BITS} ]] \
196 && BITS="32" \
197 || BITS="32 ${BITS}"
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}
206 pkg_postinst() {
207 # beware this also switches when it's on another branch version of GCC
208 gcc-config ${CTARGET}-${GCC_VERS}
211 pkg_postrm() {
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}
219 return 0