x11-libs/libast: import
[portage-prefix-bleeding-edge-ebuilds.git] / sys-devel / gcc-apple / gcc-apple-4.0.1_p5465-r1.ebuild
bloba943b92b809917d008a71264511c9164e96265eb
1 # Copyright 1999-2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
5 EAPI="prefix"
7 ETYPE="gcc-compiler"
9 inherit eutils toolchain
11 GCC_VERS=${PV/_p*/}
12 APPLE_VERS=${PV/*_p/}
13 DESCRIPTION="Apple branch of the GNU Compiler Collection, from 10.5"
14 HOMEPAGE="http://gcc.gnu.org"
15 SRC_URI="http://www.opensource.apple.com/darwinsource/tarballs/other/gcc-${APPLE_VERS}.tar.gz"
16 LICENSE="APSL-2 GPL-2"
18 if is_crosscompile; then
19 SLOT="${CTARGET}-40"
20 else
21 SLOT="40"
24 KEYWORDS="~ppc-macos ~x86-macos"
26 IUSE="nls objc objc++ nocxx"
28 RDEPEND=">=sys-libs/zlib-1.1.4
29 >=sys-libs/ncurses-5.2-r2
30 nls? ( sys-devel/gettext )
31 >=sys-devel/gcc-config-1.3.12-r4"
32 DEPEND="${RDEPEND}
33 >=sys-apps/texinfo-4.2-r4
34 >=sys-devel/bison-1.875
35 ${CATEGORY}/binutils-apple"
37 S=${WORKDIR}/gcc-${APPLE_VERS}
39 # TPREFIX is the prefix of the CTARGET installation
40 export TPREFIX=${TPREFIX:-${EPREFIX}}
42 LIBPATH=${EPREFIX}/usr/lib/gcc/${CTARGET}/${GCC_VERS}
43 if is_crosscompile ; then
44 BINPATH=${EPREFIX}/usr/${CHOST}/${CTARGET}/gcc-bin/${GCC_VERS}
45 else
46 BINPATH=${EPREFIX}/usr/${CTARGET}/gcc-bin/${GCC_VERS}
48 STDCXX_INCDIR=${LIBPATH}/include/g++-v${GCC_VERS/\.*/}
50 src_unpack() {
51 unpack ${A}
52 cd "${S}"
53 # we use our libtool
54 sed -i -e "s:/usr/bin/libtool:${EPREFIX}/usr/bin/${CTARGET}-libtool:" \
55 gcc/config/darwin.h || die "sed gcc/config/darwin.h failed"
56 # add prefixed Frameworks to default search paths (may want to change this
57 # in a cross-compile)
58 sed -i -e "/\"\/System\/Library\/Frameworks\"\,/i\ \ \"${EPREFIX}/Frameworks\"\, " \
59 gcc/config/darwin-c.c || die "sed gcc/config/darwin-c.c failed"
61 # Workaround deprecated "+Nc" syntax for GNU tail(1)
62 sed -i -e "s:tail +16c:tail -c +16:g" \
63 gcc/Makefile.in || die "sed gcc/Makefile.in failed."
65 epatch "${FILESDIR}"/${P}-default-altivec.patch
68 src_compile() {
69 local langs="c"
70 use nocxx || langs="${langs},c++"
71 use objc && langs="${langs},objc"
72 use objc++ && langs="${langs/,objc/},objc,obj-c++" # need objc with objc++
74 local myconf="${myconf} \
75 --prefix=${EPREFIX}/usr \
76 --bindir=${BINPATH} \
77 --includedir=${LIBPATH}/include \
78 --datadir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS} \
79 --mandir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS}/man \
80 --infodir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS}/info \
81 --libdir=${LIBPATH} \
82 --with-gxx-include-dir=${STDCXX_INCDIR} \
83 --host=${CHOST}"
85 if is_crosscompile ; then
86 # Straight from the GCC install doc:
87 # "GCC has code to correctly determine the correct value for target
88 # for nearly all native systems. Therefore, we highly recommend you
89 # not provide a configure target when configuring a native compiler."
90 myconf="${myconf} --target=${CTARGET}"
92 # Tell compiler where to find what it needs
93 myconf="${myconf} --with-sysroot=${EPREFIX}/usr/${CTARGET}"
95 # Set this to something sane for both native and target
96 CFLAGS="-O2 -pipe"
98 local VAR="CFLAGS_"${CTARGET//-/_}
99 CXXFLAGS=${!VAR}
101 [[ -n ${CBUILD} ]] && myconf="${myconf} --build=${CBUILD}"
103 # Native Language Support
104 if use nls ; then
105 myconf="${myconf} --enable-nls --without-included-gettext"
106 else
107 myconf="${myconf} --disable-nls"
110 # reasonably sane globals (hopefully)
111 myconf="${myconf} \
112 --with-system-zlib \
113 --disable-checking \
114 --disable-werror"
116 # languages to build
117 myconf="${myconf} --enable-languages=${langs}"
119 # ???
120 myconf="${myconf} --enable-shared --enable-threads=posix"
122 # make clear we're in an offset
123 use prefix && myconf="${myconf} --with-local-prefix=${TPREFIX}/usr"
125 # we don't use a GNU linker, so tell GCC where to find the linker stuff we
126 # want it to use
127 myconf="${myconf} \
128 --with-as=${EPREFIX}/usr/bin/${CTARGET}-as \
129 --with-ld=${EPREFIX}/usr/bin/${CTARGET}-ld"
131 # make sure we never do multilib stuff, for that we need a different Prefix
132 myconf="${myconf} --disable-multilib"
134 # The produced libgcc_s.dylib is faulty if using a bit too much
135 # optimisation. Nail it down to something sane
136 CFLAGS="-O2 -pipe"
137 CXXFLAGS=${CFLAGS}
139 # http://gcc.gnu.org/ml/gcc-patches/2006-11/msg00765.html
140 # (won't hurt if already 64-bits, but is essential when coming from a
141 # multilib compiler -- the default)
142 [[ ${CTARGET} == powerpc64-* || ${CTARGET} == x86_64-* ]] && \
143 export CC="gcc -m64"
145 mkdir -p "${WORKDIR}"/build
146 cd "${WORKDIR}"/build
147 einfo "Configuring GCC with: ${myconf//--/\n\t--}"
148 "${S}"/configure ${myconf} || die "conf failed"
149 emake bootstrap || die "emake failed"
152 src_install() {
153 cd "${WORKDIR}"/build
154 # -jX doesn't work
155 emake -j1 DESTDIR="${D}" install || die
157 # Basic sanity check
158 if ! is_crosscompile ; then
159 local EXEEXT
160 eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log)
161 [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${ED}"
164 # create gcc-config entry
165 dodir /etc/env.d/gcc
166 local gcc_envd_base="/etc/env.d/gcc/${CHOST}-${GCC_VERS}"
168 gcc_envd_file="${ED}${gcc_envd_base}"
170 # phase PATH/ROOTPATH out ...
171 echo "PATH=\"${BINPATH}\"" > ${gcc_envd_file}
172 echo "ROOTPATH=\"${BINPATH}\"" >> ${gcc_envd_file}
173 echo "GCC_PATH=\"${BINPATH}\"" >> ${gcc_envd_file}
175 # we don't do multilib
176 LDPATH="${LIBPATH}"
177 echo "LDPATH=\"${LDPATH}\"" >> ${gcc_envd_file}
178 echo "MANPATH=\"${EPREFIX}/usr/share/gcc-data/${CHOST}/${GCC_VERS}/man\"" >> ${gcc_envd_file}
179 echo "INFOPATH=\"${EPREFIX}/usr/share/gcc-data/${CHOST}/${GCC_VERS}/info\"" >> ${gcc_envd_file}
180 echo "STDCXX_INCDIR=\"g++-v${GCC_VERS/\.*/}\"" >> ${gcc_envd_file}
181 is_crosscompile && echo "CTARGET=${CTARGET}" >> ${gcc_envd_file}
183 # Move <cxxabi.h> to compiler-specific directories
184 [[ -f ${D}${STDCXX_INCDIR}/cxxabi.h ]] && \
185 mv -f "${D}"${STDCXX_INCDIR}/cxxabi.h "${D}"${LIBPATH}/include/
187 # These should be symlinks
188 dodir /usr/bin
189 cd "${D}"${BINPATH}
190 for x in cpp gcc g++ c++ g77 gcj gcjh gfortran ; do
191 # For some reason, g77 gets made instead of ${CTARGET}-g77...
192 # this should take care of that
193 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
195 if [[ -f ${CTARGET}-${x} ]] && ! is_crosscompile ; then
196 ln -sf ${CTARGET}-${x} ${x}
198 # Create version-ed symlinks
199 dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} \
200 /usr/bin/${CTARGET}-${x}-${GCC_VERS}
201 dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} \
202 /usr/bin/${x}-${GCC_VERS}
205 if [[ -f ${CTARGET}-${x}-${GCC_VERS} ]] ; then
206 rm -f ${CTARGET}-${x}-${GCC_VERS}
207 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_VERS}
209 done
211 # I do not know if this will break gcj stuff, so I'll only do it for
212 # objc for now; basically "ffi.h" is the correct file to include,
213 # but it gets installed in .../GCCVER/include and yet it does
214 # "#include <ffitarget.h>" which (correctly, as it's an "extra" file)
215 # is installed in .../GCCVER/include/libffi; the following fixes
216 # ffi.'s include of ffitarget.h - Armando Di Cianno <fafhrd@gentoo.org>
217 if [[ -d ${D}${LIBPATH}/include/libffi ]] ; then
218 mv -i "${D}"${LIBPATH}/include/libffi/* "${D}"${LIBPATH}/include || die
219 rm -r "${D}"${LIBPATH}/include/libffi || die
222 # Now do the fun stripping stuff
223 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}"
224 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
225 # gcc used to install helper binaries in lib/ but then moved to libexec/
226 [[ -d ${ED}/usr/libexec/gcc ]] && \
227 env RESTRICT="" CHOST=${CHOST} prepstrip "${ED}/usr/libexec/gcc/${CTARGET}/${GCC_VERS}"
229 # prune empty dirs left behind
230 find "${ED}" -type d | xargs rmdir >& /dev/null
233 pkg_postinst() {
234 # beware this also switches when it's on another branch version of GCC
235 gcc-config ${CTARGET}-${GCC_VERS}
238 pkg_postrm() {
239 # clean up the cruft left behind by cross-compilers
240 if is_crosscompile ; then
241 if [[ -z $(ls "${EROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
242 rm -f "${EROOT}"/etc/env.d/gcc/config-${CTARGET}
243 rm -f "${EROOT}"/etc/env.d/??gcc-${CTARGET}
244 rm -f "${EROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}
246 return 0