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