x11-libs/libast: import
[portage-prefix-bleeding-edge-ebuilds.git] / sys-devel / gcc-apple / gcc-apple-4.0.1_p5488.ebuild
blobe0aaf65f7b427e7297b6868875aee7775bf350c3
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, iPhone 2.1 + SDK"
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 DEPEND="${RDEPEND}
32 >=sys-apps/texinfo-4.2-r4
33 >=sys-devel/bison-1.875
34 ${CATEGORY}/binutils-apple"
36 S=${WORKDIR}/gcc-${APPLE_VERS}
38 # TPREFIX is the prefix of the CTARGET installation
39 export TPREFIX=${TPREFIX:-${EPREFIX}}
41 LIBPATH=${EPREFIX}/usr/lib/gcc/${CTARGET}/${GCC_VERS}
42 if is_crosscompile ; then
43 BINPATH=${EPREFIX}/usr/${CHOST}/${CTARGET}/gcc-bin/${GCC_VERS}
44 else
45 BINPATH=${EPREFIX}/usr/${CTARGET}/gcc-bin/${GCC_VERS}
47 STDCXX_INCDIR=${LIBPATH}/include/g++-v${GCC_VERS/\.*/}
49 src_unpack() {
50 unpack ${A}
51 cd "${S}"
52 # we use our libtool
53 sed -i -e "s:/usr/bin/libtool:${EPREFIX}/usr/bin/${CTARGET}-libtool:" \
54 gcc/config/darwin.h || die "sed gcc/config/darwin.h failed"
55 # add prefixed Frameworks to default search paths (may want to change this
56 # in a cross-compile)
57 sed -i -e "/\"\/System\/Library\/Frameworks\"\,/i\ \ \"${EPREFIX}/Frameworks\"\, " \
58 gcc/config/darwin-c.c || die "sed gcc/config/darwin-c.c failed"
60 # Workaround deprecated "+Nc" syntax for GNU tail(1)
61 sed -i -e "s:tail +16c:tail -c +16:g" \
62 gcc/Makefile.in || die "sed gcc/Makefile.in failed."
64 epatch "${FILESDIR}"/${PN}-4.0.1_p5465-default-altivec.patch
67 src_compile() {
68 local langs="c"
69 use nocxx || langs="${langs},c++"
70 use objc && langs="${langs},objc"
71 use objc++ && langs="${langs/,objc/},objc,obj-c++" # need objc with objc++
73 local myconf="${myconf} \
74 --prefix=${EPREFIX}/usr \
75 --bindir=${BINPATH} \
76 --includedir=${LIBPATH}/include \
77 --datadir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS} \
78 --mandir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS}/man \
79 --infodir=${EPREFIX}/usr/share/gcc-data/${CTARGET}/${GCC_VERS}/info \
80 --libdir=${LIBPATH} \
81 --with-gxx-include-dir=${STDCXX_INCDIR} \
82 --host=${CHOST}"
84 if is_crosscompile ; then
85 # Straight from the GCC install doc:
86 # "GCC has code to correctly determine the correct value for target
87 # for nearly all native systems. Therefore, we highly recommend you
88 # not provide a configure target when configuring a native compiler."
89 myconf="${myconf} --target=${CTARGET}"
91 # Tell compiler where to find what it needs
92 myconf="${myconf} --with-sysroot=${EPREFIX}/usr/${CTARGET}"
94 # Set this to something sane for both native and target
95 CFLAGS="-O2 -pipe"
97 local VAR="CFLAGS_"${CTARGET//-/_}
98 CXXFLAGS=${!VAR}
100 [[ -n ${CBUILD} ]] && myconf="${myconf} --build=${CBUILD}"
102 # Native Language Support
103 if use nls ; then
104 myconf="${myconf} --enable-nls --without-included-gettext"
105 else
106 myconf="${myconf} --disable-nls"
109 # reasonably sane globals (hopefully)
110 myconf="${myconf} \
111 --with-system-zlib \
112 --disable-checking \
113 --disable-werror"
115 # languages to build
116 myconf="${myconf} --enable-languages=${langs}"
118 # ???
119 myconf="${myconf} --enable-shared --enable-threads=posix"
121 # make clear we're in an offset
122 use prefix && myconf="${myconf} --with-local-prefix=${TPREFIX}/usr"
124 # we don't use a GNU linker, so tell GCC where to find the linker stuff we
125 # want it to use
126 myconf="${myconf} \
127 --with-as=${EPREFIX}/usr/bin/${CTARGET}-as \
128 --with-ld=${EPREFIX}/usr/bin/${CTARGET}-ld"
130 # make sure we never do multilib stuff, for that we need a different Prefix
131 myconf="${myconf} --disable-multilib"
133 # The produced libgcc_s.dylib is faulty if using a bit too much
134 # optimisation. Nail it down to something sane
135 CFLAGS="-O2 -pipe"
136 CXXFLAGS=${CFLAGS}
138 # http://gcc.gnu.org/ml/gcc-patches/2006-11/msg00765.html
139 # (won't hurt if already 64-bits, but is essential when coming from a
140 # multilib compiler -- the default)
141 [[ ${CTARGET} == powerpc64-* || ${CTARGET} == x86_64-* ]] && \
142 export CC="gcc -m64"
144 mkdir -p "${WORKDIR}"/build
145 cd "${WORKDIR}"/build
146 einfo "Configuring GCC with: ${myconf//--/\n\t--}"
147 "${S}"/configure ${myconf} || die "conf failed"
148 emake bootstrap || die "emake failed"
151 src_install() {
152 cd "${WORKDIR}"/build
153 # -jX doesn't work
154 emake -j1 DESTDIR="${D}" install || die
156 # Basic sanity check
157 if ! is_crosscompile ; then
158 local EXEEXT
159 eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log)
160 [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${ED}"
163 # create gcc-config entry
164 dodir /etc/env.d/gcc
165 local gcc_envd_base="/etc/env.d/gcc/${CHOST}-${GCC_VERS}"
167 gcc_envd_file="${ED}${gcc_envd_base}"
169 # phase PATH/ROOTPATH out ...
170 echo "PATH=\"${BINPATH}\"" > ${gcc_envd_file}
171 echo "ROOTPATH=\"${BINPATH}\"" >> ${gcc_envd_file}
172 echo "GCC_PATH=\"${BINPATH}\"" >> ${gcc_envd_file}
174 # we don't do multilib
175 LDPATH="${LIBPATH}"
176 echo "LDPATH=\"${LDPATH}\"" >> ${gcc_envd_file}
177 echo "MANPATH=\"${EPREFIX}/usr/share/gcc-data/${CHOST}/${GCC_VERS}/man\"" >> ${gcc_envd_file}
178 echo "INFOPATH=\"${EPREFIX}/usr/share/gcc-data/${CHOST}/${GCC_VERS}/info\"" >> ${gcc_envd_file}
179 echo "STDCXX_INCDIR=\"g++-v${GCC_VERS/\.*/}\"" >> ${gcc_envd_file}
180 is_crosscompile && echo "CTARGET=${CTARGET}" >> ${gcc_envd_file}
182 # Move <cxxabi.h> to compiler-specific directories
183 [[ -f ${D}${STDCXX_INCDIR}/cxxabi.h ]] && \
184 mv -f "${D}"${STDCXX_INCDIR}/cxxabi.h "${D}"${LIBPATH}/include/
186 # These should be symlinks
187 dodir /usr/bin
188 cd "${D}"${BINPATH}
189 for x in cpp gcc g++ c++ g77 gcj gcjh gfortran ; do
190 # For some reason, g77 gets made instead of ${CTARGET}-g77...
191 # this should take care of that
192 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
194 if [[ -f ${CTARGET}-${x} ]] && ! is_crosscompile ; then
195 ln -sf ${CTARGET}-${x} ${x}
197 # Create version-ed symlinks
198 dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} \
199 /usr/bin/${CTARGET}-${x}-${GCC_VERS}
200 dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} \
201 /usr/bin/${x}-${GCC_VERS}
204 if [[ -f ${CTARGET}-${x}-${GCC_VERS} ]] ; then
205 rm -f ${CTARGET}-${x}-${GCC_VERS}
206 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_VERS}
208 done
210 # I do not know if this will break gcj stuff, so I'll only do it for
211 # objc for now; basically "ffi.h" is the correct file to include,
212 # but it gets installed in .../GCCVER/include and yet it does
213 # "#include <ffitarget.h>" which (correctly, as it's an "extra" file)
214 # is installed in .../GCCVER/include/libffi; the following fixes
215 # ffi.'s include of ffitarget.h - Armando Di Cianno <fafhrd@gentoo.org>
216 if [[ -d ${D}${LIBPATH}/include/libffi ]] ; then
217 mv -i "${D}"${LIBPATH}/include/libffi/* "${D}"${LIBPATH}/include || die
218 rm -r "${D}"${LIBPATH}/include/libffi || die
221 # Now do the fun stripping stuff
222 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}"
223 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
224 # gcc used to install helper binaries in lib/ but then moved to libexec/
225 [[ -d ${ED}/usr/libexec/gcc ]] && \
226 env RESTRICT="" CHOST=${CHOST} prepstrip "${ED}/usr/libexec/gcc/${CTARGET}/${GCC_VERS}"
228 # prune empty dirs left behind
229 find "${ED}" -type d | xargs rmdir >& /dev/null
232 pkg_postinst() {
233 # beware this also switches when it's on another branch version of GCC
234 gcc-config ${CTARGET}-${GCC_VERS}
237 pkg_postrm() {
238 # clean up the cruft left behind by cross-compilers
239 if is_crosscompile ; then
240 if [[ -z $(ls "${EROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
241 rm -f "${EROOT}"/etc/env.d/gcc/config-${CTARGET}
242 rm -f "${EROOT}"/etc/env.d/??gcc-${CTARGET}
243 rm -f "${EROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}
245 return 0