x11-misc/alock: Take ownership of package
[gentoo.git] / eclass / gnatbuild.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4 #
5 # Authors: George Shapovalov <george@gentoo.org>
6 #          Steve Arnold <nerdboy@gentoo.org>
7 #
8 # Belongs to: ada herd <ada@gentoo.org>
9 #
10 # Notes:
11 #  HOMEPAGE and LICENSE are set in appropriate ebuild, as
12 #  gnat is developed by FSF and AdaCore "in parallel"
13 #
14 # The following vars can be set in ebuild before inheriting this eclass. They
15 # will be respected:
16 #  SLOT
17 #  BOOT_SLOT - where old bootstrap is used as it works fine
18
19 #WANT_AUTOMAKE="1.8"
20 #WANT_AUTOCONF="2.1"
21
22 inherit eutils versionator toolchain-funcs flag-o-matic multilib autotools \
23         libtool fixheadtails gnuconfig pax-utils
24
25 EXPORT_FUNCTIONS pkg_setup pkg_postinst pkg_postrm src_unpack src_compile src_install
26
27 IUSE="nls"
28 # multilib is supported via profiles now, multilib usevar is deprecated
29
30 DEPEND=">=app-eselect/eselect-gnat-1.3
31         sys-devel/bc
32 "
33
34 RDEPEND="app-eselect/eselect-gnat"
35
36 # Note!
37 # It may not be safe to source this at top level. Only source inside local
38 # functions!
39 GnatCommon="/usr/share/gnat/lib/gnat-common.bash"
40
41 #---->> globals and SLOT <<----
42
43 # just a check, this location seems to vary too much, easier to track it in
44 # ebuild
45 #[ -z "${GNATSOURCE}" ] && die "please set GNATSOURCE in ebuild! (before inherit)"
46
47 # versioning
48 # because of gnatpro/gnatgpl we need to track both gcc and gnat versions
49
50 # these simply default to $PV
51 GNATMAJOR=$(get_version_component_range 1)
52 GNATMINOR=$(get_version_component_range 2)
53 GNATBRANCH=$(get_version_component_range 1-2)
54 GNATRELEASE=$(get_version_component_range 1-3)
55 # this one is for the gnat-gpl which is versioned by gcc backend and ACT version
56 # number added on top
57 ACT_Ver=$(get_version_component_range 4)
58
59 # GCCVER and SLOT logic
60 #
61 # I better define vars for package names, as there was discussion on proper
62 # naming and it may change
63 PN_GnatGCC="gnat-gcc"
64 PN_GnatGpl="gnat-gpl"
65
66 # ATTN! GCCVER stands for the provided backend gcc, not the one on the system
67 # so tc-* functions are of no use here. The present versioning scheme makes
68 # GCCVER basically a part of PV, but *this may change*!!
69 #
70 # GCCVER can be set in the ebuild.
71 [[ -z ${GCCVER} ]] && GCCVER="${GNATRELEASE}"
72
73
74 # finally extract GCC version strings
75 GCCMAJOR=$(get_version_component_range 1 "${GCCVER}")
76 GCCMINOR=$(get_version_component_range 2 "${GCCVER}")
77 GCCBRANCH=$(get_version_component_range 1-2 "${GCCVER}")
78 GCCRELEASE=$(get_version_component_range 1-3 "${GCCVER}")
79
80 # SLOT logic, make it represent gcc backend, as this is what matters most
81 # There are some special cases, so we allow it to be defined in the ebuild
82 # ATTN!! If you set SLOT in the ebuild, don't forget to make sure that
83 # BOOT_SLOT is also set properly!
84 [[ -z ${SLOT} ]] && SLOT="${GCCBRANCH}"
85
86 # possible future crosscompilation support
87 export CTARGET=${CTARGET:-${CHOST}}
88
89 is_crosscompile() {
90         [[ ${CHOST} != ${CTARGET} ]]
91 }
92
93 # Bootstrap CTARGET and SLOT logic. For now BOOT_TARGET=CHOST is "guaranteed" by
94 # profiles, so mostly watch out for the right SLOT used in the bootstrap.
95 # As above, with SLOT, it may need to be defined in the ebuild
96 BOOT_TARGET=${CTARGET}
97 [[ -z ${BOOT_SLOT} ]] && BOOT_SLOT=${SLOT}
98
99 # set our install locations
100 PREFIX=${GNATBUILD_PREFIX:-/usr} # not sure we need this hook, but may be..
101 LIBPATH=${PREFIX}/$(get_libdir)/${PN}/${CTARGET}/${SLOT}
102 LIBEXECPATH=${PREFIX}/libexec/${PN}/${CTARGET}/${SLOT}
103 INCLUDEPATH=${LIBPATH}/include
104 BINPATH=${PREFIX}/${CTARGET}/${PN}-bin/${SLOT}
105 DATAPATH=${PREFIX}/share/${PN}-data/${CTARGET}/${SLOT}
106 # ATTN! the one below should match the path defined in eselect-gnat module
107 CONFIG_PATH="/usr/share/gnat/eselect"
108 gnat_profile="${CTARGET}-${PN}-${SLOT}"
109 gnat_config_file="${CONFIG_PATH}/${gnat_profile}"
110
111
112 # ebuild globals
113 if [[ ${PN} == "${PN_GnatPro}" ]] && [[ ${GNATMAJOR} == "3" ]]; then
114                 DEPEND="x86? ( >=app-shells/tcsh-6.0 )"
115 fi
116 S="${WORKDIR}/gcc-${GCCVER}"
117
118 # bootstrap globals, common to src_unpack and src_compile
119 GNATBOOT="${WORKDIR}/usr"
120 GNATBUILD="${WORKDIR}/build"
121
122 # necessary for detecting lib locations and creating env.d entry
123 #XGCC="${GNATBUILD}/gcc/xgcc -B${GNATBUILD}/gcc"
124
125 #----<< globals and SLOT >>----
126
127 # set SRC_URI's in ebuilds for now
128
129 #----<< support checks >>----
130 # skipping this section - do not care about hardened/multilib for now
131
132 #---->> specs + env.d logic <<----
133 # TODO!!!
134 # set MANPATH, etc..
135 #----<< specs + env.d logic >>----
136
137
138 #---->> some helper functions <<----
139 is_multilib() {
140         [[ ${GCCMAJOR} < 3 ]] && return 1
141         case ${CTARGET} in
142                 mips64*|powerpc64*|s390x*|sparc64*|x86_64*)
143                         has_multilib_profile || use multilib ;;
144                 *)  false ;;
145         esac
146 }
147
148 # adapted from toolchain,
149 # left only basic multilib functionality and cut off mips stuff
150
151 create_specs_file() {
152         einfo "Creating a vanilla gcc specs file"
153         "${WORKDIR}"/build/gcc/xgcc -dumpspecs > "${WORKDIR}"/build/vanilla.specs
154 }
155
156
157 # eselect stuff taken straight from toolchain.eclass and greatly simplified
158 add_profile_eselect_conf() {
159         local gnat_config_file=$1
160         local abi=$2
161         local var
162
163         echo >> "${D}/${gnat_config_file}"
164         if ! is_multilib ; then
165                 echo "  ctarget=${CTARGET}" >> "${D}/${gnat_config_file}"
166         else
167                 echo "[${abi}]" >> "${D}/${gnat_config_file}"
168                 var="CTARGET_${abi}"
169                 if [[ -n ${!var} ]] ; then
170                         echo "  ctarget=${!var}" >> "${D}/${gnat_config_file}"
171                 else
172                         var="CHOST_${abi}"
173                         if [[ -n ${!var} ]] ; then
174                                 echo "  ctarget=${!var}" >> "${D}/${gnat_config_file}"
175                         else
176                                 echo "  ctarget=${CTARGET}" >> "${D}/${gnat_config_file}"
177                         fi
178                 fi
179         fi
180
181         var="CFLAGS_${abi}"
182         if [[ -n ${!var} ]] ; then
183                 echo "  cflags=${!var}" >> "${D}/${gnat_config_file}"
184         fi
185 }
186
187
188 create_eselect_conf() {
189         local abi
190
191         dodir ${CONFIG_PATH}
192
193         echo "[global]" > "${D}/${gnat_config_file}"
194         echo "  version=${CTARGET}-${SLOT}" >> "${D}/${gnat_config_file}"
195         echo "  binpath=${BINPATH}" >> "${D}/${gnat_config_file}"
196         echo "  libexecpath=${LIBEXECPATH}" >> "${D}/${gnat_config_file}"
197         echo "  ldpath=${LIBPATH}" >> "${D}/${gnat_config_file}"
198         echo "  manpath=${DATAPATH}/man" >> "${D}/${gnat_config_file}"
199         echo "  infopath=${DATAPATH}/info" >> "${D}/${gnat_config_file}"
200         echo "  bin_prefix=${CTARGET}" >> "${D}/${gnat_config_file}"
201
202         for abi in $(get_all_abis) ; do
203                 add_profile_eselect_conf "${D}/${gnat_config_file}" "${abi}"
204         done
205 }
206
207
208
209 should_we_eselect_gnat() {
210         # we only want to switch compilers if installing to / or /tmp/stage1root
211         [[ ${ROOT} == "/" ]] || return 1
212
213         # if the current config is invalid, we definitely want a new one
214         # Note: due to bash quirkiness, the following must not be 1 line
215         local curr_config
216         curr_config=$(eselect gnat show | grep ${CTARGET} | awk '{ print $1 }') || return 0
217         [[ -z ${curr_config} ]] && return 0
218
219         # The logic is basically "try to keep the same profile if possible"
220
221         if [[ ${curr_config} == ${CTARGET}-${PN}-${SLOT} ]] ; then
222                 return 0
223         else
224                 elog "The current gcc config appears valid, so it will not be"
225                 elog "automatically switched for you.  If you would like to"
226                 elog "switch to the newly installed gcc version, do the"
227                 elog "following:"
228                 echo
229                 elog "eselect gnat set <profile>"
230                 echo
231                 ebeep
232                 return 1
233         fi
234 }
235
236 # active compiler selection, called from pkg_postinst
237 do_gnat_config() {
238         eselect gnat set ${CTARGET}-${PN}-${SLOT} &> /dev/null
239
240         elog "The following gnat profile has been activated:"
241         elog "${CTARGET}-${PN}-${SLOT}"
242         elog ""
243         elog "The compiler has been installed as gnatgcc, and the coverage testing"
244         elog "tool as gnatgcov."
245         elog ""
246         elog "Ada handling in Gentoo allows you to have multiple gnat variants"
247         elog "installed in parallel and automatically manage Ada libs."
248         elog "Please take a look at the Ada project page for some documentation:"
249         elog "https://www.gentoo.org/proj/en/prog_lang/ada/index.xml"
250 }
251
252
253 # Taken straight from the toolchain.eclass. Only removed the "obsolete hunk"
254 #
255 # The purpose of this DISGUSTING gcc multilib hack is to allow 64bit libs
256 # to live in lib instead of lib64 where they belong, with 32bit libraries
257 # in lib32. This hack has been around since the beginning of the amd64 port,
258 # and we're only now starting to fix everything that's broken. Eventually
259 # this should go away.
260 #
261 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
262 #
263 disgusting_gcc_multilib_HACK() {
264         local config
265         local libdirs
266         if has_multilib_profile ; then
267                 case $(tc-arch) in
268                         amd64)
269                                 config="i386/t-linux64"
270                                 libdirs="../$(get_abi_LIBDIR amd64) ../$(get_abi_LIBDIR x86)" \
271                         ;;
272                         ppc64)
273                                 config="rs6000/t-linux64"
274                                 libdirs="../$(get_abi_LIBDIR ppc64) ../$(get_abi_LIBDIR ppc)" \
275                         ;;
276                 esac
277         else
278                 die "Your profile is no longer supported by portage."
279         fi
280
281         einfo "updating multilib directories to be: ${libdirs}"
282         sed -i -e "s:^MULTILIB_OSDIRNAMES.*:MULTILIB_OSDIRNAMES = ${libdirs}:" "${S}"/gcc/config/${config}
283 }
284
285
286 #---->> pkg_* <<----
287 gnatbuild_pkg_setup() {
288         debug-print-function ${FUNCNAME} $@
289
290         # Setup variables which would normally be in the profile
291         if is_crosscompile ; then
292                 multilib_env ${CTARGET}
293         fi
294
295         # we dont want to use the installed compiler's specs to build gnat!
296         unset GCC_SPECS
297 }
298
299 gnatbuild_pkg_postinst() {
300         if should_we_eselect_gnat; then
301                 do_gnat_config
302         else
303                 eselect gnat update
304         fi
305
306         # if primary compiler list is empty, add this profile to the list, so
307         # that users are not left without active compilers (making sure that
308         # libs are getting built for at least one)
309         elog
310         . ${GnatCommon} || die "failed to source common code"
311         if [[ ! -f ${PRIMELIST} ]] || [[ ! -s ${PRIMELIST} ]]; then
312                 mkdir -p ${SETTINGSDIR}
313                 echo "${gnat_profile}" > ${PRIMELIST}
314                 elog "The list of primary compilers was empty and got assigned ${gnat_profile}."
315         fi
316         elog "Please edit ${PRIMELIST} and list there gnat profiles intended"
317         elog "for common use, one per line."
318 }
319
320
321 gnatbuild_pkg_postrm() {
322         # "eselect gnat update" now removes the env.d file if the corresponding
323         # gnat profile was unmerged
324         eselect gnat update
325         elog "If you just unmerged the last gnat in this SLOT, your active gnat"
326         elog "profile got unset. Please check what eselect gnat show tells you"
327         elog "and set the desired profile"
328 }
329 #---->> pkg_* <<----
330
331 #---->> src_* <<----
332
333 # common unpack stuff
334 gnatbuild_src_unpack() {
335         debug-print-function ${FUNCNAME} $@
336         [ -z "$1" ] &&  gnatbuild_src_unpack all
337
338         while [ "$1" ]; do
339         case $1 in
340                 base_unpack)
341                         unpack ${A}
342                         pax-mark E $(find ${GNATBOOT} -name gnat1)
343
344                         cd "${S}"
345                         # patching gcc sources, following the toolchain
346                         # first, the common patches
347                         if [[ -d "${FILESDIR}"/patches ]] && [[ ! -z $(ls "${FILESDIR}"/patches/*.patch 2>/dev/null) ]] ; then
348                                 EPATCH_MULTI_MSG="Applying common Gentoo patches ..." \
349                                 epatch "${FILESDIR}"/patches/*.patch
350                         fi
351                         #
352                         # then per SLOT
353                         if [[ -d "${FILESDIR}"/patches/${SLOT} ]] && [[ ! -z $(ls "${FILESDIR}"/patches/${SLOT}/*.patch 2>/dev/null) ]] ; then
354                                 EPATCH_MULTI_MSG="Applying SLOT-specific Gentoo patches ..." \
355                                 epatch "${FILESDIR}"/patches/${SLOT}/*.patch
356                         fi
357                         # Replacing obsolete head/tail with POSIX compliant ones
358                         ht_fix_file */configure
359
360 #                       if ! is_crosscompile && is_multilib && \
361 #                               [[ ( $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ) && -z ${SKIP_MULTILIB_HACK} ]] ; then
362 #                                       disgusting_gcc_multilib_HACK || die "multilib hack failed"
363 #                       fi
364
365                         # Fixup libtool to correctly generate .la files with portage
366                         cd "${S}"
367                         elibtoolize --portage --shallow --no-uclibc
368
369                         gnuconfig_update
370                         # update configure files
371                         einfo "Fixing misc issues in configure files"
372                         for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
373                                 ebegin "  Updating ${f}"
374                                 patch "${f}" "${FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
375                                         || eerror "Please file a bug about this"
376                                 eend $?
377                         done
378
379 #                       this is only needed for gnat-gpl-4.1 and breaks for gnat-gcc, so
380 #                       this block was moved to corresponding ebuild
381 #                       pushd "${S}"/gnattools &> /dev/null
382 #                               eautoconf
383 #                       popd &> /dev/null
384                 ;;
385
386                 common_prep)
387                         # Prepare the gcc source directory
388                         cd "${S}/gcc"
389                         touch cstamp-h.in
390                         touch ada/[es]info.h
391                         touch ada/nmake.ad[bs]
392                         # set the compiler name to gnatgcc
393                         for i in `find ada/ -name '*.ad[sb]'`; do \
394                                 sed -i -e "s/\"gcc\"/\"gnatgcc\"/g" ${i}; \
395                         done
396                         # add -fPIC flag to shared libs for 3.4* backend
397                         if [ "3.4" == "${GCCBRANCH}" ] ; then
398                                 cd ada
399                                 epatch "${FILESDIR}"/gnat-Make-lang.in.patch
400                         fi
401
402                         # gcc 4.3 sources seem to have a common omission of $(DESTDIR),
403                         # that leads to make install trying to rm -f file on live system.
404                         # As we do not need this rm, we simply remove the whole line
405                         if [ "4.3" == "${GCCBRANCH}" ] ; then
406                                 sed -i -e "/\$(RM) \$(bindir)/d" "${S}"/gcc/ada/Make-lang.in
407                         fi
408
409                         mkdir -p "${GNATBUILD}"
410                 ;;
411
412                 all)
413                         gnatbuild_src_unpack base_unpack common_prep
414                 ;;
415         esac
416         shift
417         done
418 }
419
420 # it would be nice to split configure and make steps
421 # but both need to operate inside specially tuned evironment
422 # so just do sections for now (as in eclass section of handbook)
423 # sections are: configure, make-tools, bootstrap,
424 #  gnatlib_and_tools, gnatlib-shared
425 gnatbuild_src_compile() {
426         debug-print-function ${FUNCNAME} $@
427         if [[ -z "$1" ]]; then
428                 gnatbuild_src_compile all
429                 return $?
430         fi
431
432         if [[ "all" == "$1" ]]
433         then # specialcasing "all" to avoid scanning sources unnecessarily
434                 gnatbuild_src_compile configure make-tools \
435                         bootstrap gnatlib_and_tools gnatlib-shared
436
437         else
438                 # Set some paths to our bootstrap compiler.
439                 export PATH="${GNATBOOT}/bin:${PATH}"
440                 # !ATTN! the bootstrap compilers have a very simplystic structure,
441                 # so many paths are not identical to the installed ones.
442                 # Plus it was simplified even more in new releases.
443                 if [[ ${BOOT_SLOT} > 4.1 ]] ; then
444                         GNATLIB="${GNATBOOT}/lib"
445                 else
446                         GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_SLOT}"
447                 fi
448
449                 export CC="${GNATBOOT}/bin/gnatgcc"
450                 # CPATH is supposed to be applied for any language, thus
451                 # superceding either of C/CPLUS/OBJC_INCLUDE_PATHs
452                 export CPATH="${GNATLIB}/include"
453                 #export INCLUDE_DIR="${GNATLIB}/include"
454                 #export C_INCLUDE_PATH="${GNATLIB}/include"
455                 #export CPLUS_INCLUDE_PATH="${GNATLIB}/include"
456                 export LIB_DIR="${GNATLIB}"
457                 export LDFLAGS="-L${GNATLIB}"
458
459                 # additional vars from gnuada and elsewhere
460                 #export LD_RUN_PATH="${LIBPATH}"
461                 export LIBRARY_PATH="${GNATLIB}"
462                 #export LD_LIBRARY_PATH="${GNATLIB}"
463 #               export COMPILER_PATH="${GNATBOOT}/bin/"
464
465                 export ADA_OBJECTS_PATH="${GNATLIB}/adalib"
466                 export ADA_INCLUDE_PATH="${GNATLIB}/adainclude"
467
468 #               einfo "CC=${CC},
469 #                       ADA_INCLUDE_PATH=${ADA_INCLUDE_PATH},
470 #                       LDFLAGS=${LDFLAGS},
471 #                       PATH=${PATH}"
472
473                 while [ "$1" ]; do
474                 case $1 in
475                         configure)
476                                 debug-print-section configure
477                                 # Configure gcc
478                                 local confgcc
479
480                                 # some cross-compile logic from toolchain
481                                 confgcc="${confgcc} --host=${CHOST}"
482                                 if is_crosscompile || tc-is-cross-compiler ; then
483                                         confgcc="${confgcc} --target=${CTARGET}"
484                                 fi
485                                 [[ -n ${CBUILD} ]] && confgcc="${confgcc} --build=${CBUILD}"
486
487                                 # Native Language Support
488                                 if use nls ; then
489                                         confgcc="${confgcc} --enable-nls --without-included-gettext"
490                                 else
491                                         confgcc="${confgcc} --disable-nls"
492                                 fi
493
494                                 if version_is_at_least 4.6 ; then
495                                         confgcc+=( $(use_enable lto) )
496                                 else
497                                         confgcc+=( --disable-lto )
498                                 fi
499
500                                 # reasonably sane globals (from toolchain)
501                                 # also disable mudflap and ssp
502                                 confgcc="${confgcc} \
503                                         --with-system-zlib \
504                                         --disable-checking \
505                                         --disable-werror \
506                                         --disable-libgomp \
507                                         --disable-libmudflap \
508                                         --disable-libssp \
509                                         --disable-libunwind-exceptions"
510
511                                 if in_iuse openmp ; then
512                                         # Make sure target has pthreads support. #326757 #335883
513                                         # There shouldn't be a chicken&egg problem here as openmp won't
514                                         # build without a C library, and you can't build that w/out
515                                         # already having a compiler ...
516                                         if ! is_crosscompile || \
517                                                 $(tc-getCPP ${CTARGET}) -E - <<<"#include <pthread.h>" >& /dev/null
518                                         then
519                                                 case $(tc-arch) in
520                                                         arm)
521                                                                 confgcc+=( --disable-libgomp )
522                                                                 ;;
523                                                         *)
524                                                                 confgcc+=( $(use_enable openmp libgomp) )
525                                                                 ;;
526                                                 esac
527                                         else
528                                                 # Force disable as the configure script can be dumb #359855
529                                                 confgcc+=( --disable-libgomp )
530                                         fi
531                                 else
532                                         # For gcc variants where we don't want openmp (e.g. kgcc)
533                                         confgcc+=( --disable-libgomp )
534                                 fi
535
536                                 # ACT's gnat-gpl does not like libada for whatever reason..
537                                 if version_is_at_least 4.2 ; then
538                                         confgcc="${confgcc} --enable-libada"
539 #                               else
540 #                                       einfo "ACT's gnat-gpl does not like libada, disabling"
541 #                                       confgcc="${confgcc} --disable-libada"
542                                 fi
543
544                                 # set some specifics available in later versions
545                                 if version_is_at_least 4.3 ; then
546                                         einfo "setting gnat thread model"
547                                         confgcc="${confgcc} --enable-threads=gnat"
548                                         confgcc="${confgcc} --enable-shared=boehm-gc,ada,libada"
549                                 else
550                                         confgcc="${confgcc} --enable-threads=posix"
551                                         confgcc="${confgcc} --enable-shared"
552                                 fi
553
554                                 # multilib support
555                                 if is_multilib ; then
556                                         confgcc="${confgcc} --enable-multilib"
557                                 else
558                                         confgcc="${confgcc} --disable-multilib"
559                                 fi
560
561                                 # __cxa_atexit is "essential for fully standards-compliant handling of
562                                 # destructors", but apparently requires glibc.
563                                 if [[ ${CTARGET} == *-gnu* ]] ; then
564                                         confgcc="${confgcc} --enable-__cxa_atexit"
565                                         confgcc="${confgcc} --enable-clocale=gnu"
566                                 fi
567
568                                 einfo "confgcc=${confgcc}"
569
570                                 # need to strip graphite flags or we'll get the
571                                 # dreaded C compiler cannot create executables...
572                                 # error.
573                                 strip-flags -floop-interchange -floop-strip-mine -floop-block
574
575                                 cd "${GNATBUILD}"
576                                 CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" "${S}"/configure \
577                                         --prefix=${PREFIX} \
578                                         --bindir=${BINPATH} \
579                                         --includedir=${INCLUDEPATH} \
580                                         --libdir="${LIBPATH}" \
581                                         --libexecdir="${LIBEXECPATH}" \
582                                         --datadir=${DATAPATH} \
583                                         --mandir=${DATAPATH}/man \
584                                         --infodir=${DATAPATH}/info \
585                                         --program-prefix=gnat \
586                                         --enable-languages="c,ada" \
587                                         --with-gcc \
588                                         ${confgcc} || die "configure failed"
589                         ;;
590
591                         make-tools)
592                                 debug-print-section make-tools
593                                 # Compile helper tools
594                                 cd "${GNATBOOT}"
595                                 cp "${S}"/gcc/ada/xtreeprs.adb .
596                                 cp "${S}"/gcc/ada/xsinfo.adb   .
597                                 cp "${S}"/gcc/ada/xeinfo.adb   .
598                                 cp "${S}"/gcc/ada/xnmake.adb   .
599                                 cp "${S}"/gcc/ada/xutil.ad{s,b}   .
600                                 if (( ${GNATMINOR} > 5 )) ; then
601                                         cp "${S}"/gcc/ada/einfo.ad{s,b}  .
602                                         cp "${S}"/gcc/ada/csinfo.adb  .
603                                         cp "${S}"/gcc/ada/ceinfo.adb  .
604                                 fi
605                                 gnatmake xtreeprs && \
606                                 gnatmake xsinfo   && \
607                                 gnatmake xeinfo   && \
608                                 gnatmake xnmake   || die "building helper tools"
609                         ;;
610
611                         bootstrap)
612                                 debug-print-section bootstrap
613                                 # and, finally, the build itself
614                                 cd "${GNATBUILD}"
615                                 emake bootstrap || die "bootstrap failed"
616                         ;;
617
618                         gnatlib_and_tools)
619                                 debug-print-section gnatlib_and_tools
620                                 einfo "building gnatlib_and_tools"
621                                 cd "${GNATBUILD}"
622                                 emake -j1 -C gcc gnatlib_and_tools || \
623                                         die "gnatlib_and_tools failed"
624                         ;;
625
626                         gnatlib-shared)
627                                 debug-print-section gnatlib-shared
628                                 einfo "building shared lib"
629                                 cd "${GNATBUILD}"
630                                 rm -f gcc/ada/rts/*.{o,ali} || die
631                                 #otherwise make tries to reuse already compiled (without -fPIC) objs..
632                                 emake -j1 -C gcc gnatlib-shared LIBRARY_VERSION="${GCCBRANCH}" || \
633                                         die "gnatlib-shared failed"
634                         ;;
635
636                 esac
637                 shift
638                 done # while
639         fi   # "all" == "$1"
640 }
641 # -- end gnatbuild_src_compile
642
643
644 gnatbuild_src_install() {
645         debug-print-function ${FUNCNAME} $@
646
647         if [[ -z "$1" ]] ; then
648                 gnatbuild_src_install all
649                 return $?
650         fi
651
652         while [ "$1" ]; do
653         case $1 in
654         install) # runs provided make install
655                 debug-print-section install
656
657                 # Looks like we need an access to the bootstrap compiler here too
658                 # as gnat apparently wants to compile something during the installation
659                 # The spotted obuser was xgnatugn, used to process gnat_ugn_urw.texi,
660                 # during preparison of the docs.
661                 export PATH="${GNATBOOT}/bin:${PATH}"
662                 if [[ ${BOOT_SLOT} > 4.1 ]] ; then
663                         GNATLIB="${GNATBOOT}/lib"
664                 else
665                         GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_SLOT}"
666                 fi
667
668                 export CC="${GNATBOOT}/bin/gnatgcc"
669                 export INCLUDE_DIR="${GNATLIB}/include"
670                 export C_INCLUDE_PATH="${GNATLIB}/include"
671                 export CPLUS_INCLUDE_PATH="${GNATLIB}/include"
672                 export LIB_DIR="${GNATLIB}"
673                 export LDFLAGS="-L${GNATLIB}"
674                 export ADA_OBJECTS_PATH="${GNATLIB}/adalib"
675                 export ADA_INCLUDE_PATH="${GNATLIB}/adainclude"
676
677                 # Do not allow symlinks in /usr/lib/gcc/${CHOST}/${MY_PV}/include as
678                 # this can break the build.
679                 for x in "${GNATBUILD}"/gcc/include/* ; do
680                         if [ -L ${x} ] ; then
681                                 rm -f ${x}
682                         fi
683                 done
684                 # Remove generated headers, as they can cause things to break
685                 # (ncurses, openssl, etc). (from toolchain.eclass)
686                 for x in $(find "${WORKDIR}"/build/gcc/include/ -name '*.h') ; do
687                         grep -q 'It has been auto-edited by fixincludes from' "${x}" \
688                                 && rm -f "${x}"
689                 done
690
691
692                 cd "${GNATBUILD}"
693                 make DESTDIR="${D}" install || die
694
695                 if use doc ; then
696                         if (( $(bc <<< "${GNATBRANCH} > 4.3") )) ; then
697                                 #make a convenience info link
698                                 elog "Yay!  Math is good."
699                                 dosym gnat_ugn.info ${DATAPATH}/info/gnat.info
700                         fi
701                 fi
702                 ;;
703
704         move_libs)
705                 debug-print-section move_libs
706
707                 # first we need to remove some stuff to make moving easier
708                 rm -rf "${D}${LIBPATH}"/{32,include,libiberty.a}
709                 # gcc insists on installing libs in its own place
710                 mv "${D}${LIBPATH}/gcc/${CTARGET}/${GCCRELEASE}"/* "${D}${LIBPATH}"
711                 mv "${D}${LIBEXECPATH}/gcc/${CTARGET}/${GCCRELEASE}"/* "${D}${LIBEXECPATH}"
712
713                 # libgcc_s  and, with gcc>=4.0, other libs get installed in multilib specific locations by gcc
714                 # we pull everything together to simplify working environment
715                 if has_multilib_profile ; then
716                         case $(tc-arch) in
717                                 amd64)
718                                         mv "${D}${LIBPATH}"/../$(get_abi_LIBDIR amd64)/* "${D}${LIBPATH}"
719                                         mv "${D}${LIBPATH}"/../$(get_abi_LIBDIR x86)/* "${D}${LIBPATH}"/32
720                                 ;;
721                                 ppc64)
722                                         # not supported yet, will have to be adjusted when we
723                                         # actually build gnat for that arch
724                                 ;;
725                         esac
726                 fi
727
728                 # force gnatgcc to use its own specs - versions prior to 3.4.6 read specs
729                 # from system gcc location. Do the simple wrapper trick for now
730                 # !ATTN! change this if eselect-gnat starts to follow eselect-compiler
731                 if [[ ${GCCVER} < 3.4.6 ]] ; then
732                         # gcc 4.1 uses builtin specs. What about 4.0?
733                         cd "${D}${BINPATH}"
734                         mv gnatgcc gnatgcc_2wrap
735                         cat > gnatgcc << EOF
736 #! /bin/bash
737 # wrapper to cause gnatgcc read appropriate specs and search for the right .h
738 # files (in case no matching gcc is installed)
739 BINDIR=\$(dirname \$0)
740 # The paths in the next line have to be absolute, as gnatgcc may be called from
741 # any location
742 \${BINDIR}/gnatgcc_2wrap -specs="${LIBPATH}/specs" -I"${LIBPATH}/include" \$@
743 EOF
744                         chmod a+x gnatgcc
745                 fi
746
747                 # earlier gnat's generate some Makefile's at generic location, need to
748                 # move to avoid collisions
749                 [ -f "${D}${PREFIX}"/share/gnat/Makefile.generic ] &&
750                         mv "${D}${PREFIX}"/share/gnat/Makefile.* "${D}${DATAPATH}"
751
752                 # use gid of 0 because some stupid ports don't have
753                 # the group 'root' set to gid 0 (toolchain.eclass)
754                 chown -R root:0 "${D}${LIBPATH}"
755                 ;;
756
757         cleanup)
758                 debug-print-section cleanup
759
760                 rm -rf "${D}${LIBPATH}"/{gcc,install-tools,../lib{32,64}}
761                 rm -rf "${D}${LIBEXECPATH}"/{gcc,install-tools}
762
763                 # this one is installed by gcc and is a duplicate even here anyway
764                 rm -f "${D}${BINPATH}/${CTARGET}-gcc-${GCCRELEASE}"
765
766                 # remove duplicate docs
767                 rm -f  "${D}${DATAPATH}"/info/{dir,gcc,cpp}*
768                 rm -rf "${D}${DATAPATH}"/man/man7/
769
770                 # fix .la path for lto plugin
771                 if use lto ; then
772                         sed -i -e \
773                                 "/libdir=/c\libdir='${LIBEXECPATH}'" \
774                                 "${D}${LIBEXECPATH}"/liblto_plugin.la \
775                                 || die "sed update of .la file failed!"
776                 fi
777
778                 # add config directory (bug 440660)
779                 keepdir /etc/ada
780                 ;;
781
782         prep_env)
783                 # instead of putting junk under /etc/env.d/gnat we recreate env files as
784                 # needed with eselect
785                 create_eselect_conf
786                 ;;
787
788         all)
789                 gnatbuild_src_install install move_libs cleanup prep_env
790                 ;;
791         esac
792         shift
793         done # while
794 }
795 # -- end gnatbuild_src_install