1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # Author: George Shapovalov <george@gentoo.org>
5 # Author: Steve Arnold <nerdboy@gentoo.org>
6 # No maintainer <maintainer-needed@gentoo.org>
9 # HOMEPAGE and LICENSE are set in appropriate ebuild, as
10 # gnat is developed by FSF and AdaCore "in parallel"
12 # The following vars can be set in ebuild before inheriting this eclass. They
15 # BOOT_SLOT - where old bootstrap is used as it works fine for 4.4 - 4.6
20 inherit eutils fixheadtails flag-o-matic gnuconfig libtool multilib pax-utils toolchain-funcs versionator
22 FEATURES=${FEATURES/multilib-strict/}
24 EXPORTED_FUNCTIONS="pkg_setup pkg_postinst pkg_postrm src_unpack src_configure src_compile src_install"
26 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
28 IUSE="nls openmp hardened multilib"
29 # multilib is supported via profiles now, multilib usevar is deprecated
31 RDEPEND="virtual/libiconv
32 nls? ( virtual/libintl )"
35 >=app-eselect/eselect-gnat-1.5
37 >=sys-devel/binutils-2.23
39 >=sys-devel/bison-1.875
40 >=sys-devel/flex-2.5.4
41 nls? ( sys-devel/gettext )"
44 # It may not be safe to source this at top level. Only source inside local
46 GnatCommon="/usr/share/gnat/lib/gnat-common.bash"
48 #---->> globals and SLOT <<----
50 # just a check, this location seems to vary too much, easier to track it in
52 #[ -z "${GNATSOURCE}" ] && die "please set GNATSOURCE in ebuild! (before inherit)"
55 # because of gnatpro/gnatgpl we need to track both gcc and gnat versions
57 # these simply default to $PV
58 GNATMAJOR=$(get_version_component_range 1)
59 GNATMINOR=$(get_version_component_range 2)
60 GNATBRANCH=$(get_version_component_range 1-2)
61 GNATRELEASE=$(get_version_component_range 1-3)
62 # this one is for the gnat-gpl which is versioned by gcc backend and ACT version
64 ACT_Ver=$(get_version_component_range 4)
66 # GCCVER and SLOT logic
68 # I better define vars for package names, as there was discussion on proper
69 # naming and it may change
73 # ATTN! GCCVER stands for the provided backend gcc, not the one on the system
74 # so tc-* functions are of no use here. The present versioning scheme makes
75 # GCCVER basically a part of PV, but *this may change*!!
77 # GCCVER can be set in the ebuild.
78 [[ -z ${GCCVER} ]] && GCCVER="${GNATRELEASE}"
81 # finally extract GCC version strings
82 GCCMAJOR=$(get_version_component_range 1 "${GCCVER}")
83 GCCMINOR=$(get_version_component_range 2 "${GCCVER}")
84 GCCBRANCH=$(get_version_component_range 1-2 "${GCCVER}")
85 GCCRELEASE=$(get_version_component_range 1-3 "${GCCVER}")
87 # SLOT logic, make it represent gcc backend, as this is what matters most
88 # There are some special cases, so we allow it to be defined in the ebuild
89 # ATTN!! If you set SLOT in the ebuild, don't forget to make sure that
90 # BOOT_SLOT is also set properly!
91 [[ -z ${SLOT} ]] && SLOT="${GCCBRANCH}"
93 # possible future crosscompilation support
94 export CTARGET=${CTARGET:-${CHOST}}
97 [[ ${CHOST} != ${CTARGET} ]]
100 # Bootstrap CTARGET and SLOT logic. For now BOOT_TARGET=CHOST is "guaranteed" by
101 # profiles, so mostly watch out for the right SLOT used in the bootstrap.
102 # As above, with SLOT, it may need to be defined in the ebuild
103 BOOT_TARGET=${CTARGET}
104 [[ -z ${BOOT_SLOT} ]] && BOOT_SLOT=${SLOT}
106 # for newer bootstrap starting with 4.9 (still experimental)
107 BOOT_VER=${GCCRELEASE}
109 # set our install locations
110 PREFIX=${GNATBUILD_PREFIX:-/usr} # not sure we need this hook, but may be..
111 LIBPATH=${PREFIX}/$(get_libdir)/${PN}/${CTARGET}/${SLOT}
112 LIBEXECPATH=${PREFIX}/libexec/${PN}/${CTARGET}/${SLOT}
113 INCLUDEPATH=${LIBPATH}/include
114 BINPATH=${PREFIX}/${CTARGET}/${PN}-bin/${SLOT}
115 DATAPATH=${PREFIX}/share/${PN}-data/${CTARGET}/${SLOT}
116 # ATTN! the one below should match the path defined in eselect-gnat module
117 CONFIG_PATH="/usr/share/gnat/eselect"
118 gnat_profile="${CTARGET}-${PN}-${SLOT}"
119 gnat_config_file="${CONFIG_PATH}/${gnat_profile}"
122 if [[ ${PN} == "${PN_GnatPro}" ]] && [[ ${GNATMAJOR} == "3" ]]; then
123 DEPEND="x86? ( >=app-shells/tcsh-6.0 )"
125 S="${WORKDIR}/gcc-${GCCVER}"
127 # bootstrap globals, common to src_unpack and src_compile
128 GNATBOOT="${WORKDIR}/usr"
129 GNATBUILD="${WORKDIR}/build"
130 #GNATBUILD="${BUILD_DIR}"
132 # necessary for detecting lib locations and creating env.d entry
133 #XGCC="${GNATBUILD}/gcc/xgcc -B${GNATBUILD}/gcc"
135 #----<< globals and SLOT >>----
137 # set SRC_URI's in ebuilds for now
139 #----<< global toolchain vars >>----
141 : ${TARGET_ABI:=${ABI}}
142 : ${TARGET_MULTILIB_ABIS:=${MULTILIB_ABIS}}
143 : ${TARGET_DEFAULT_ABI:=${DEFAULT_ABI}}
146 #---->> specs + env.d logic <<----
149 #----<< specs + env.d logic >>----
152 #---->> some helper functions <<----
153 tc_version_is_at_least() {
154 version_is_at_least "$1" "${2:-${GCCBRANCH}}"
157 guess_patch_type_in_dir() {
158 [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
159 && EPATCH_SUFFIX="patch.bz2" \
160 || EPATCH_SUFFIX="patch"
163 # configure to build with the hardened GCC specs as the default
165 # we want to be able to control the pie patch logic via something other
167 sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
168 -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
169 -i "${S}"/gcc/Makefile.in
170 # Need to add HARD_CFLAGS to ALL_CXXFLAGS on >= 4.7
171 if tc_version_is_at_least 4.7 ; then
172 sed -e '/^ALL_CXXFLAGS/iHARD_CFLAGS = ' \
173 -e 's|^ALL_CXXFLAGS = |ALL_CXXFLAGS = $(HARD_CFLAGS) |' \
174 -i "${S}"/gcc/Makefile.in
177 # defaults to enable for new gnatbuild
178 if use hardened ; then
179 gcc_hard_flags=" -DEFAULT_PIE_SSP"
181 gcc_hard_flags+=" -DEFAULT_SSP"
185 -e "/^HARD_CFLAGS = /s|=|= ${gcc_hard_flags} |" \
186 "${S}"/gcc/Makefile.in || die
190 gcc-multilib-configure() {
191 if ! is_multilib ; then
192 confgcc="${confgcc} --disable-multilib"
193 # Fun times: if we are building for a target that has multiple
194 # possible ABI formats, and the user has told us to pick one
195 # that isn't the default, then not specifying it via the list
196 # below will break that on us.
198 confgcc="${confgcc} --enable-multilib"
201 # translate our notion of multilibs into gcc's
203 for abi in $(get_all_abis TARGET) ; do
204 local l=$(gcc-abi-map ${abi})
205 [[ -n ${l} ]] && list+=",${l}"
207 if [[ -n ${list} ]] ; then
210 tc_version_is_at_least 4.8 && confgcc="${confgcc} --with-multilib-list=${list:1}"
217 # Convert the ABI name we use in Gentoo to what gcc uses
220 mips*) map=("o32 32" "n32 n32" "n64 64") ;;
221 x86_64*) map=("amd64 m64" "x86 m32" "x32 mx32") ;;
225 for m in "${map[@]}" ; do
227 [[ $1 == ${l[0]} ]] && echo ${l[1]} && break
232 tc_version_is_at_least 3 || return 1
236 ## note: replaced with minspecs (sort of)
237 #create_specs_file() {
238 # einfo "Creating a vanilla gcc specs file"
239 # "${WORKDIR}"/build/gcc/xgcc -dumpspecs > "${WORKDIR}"/build/vanilla.specs
242 # eselect stuff taken straight from toolchain.eclass and greatly simplified
243 add_profile_eselect_conf() {
244 local gnat_config_file=$1
248 echo >> "${D}/${gnat_config_file}"
249 if ! is_multilib ; then
250 echo " ctarget=${CTARGET}" >> "${D}/${gnat_config_file}"
252 echo "[${abi}]" >> "${D}/${gnat_config_file}"
254 if [[ -n ${!var} ]] ; then
255 echo " ctarget=${!var}" >> "${D}/${gnat_config_file}"
258 if [[ -n ${!var} ]] ; then
259 echo " ctarget=${!var}" >> "${D}/${gnat_config_file}"
261 echo " ctarget=${CTARGET}" >> "${D}/${gnat_config_file}"
267 if [[ -n ${!var} ]] ; then
268 echo " cflags=${!var}" >> "${D}/${gnat_config_file}"
272 create_eselect_conf() {
277 echo "[global]" > "${D}/${gnat_config_file}"
278 echo " version=${CTARGET}-${SLOT}" >> "${D}/${gnat_config_file}"
279 echo " binpath=${BINPATH}" >> "${D}/${gnat_config_file}"
280 echo " libexecpath=${LIBEXECPATH}" >> "${D}/${gnat_config_file}"
281 echo " ldpath=${LIBPATH}" >> "${D}/${gnat_config_file}"
282 echo " manpath=${DATAPATH}/man" >> "${D}/${gnat_config_file}"
283 echo " infopath=${DATAPATH}/info" >> "${D}/${gnat_config_file}"
284 echo " bin_prefix=${CTARGET}" >> "${D}/${gnat_config_file}"
286 for abi in $(get_all_abis) ; do
287 add_profile_eselect_conf "${gnat_config_file}" "${abi}"
291 should_we_eselect_gnat() {
292 # we only want to switch compilers if installing to / or /tmp/stage1root
293 [[ ${ROOT} == "/" ]] || return 1
295 # if the current config is invalid, we definitely want a new one
296 # Note: due to bash quirkiness, the following must not be 1 line
298 curr_config=$(eselect --colour=no gnat show | grep ${CTARGET} | awk '{ print $1 }') || return 0
299 [[ -z ${curr_config} ]] && return 0
301 # The logic is basically "try to keep the same profile if possible"
303 if [[ ${curr_config} == ${CTARGET}-${PN}-${SLOT} ]] ; then
306 elog "The current gcc config appears valid, so it will not be"
307 elog "automatically switched for you. If you would like to"
308 elog "switch to the newly installed gcc version, do the"
311 elog "eselect gnat set <profile>"
318 # active compiler selection, called from pkg_postinst
320 eselect gnat set ${CTARGET}-${PN}-${SLOT} &> /dev/null
322 elog "The following gnat profile has been activated:"
323 elog "${CTARGET}-${PN}-${SLOT}"
325 elog "The compiler has been installed as gnatgcc, and the coverage testing"
326 elog "tool as gnatgcov."
328 elog "Ada handling in Gentoo allows you to have multiple gnat variants"
329 elog "installed in parallel and automatically manage Ada libs."
330 elog "Please take a look at the Ada project page for some documentation:"
331 elog "http://www.gentoo.org/proj/en/prog_lang/ada/index.xml"
335 # Taken straight from the toolchain.eclass. Only removed the "obsolete hunk"
337 # The purpose of this DISGUSTING gcc multilib hack is to allow 64bit libs
338 # to live in lib instead of lib64 where they belong, with 32bit libraries
339 # in lib32. This hack has been around since the beginning of the amd64 port,
340 # and we're only now starting to fix everything that's broken. Eventually
341 # this should go away.
343 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
345 disgusting_gcc_multilib_HACK() {
348 if has_multilib_profile ; then
351 config="i386/t-linux64"
352 libdirs="../$(get_abi_LIBDIR amd64) ../$(get_abi_LIBDIR x86)" \
355 config="rs6000/t-linux64"
356 libdirs="../$(get_abi_LIBDIR ppc64) ../$(get_abi_LIBDIR ppc)" \
360 die "Your profile is no longer supported by portage."
363 einfo "updating multilib directories to be: ${libdirs}"
364 sed -i -e "s:^MULTILIB_OSDIRNAMES.*:MULTILIB_OSDIRNAMES = ${libdirs}:" "${S}"/gcc/config/${config}
369 gnatbuild-r1_pkg_setup() {
370 debug-print-function ${FUNCNAME} $@
372 # Setup variables which would normally be in the profile
373 if is_crosscompile ; then
374 multilib_env ${CTARGET}
377 # we dont want to use the installed compiler's specs to build gnat!
379 unset LANGUAGES #265283
382 gnatbuild-r1_pkg_postinst() {
383 if should_we_eselect_gnat; then
389 # if primary compiler list is empty, add this profile to the list, so
390 # that users are not left without active compilers (making sure that
391 # libs are getting built for at least one)
393 . ${GnatCommon} || die "failed to source common code"
394 if [[ ! -f ${PRIMELIST} ]] || [[ ! -s ${PRIMELIST} ]]; then
395 echo "${gnat_profile}" > ${PRIMELIST}
396 elog "The list of primary compilers was empty and got assigned ${gnat_profile}."
398 elog "Please edit ${PRIMELIST} and list there gnat profiles intended"
399 elog "for common use."
403 gnatbuild-r1_pkg_postrm() {
404 # "eselect gnat update" now removes the env.d file if the corresponding
405 # gnat profile was unmerged
407 elog "If you just unmerged the last gnat in this SLOT, your active gnat"
408 elog "profile got unset. Please check what eselect gnat show tells you"
409 elog "and set the desired profile"
415 # common unpack stuff
416 gnatbuild-r1_src_unpack() {
417 debug-print-function ${FUNCNAME} $@
419 [ -z "$1" ] && gnatbuild-r1_src_unpack all
425 pax-mark E $(find ${GNATBOOT} -name gnat1)
428 # patching gcc sources, following the toolchain
429 # first, the common patches
430 guess_patch_type_in_dir "${WORKDIR}"/patch
431 EPATCH_MULTI_MSG="Applying common Gentoo patches ..." \
432 epatch "${WORKDIR}"/patch
433 guess_patch_type_in_dir "${WORKDIR}"/piepatch
434 EPATCH_MULTI_MSG="Applying Gentoo PIE patches ..." \
435 epatch "${WORKDIR}"/piepatch
437 if [[ -d "${FILESDIR}"/patches ]] && [[ ! -z $(ls "${FILESDIR}"/patches/*.patch 2>/dev/null) ]] ; then
438 EPATCH_MULTI_MSG="Applying local Gentoo patches ..." \
439 epatch "${FILESDIR}"/patches/*.patch
443 if [[ -d "${FILESDIR}"/patches/${SLOT} ]] && [[ ! -z $(ls "${FILESDIR}"/patches/${SLOT}/*.patch 2>/dev/null) ]] ; then
444 EPATCH_MULTI_MSG="Applying SLOT-specific Gentoo patches ..." \
445 epatch "${FILESDIR}"/patches/${SLOT}/*.patch
448 # add hardening as per toolchain eclass
451 # Replacing obsolete head/tail with POSIX compliant ones
452 ht_fix_file */configure
454 # if ! is_crosscompile && is_multilib && \
455 # [[ ( $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ) && -z ${SKIP_MULTILIB_HACK} ]] ; then
456 # disgusting_gcc_multilib_HACK || die "multilib hack failed"
459 # Fixup libtool to correctly generate .la files with portage
461 elibtoolize --portage --shallow --no-uclibc
464 # update configure files
465 einfo "Fixing misc issues in configure files"
466 for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
467 ebegin " Updating ${f}"
468 patch "${f}" "${FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
469 || eerror "Please file a bug about this"
473 # apply global slot/path patch
474 EPATCH_MULTI_MSG="Adjusting default paths for gnat-gcc ..." \
475 epatch "${FILESDIR}"/${PN}-4.9.3-make-default-paths-match-slot.patch
476 sed -i -e "s|SLOT_MARKER|${BOOT_SLOT}|" "${S}"/gcc/Makefile.in
478 [[ ${CHOST} == ${CTARGET} ]] && epatch "${FILESDIR}"/gcc-spec-env-r1.patch
480 # this is only needed for gnat-gpl-4.1 and breaks for gnat-gcc, so
481 # this block was moved to corresponding ebuild
482 # pushd "${S}"/gnattools &> /dev/null
488 # Prepare the gcc source directory
492 touch ada/nmake.ad[bs]
493 # set the compiler name to gnatgcc
494 for i in `find ada/ -name '*.ad[sb]'`; do \
495 sed -i -e "s/\"gcc\"/\"gnatgcc\"/g" ${i}; \
497 # add -fPIC flag to shared libs for 3.4* backend
498 if [ "3.4" == "${GCCBRANCH}" ] ; then
500 epatch "${FILESDIR}"/gnat-Make-lang.in.patch
503 # gcc 4.3 sources seem to have a common omission of $(DESTDIR),
504 # that leads to make install trying to rm -f file on live system.
505 # As we do not need this rm, we simply remove the whole line
506 if [ "4.3" == "${GCCBRANCH}" ] ; then
507 sed -i -e "/\$(RM) \$(bindir)/d" "${S}"/gcc/ada/Make-lang.in
510 find "${S}" -name Makefile.in \
511 -exec sed -i '/^pkgconfigdir/s:=.*:=$(toolexeclibdir)/pkgconfig:' {} +
513 mkdir -p "${GNATBUILD}"
517 gnatbuild-r1_src_unpack base_unpack common_prep
524 # for now just dont run default configure
525 gnatbuild-r1_src_configure() {
529 # it would be nice to split configure and make steps
530 # but both need to operate inside specially tuned evironment
531 # so just do sections for now (as in eclass section of handbook)
532 # sections are: configure, make-tools, bootstrap,
533 # gnatlib_and_tools, gnatlib-shared
534 gnatbuild-r1_src_compile() {
535 debug-print-function ${FUNCNAME} $@
537 if [[ -z "$1" ]]; then
538 gnatbuild-r1_src_compile all
542 if [[ "all" == "$1" ]]
543 then # specialcasing "all" to avoid scanning sources unnecessarily
544 gnatbuild-r1_src_compile configure make-tools \
545 bootstrap gnatlib_and_tools gnatlib-shared
548 # Set some paths to our bootstrap compiler.
549 export PATH="${GNATBOOT}/bin:${PATH}"
550 # !ATTN! the bootstrap compilers have a very simplystic structure,
551 # so many paths are not identical to the installed ones.
552 # Plus it was simplified even more in new releases.
553 if [[ ${BOOT_SLOT} > 4.1 ]] ; then
556 GNATLIB="${GNATBOOT}/lib/gcc/${BOOT_TARGET}/${BOOT_SLOT}"
559 GNATLIB="${GNATBOOT}/lib/gcc/${BOOT_TARGET}/${BOOT_VER}"
562 GNATLIB="${GNATBOOT}/lib"
566 GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_SLOT}"
569 export CC="${GNATBOOT}/bin/gnatgcc"
570 export CXX="${GNATBOOT}/bin/gnatg++"
571 export LDFLAGS="${LDFLAGS}"
572 export CFLAGS="${CFLAGS}"
573 export CXXFLAGS="${CFLAGS}"
574 # CPATH is supposed to be applied for any language, thus
575 # superceding either of C/CPLUS/OBJC_INCLUDE_PATHs
576 export CPATH="${GNATLIB}/include"
578 LDFLAGS="${LDFLAGS} -L${GNATLIB}"
580 # additional vars from gnuada and elsewhere
581 export LIBRARY_PATH="${GNATLIB}"
583 STDCXX_INCDIR="${LIBPATH}/include/g++-v${SLOT/\.*/}"
585 export ADA_OBJECTS_PATH="${GNATLIB}/adalib"
586 export ADA_INCLUDE_PATH="${GNATLIB}/adainclude"
591 debug-print-section configure
595 confgcc="${confgcc} --host=${CHOST}"
597 # some cross-compile logic from toolchain
598 if is_crosscompile || tc-is-cross-compiler ; then
599 confgcc="${confgcc} --target=${CTARGET}"
601 [[ -n ${CBUILD} ]] && confgcc="${confgcc} --build=${CBUILD}"
603 # Native Language Support
605 confgcc="${confgcc} --enable-nls --without-included-gettext"
607 confgcc="${confgcc} --disable-nls"
610 # bug 586538: extra lto-wrapper dorks up system gcc
611 confgcc="${confgcc} --disable-lto"
613 # setup multilib abi stuff
614 gcc-multilib-configure
616 use hardened && confgcc="${confgcc} --enable-esp"
618 # reasonably sane globals (from toolchain)
619 # also disable mudflap and ssp
620 confgcc="${confgcc} \
621 --enable-languages="c,ada,c++" \
627 --enable-checking=release \
628 --enable-libstdcxx-time \
629 --disable-libmudflap \
632 --disable-fixed-point \
634 --disable-libcilkrts \
635 --disable-libquadmath \
636 --enable-libsanitizer \
637 --enable-targets=all \
638 --with-bugurl=https://bugs.gentoo.org/ \
639 --with-python-dir=${DATAPATH/$PREFIX/}/python"
641 if in_iuse openmp ; then
642 # Make sure target has pthreads support. #326757 #335883
643 # There shouldn't be a chicken&egg problem here as openmp won't
644 # build without a C library, and you can't build that w/out
645 # already having a compiler ...
646 if ! is_crosscompile || \
647 $(tc-getCPP ${CTARGET}) -E - <<<"#include <pthread.h>" >& /dev/null
651 confgcc="${confgcc} --disable-libgomp"
655 confgcc="${confgcc} --enable-libgomp"
657 confgcc="${confgcc} --disable-libgomp"
662 # Force disable as the configure script can be dumb #359855
663 confgcc="${confgcc} --disable-libgomp"
666 # For gcc variants where we don't want openmp (e.g. kgcc)
667 confgcc="${confgcc} --disable-libgomp"
670 # ACT's gnat-gpl does not like libada for whatever reason..
671 if tc_version_is_at_least 4.2 ; then
672 confgcc="${confgcc} --enable-libada"
674 # einfo "ACT's gnat-gpl does not like libada, disabling"
675 # confgcc="${confgcc} --disable-libada"
678 # set some specifics available in later versions
679 confgcc="${confgcc} --enable-shared"
680 if tc_version_is_at_least 4.7 ; then
681 einfo "setting gnat thread model"
682 confgcc="${confgcc} --enable-threads=posix"
683 confgcc="${confgcc} --enable-shared=boehm-gc,ada,libada"
684 elif tc_version_is_at_least 4.3 ; then
685 confgcc="${confgcc} --enable-threads=gnat"
686 confgcc="${confgcc} --enable-shared=boehm-gc,ada,libada"
688 confgcc="${confgcc} --enable-threads=posix"
692 case $(tc-is-softfloat) in
693 yes) confgcc="${confgcc} --with-float=soft" ;;
694 softfp) confgcc="${confgcc} --with-float=softfp" ;;
696 # If they've explicitly opt-ed in, do hardfloat,
697 # otherwise let the gcc default kick in.
698 case ${CTARGET//_/-} in
699 *-hardfloat-*|*eabihf) confgcc="${confgcc} --with-float=hard" ;;
703 # multilib and arch support
706 local a arm_arch=${CTARGET%%-*}
707 # Remove trailing endian variations first: eb el be bl b l
708 for a in e{b,l} {b,l}e b l ; do
709 if [[ ${arm_arch} == *${a} ]] ; then
710 arm_arch=${arm_arch%${a}}
714 # Convert armv7{a,r,m} to armv7-{a,r,m}
715 [[ ${arm_arch} == armv7? ]] && arm_arch=${arm_arch/7/7-}
716 # See if this is a valid --with-arch flag
717 if (srcdir=${S}/gcc target=${CTARGET} with_arch=${arm_arch};
718 . "${srcdir}"/config.gcc) &>/dev/null
720 confgcc="${confgcc} --with-arch=${arm_arch}"
723 # Make default mode thumb for microcontroller classes #418209
724 [[ ${arm_arch} == *-m ]] && confgcc="${confgcc} --with-mode=thumb"
727 if [[ $(tc-is-softfloat) == "no" ]] && \
728 [[ ${CTARGET} == armv[67]* ]]
730 # Follow the new arm hardfp distro standard by default
731 confgcc="${confgcc} --with-float=hard"
733 armv6*) confgcc="${confgcc} --with-fpu=vfp" ;;
734 armv7*) confgcc="${confgcc} --with-fpu=vfpv3-d16" ;;
739 # Add --with-abi flags to set default ABI
740 confgcc="${confgcc} --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI})"
743 # Set up defaults based on current CFLAGS
744 is-flagq -mfloat-gprs=double && confgcc="${confgcc} --enable-e500-double"
745 [[ ${CTARGET//_/-} == *-e500v2-* ]] && confgcc="${confgcc} --enable-e500-double"
748 if is_multilib ; then
749 confgcc="${confgcc} --enable-multilib"
750 if has x32 $(get_all_abis TARGET) ; then
751 confgcc="${confgcc} --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI})"
754 confgcc="${confgcc} --disable-multilib"
758 confgcc="${confgcc} --with-arch=${CTARGET%%-*}"
759 confgcc="${confgcc} --disable-multilib"
763 # __cxa_atexit is "essential for fully standards-compliant handling of
764 # destructors", but apparently requires glibc.
765 if [[ ${CTARGET} == *-gnu* ]] ; then
766 confgcc="${confgcc} --enable-__cxa_atexit"
767 confgcc="${confgcc} --enable-clocale=gnu"
770 export gcc_cv_lto_plugin=1 # okay to build, default to opt-in
771 export gcc_cv_prog_makeinfo_modern=no
772 export ac_cv_have_x='have_x=yes ac_x_includes= ac_x_libraries='
773 use hardened && export gcc_cv_libc_provides_ssp=yes
775 # need to strip graphite/lto flags or we'll get the
776 # dreaded C compiler cannot create executables...
778 # filter-flags -floop-interchange -floop-strip-mine -floop-block
779 # filter-flags -fuse-linker-plugin -flto*
781 replace-flags -O? -O2
782 filter-flags '-mabi*' -m31 -m32 -m64
783 filter-flags -frecord-gcc-switches
784 filter-flags -mno-rtm -mno-htm
786 # gold linker barfs on some arches/configs :/
787 #tc-ld-is-gold && tc-ld-disable-gold
791 filter-flags '-mcpu=*'
797 # strip-unsupported-flags
799 STAGE1_CFLAGS="${CFLAGS} -fPIC"
800 use hardened && STAGE1_CFLAGS="-O2 -fPIC"
801 BOOT_CFLAGS="$(get_abi_CFLAGS ${TARGET_DEFAULT_ABI}) ${CFLAGS} -fPIC"
802 is_crosscompile && BOOT_CFLAGS="-O2 -fPIC"
804 einfo "Environment vars:
808 ABI=${TARGET_DEFAULT_ABI},
809 TARGET_ABI=${TARGET_ABI}.
810 TARGET_MULTILIB_ABIS=${TARGET_MULTILIB_ABIS},
811 TARGET_DEFAULT_ABI=${TARGET_DEFAULT_ABI},
812 GCC_ABI=$(gcc-abi-map ${TARGET_DEFAULT_ABI})
813 ADA_OBJECTS_PATH=${ADA_OBJECTS_PATH},
814 ADA_INCLUDE_PATH=${ADA_INCLUDE_PATH},
817 confgcc="${confgcc} ${EXTRA_ECONF}"
818 einfo "Configuring with confgcc=${confgcc}"
820 pushd "${GNATBUILD}" > /dev/null
821 CC="${CC}" CXX="${CXX}" \
822 LDFLAGS="${LDFLAGS}" \
824 CXXFLAGS="${CFLAGS}" \
826 --prefix="${PREFIX}" \
827 --bindir="${BINPATH}" \
828 --includedir="${INCLUDEPATH}" \
829 --datadir="${DATAPATH}" \
830 --mandir="${DATAPATH}"/man \
831 --infodir="${DATAPATH}"/info \
832 --with-gxx-include-dir="${STDCXX_INCDIR}" \
833 --with-pkgversion="Gentoo Hardened ${GNATRELEASE} p${PATCH_VER}, pie-${PIE_VER}" \
834 ${confgcc} || die "configure failed"
839 debug-print-section make-tools
840 # Compile helper tools
842 cp "${S}"/gcc/ada/xtreeprs.adb .
843 cp "${S}"/gcc/ada/xsinfo.adb .
844 cp "${S}"/gcc/ada/xeinfo.adb .
845 cp "${S}"/gcc/ada/xnmake.adb .
846 cp "${S}"/gcc/ada/xutil.ad{s,b} .
847 if (( ${GNATMINOR} > 5 )) ; then
848 cp "${S}"/gcc/ada/einfo.ad{s,b} .
849 cp "${S}"/gcc/ada/csinfo.adb .
850 cp "${S}"/gcc/ada/ceinfo.adb .
853 gnatmake xtreeprs && \
856 gnatmake xnmake || die "building helper tools"
858 mv xeinfo xnmake xsinfo xtreeprs bin/
862 debug-print-section bootstrap
863 # and, finally, the build itself
864 # do we need this? STAGE1_CFLAGS="${CFLAGS}"
865 # or this? bootstrap-lean
866 # removing both to try --disable-bootstrap
867 pushd "${GNATBUILD}" >/dev/null
870 LDFLAGS="${LDFLAGS}" \
871 LIBPATH="${LIBPATH}" \
872 CC="${CC}" CXX="${CXX}" \
873 STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
874 LIBRARY_VERSION="${SLOT}" \
875 BOOT_CFLAGS="${BOOT_CFLAGS}" \
877 || die "bootstrap failed"
883 debug-print-section gnatlib_and_tools
884 einfo "building gnatlib_and_tools"
886 emake -j1 -C gcc gnatlib_and_tools || \
887 die "gnatlib_and_tools failed"
891 debug-print-section gnatlib-shared
892 einfo "building shared lib"
894 rm -f gcc/ada/rts/*.{o,ali} || die
895 #otherwise make tries to reuse already compiled (without -fPIC) objs..
896 emake -j1 -C gcc gnatlib-shared LIBRARY_VERSION="${SLOT}" || \
897 die "gnatlib-shared failed"
905 # -- end gnatbuild-r1_src_compile
908 gnatbuild-r1_src_install() {
909 debug-print-function ${FUNCNAME} $@
911 if [[ -z "$1" ]] ; then
912 gnatbuild-r1_src_install all
918 install) # runs provided make install
919 debug-print-section install
921 # Looks like we need an access to the bootstrap compiler here too
922 # as gnat apparently wants to compile something during the installation
923 # The spotted obuser was xgnatugn, used to process gnat_ugn_urw.texi,
924 # during preparison of the docs.
925 export PATH="${GNATBOOT}/bin:${PATH}"
926 if [[ ${BOOT_SLOT} > 4.1 ]] ; then
927 GNATLIB="${GNATBOOT}/lib"
928 elif [[ ${BOOT_SLOT} > 4.8 ]] ; then
929 GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_VER}"
931 GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_SLOT}"
934 export CC="${GNATBOOT}/bin/gnatgcc"
935 #export INCLUDE_DIR="${GNATLIB}/include"
936 #export C_INCLUDE_PATH="${GNATLIB}/include"
937 #export CPLUS_INCLUDE_PATH="${GNATLIB}/include"
938 export ADA_OBJECTS_PATH="${GNATLIB}/adalib"
939 export ADA_INCLUDE_PATH="${GNATLIB}/adainclude"
941 # Do not allow symlinks in /usr/lib/gcc/${CHOST}/${MY_PV}/include as
942 # this can break the build.
943 find "${GNATBUILD}"/\*gcc/include/ -type l -delete
945 # Remove generated headers, as they can cause things to break
946 # (ncurses, openssl, etc). (from toolchain.eclass)
947 for x in $(find "${WORKDIR}"/build/gcc/include/ -name '*.h') ; do
948 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
954 make -j1 DESTDIR="${D}" install || die
956 find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;
957 find "${D}" -name libiberty.a -delete
959 # Disable RANDMMAP so PCH works. #301299
960 pax-mark r "${D}${LIBEXECPATH}"/{gnat1,cc1,cc1plus}
962 # Quiet QA warnings, wait for adacore exec stack patch in gcc 7
963 # (note: needs testing with hardened emulate trampolines)
964 #if use hardened ; then
965 # pax-mark Emr "${D}"${BINPATH}/{gnatmake,gnatname,gnatls,gnatclean,gnat}
967 # export QA_EXECSTACK="${BINPATH:1}/gnatls ${BINPATH:1}/gnatname
968 # ${BINPATH:1}/gnatmake ${BINPATH:1}/gnatclean ${BINPATH:1}/gnat
969 # ${LIBEXECPATH:1}/gnat1 ${LIBPATH:1}/adalib/libgnat-${SLOT}.so"
971 # export QA_EXECSTACK="${BINPATH:1}/gnatls ${BINPATH:1}/gnatname
972 # ${BINPATH:1}/gnatmake ${BINPATH:1}/gnatclean ${BINPATH:1}/gnat"
974 use hardened && pax-mark E "${D}${BINPATH}"/{gnatmake,gnatname,gnatls,gnatclean,gnat}
977 if (( $(bc <<< "${GNATBRANCH} > 4.3") )) ; then
978 #make a convenience info link
979 ewarn "Yay! Math works."
980 dosym gnat_ugn.info ${DATAPATH}/info/gnat.info
986 debug-print-section move_libs
988 # first we need to remove some stuff to make moving easier
989 #rm -rf "${D}${LIBPATH}"/{32,include}
990 # gcc insists on installing libs in its own place
991 cp -a -t "${D}${LIBPATH}"/ "${D}${PREFIX}"/lib/gcc/"${CTARGET}/${GCCRELEASE}"/*
992 cp -a -t "${D}${LIBEXECPATH}"/ "${D}${PREFIX}"/libexec/gcc/"${CTARGET}/${GCCRELEASE}"/*
993 rm -rf "${D}${PREFIX}"/libexec/gcc
995 # libgcc_s and, with gcc>=4.0, other libs get installed in multilib specific locations by gcc
996 # we pull everything together to simplify working environment
997 if is_multilib ; then
1000 cp -a -t "${D}${LIBPATH}"/ "${D}${PREFIX}"/lib/"${PN}/${CTARGET}/${SLOT}"/*
1001 mv -t "${D}${LIBPATH}"/32/ "${D}${PREFIX}"/lib32/*
1002 mv -t "${D}${LIBPATH}"/ "${D}${PREFIX}"/lib64/lib*
1003 rm -rf "${D}${PREFIX}"/lib "${D}${PREFIX}"/lib32
1006 # not supported yet, will have to be adjusted when we
1007 # actually build gnat for that arch
1011 # x86 cleanup (maybe arm)
1012 mv -t "${D}${LIBPATH}"/ "${D}${PREFIX}/lib/gcc/${CTARGET}/${GCCRELEASE}"/*
1013 mv -t "${D}${LIBPATH}"/ "${D}${PREFIX}"/lib/lib*
1014 #mv -t "${D}${LIBPATH}"/include/ "${D}${LIBPATH}"/gcc/"${CTARGET}/${GCCRELEASE}"/include/*
1015 rm -rf "${D}${PREFIX}"/lib/gcc
1016 rm -rf "${D}${LIBPATH}"/gcc
1019 local py gdbdir=/usr/share/gdb/auto-load${LIBPATH/\/lib\//\/$(get_libdir)\/}
1020 pushd "${D}${LIBPATH}" >/dev/null
1021 for py in $(find . -name '*-gdb.py') ; do
1022 local multidir=${py%/*}
1023 insinto "${gdbdir}/${multidir}"
1024 sed -i "/^libdir =/s:=.*:= '${LIBPATH}/${multidir}':" "${py}" || die
1025 doins "${py}" || die
1032 debug-print-section cleanup
1034 # force gnatgcc to use its own specs - versions prior to 3.4.6 read specs
1035 # from system gcc location. Do the simple wrapper trick for now
1036 # !ATTN! change this if eselect-gnat starts to follow eselect-compiler
1038 if [[ ${GCCVER} < 3.4.6 ]] ; then
1039 # gcc 4.1 uses builtin specs. What about 4.0?
1040 mv gnatgcc gnatgcc_2wrap
1041 cat > gnatgcc << EOF
1043 # wrapper to cause gnatgcc read appropriate specs and search for the right .h
1044 # files (in case no matching gcc is installed)
1045 BINDIR=\$(dirname \$0)
1046 # The paths in the next line have to be absolute, as gnatgcc may be called from
1048 \${BINDIR}/gnatgcc_2wrap -specs="${LIBPATH}/specs" -I"${LIBPATH}/include" \$@
1053 for i in cpp gcc gcov c++ g++ ; do
1058 # earlier gnat's generate some Makefile's at generic location, need to
1059 # move to avoid collisions
1060 [ -f "${D}${PREFIX}"/share/gnat/Makefile.generic ] &&
1061 mv "${D}${PREFIX}"/share/gnat/Makefile.* "${D}${DATAPATH}"
1063 rm -rf "${D}${LIBPATH}"/install-tools "${D}${LIBEXECPATH}"/install-tools
1065 # remove duplicate docs
1066 rm -rf "${D}${DATAPATH}"/info
1067 rm -rf "${D}${DATAPATH}"/man
1069 # fix .la path for lto plugin
1070 [ -f "${D}${LIBEXECPATH}"/liblto_plugin.la ] &&
1072 "/libdir=/c\libdir='${LIBEXECPATH}'" \
1073 "${D}${LIBEXECPATH}"/liblto_plugin.la
1075 # use gid of 0 because some stupid ports don't have
1076 # the group 'root' set to gid 0 (toolchain.eclass)
1077 chown -R root:0 "${D}${LIBPATH}" 2>/dev/null
1079 # add hardening spec stuff
1080 if use hardened ; then
1081 insinto "${LIBPATH}"
1082 doins "${WORKDIR}"/specs/*.specs || die "failed to install specs"
1087 # instead of putting junk under /etc/env.d/gnat we recreate env files as
1088 # needed with eselect
1093 # remove the move to test new install paths # move_libs
1094 gnatbuild-r1_src_install install move_libs cleanup prep_env
1100 # -- end gnatbuild-r1_src_install