net-irc/limnoria: use HTTPS for GitHub and HOMEPAGE
[gentoo.git] / eclass / gnatbuild-r1.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 for 4.4 - 4.6
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 EXPORTED_FUNCTIONS="pkg_setup pkg_postinst pkg_postrm src_unpack src_configure src_compile src_install"
25
26 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
27
28 IUSE="nls openmp hardened multilib"
29 # multilib is supported via profiles now, multilib usevar is deprecated
30
31 RDEPEND="virtual/libiconv
32         nls? ( virtual/libintl )"
33
34 DEPEND="${RDEPEND}
35         >=app-eselect/eselect-gnat-1.5
36         >=sys-libs/glibc-2.12
37         >=sys-devel/binutils-2.23
38         sys-devel/bc
39         >=sys-devel/bison-1.875
40         >=sys-devel/flex-2.5.4
41         nls? ( sys-devel/gettext )"
42
43 # Note!
44 # It may not be safe to source this at top level. Only source inside local
45 # functions!
46 GnatCommon="/usr/share/gnat/lib/gnat-common.bash"
47
48 #---->> globals and SLOT <<----
49
50 # just a check, this location seems to vary too much, easier to track it in
51 # ebuild
52 #[ -z "${GNATSOURCE}" ] && die "please set GNATSOURCE in ebuild! (before inherit)"
53
54 # versioning
55 # because of gnatpro/gnatgpl we need to track both gcc and gnat versions
56
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
63 # number added on top
64 ACT_Ver=$(get_version_component_range 4)
65
66 # GCCVER and SLOT logic
67 #
68 # I better define vars for package names, as there was discussion on proper
69 # naming and it may change
70 PN_GnatGCC="gnat-gcc"
71 PN_GnatGpl="gnat-gpl"
72
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*!!
76 #
77 # GCCVER can be set in the ebuild.
78 [[ -z ${GCCVER} ]] && GCCVER="${GNATRELEASE}"
79
80
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}")
86
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}"
92
93 # possible future crosscompilation support
94 export CTARGET=${CTARGET:-${CHOST}}
95
96 is_crosscompile() {
97         [[ ${CHOST} != ${CTARGET} ]]
98 }
99
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}
105
106 # for newer bootstrap starting with 4.9 (still experimental)
107 BOOT_VER=${GCCRELEASE}
108
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}"
120
121 # ebuild globals
122 if [[ ${PN} == "${PN_GnatPro}" ]] && [[ ${GNATMAJOR} == "3" ]]; then
123                 DEPEND="x86? ( >=app-shells/tcsh-6.0 )"
124 fi
125 S="${WORKDIR}/gcc-${GCCVER}"
126
127 # bootstrap globals, common to src_unpack and src_compile
128 GNATBOOT="${WORKDIR}/usr"
129 GNATBUILD="${WORKDIR}/build"
130 #GNATBUILD="${BUILD_DIR}"
131
132 # necessary for detecting lib locations and creating env.d entry
133 #XGCC="${GNATBUILD}/gcc/xgcc -B${GNATBUILD}/gcc"
134
135 #----<< globals and SLOT >>----
136
137 # set SRC_URI's in ebuilds for now
138
139 #----<< global toolchain vars >>----
140
141 : ${TARGET_ABI:=${ABI}}
142 : ${TARGET_MULTILIB_ABIS:=${MULTILIB_ABIS}}
143 : ${TARGET_DEFAULT_ABI:=${DEFAULT_ABI}}
144
145
146 #---->> specs + env.d logic <<----
147 # TODO!!!
148 # set MANPATH, etc..
149 #----<< specs + env.d logic >>----
150
151
152 #---->> some helper functions <<----
153 tc_version_is_at_least() {
154         version_is_at_least "$1" "${2:-${GCCBRANCH}}"
155 }
156
157 guess_patch_type_in_dir() {
158         [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
159                 && EPATCH_SUFFIX="patch.bz2" \
160                 || EPATCH_SUFFIX="patch"
161 }
162
163 # configure to build with the hardened GCC specs as the default
164 make_gcc_hard() {
165         # we want to be able to control the pie patch logic via something other
166         # than ALL_CFLAGS...
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
175         fi
176
177         # defaults to enable for new gnatbuild
178         if use hardened ; then
179                 gcc_hard_flags=" -DEFAULT_PIE_SSP"
180         else
181                 gcc_hard_flags+=" -DEFAULT_SSP"
182         fi
183
184         sed -i \
185                 -e "/^HARD_CFLAGS = /s|=|= ${gcc_hard_flags} |" \
186                 "${S}"/gcc/Makefile.in || die
187
188 }
189
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.
197         else
198                 confgcc="${confgcc} --enable-multilib"
199         fi
200
201         # translate our notion of multilibs into gcc's
202         local abi list
203         for abi in $(get_all_abis TARGET) ; do
204                 local l=$(gcc-abi-map ${abi})
205                 [[ -n ${l} ]] && list+=",${l}"
206         done
207         if [[ -n ${list} ]] ; then
208                 case ${CTARGET} in
209                 x86_64*)
210                         tc_version_is_at_least 4.8 && confgcc="${confgcc} --with-multilib-list=${list:1}"
211                         ;;
212                 esac
213         fi
214 }
215
216 gcc-abi-map() {
217         # Convert the ABI name we use in Gentoo to what gcc uses
218         local map=()
219         case ${CTARGET} in
220                 mips*)   map=("o32 32" "n32 n32" "n64 64") ;;
221                 x86_64*) map=("amd64 m64" "x86 m32" "x32 mx32") ;;
222         esac
223
224         local m
225         for m in "${map[@]}" ; do
226                 l=( ${m} )
227         [[ $1 == ${l[0]} ]] && echo ${l[1]} && break
228         done
229 }
230
231 is_multilib() {
232         tc_version_is_at_least 3 || return 1
233         use multilib
234 }
235
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
240 #}
241
242 # eselect stuff taken straight from toolchain.eclass and greatly simplified
243 add_profile_eselect_conf() {
244         local gnat_config_file=$1
245         local abi=$2
246         local var
247
248         echo >> "${D}/${gnat_config_file}"
249         if ! is_multilib ; then
250                 echo "  ctarget=${CTARGET}" >> "${D}/${gnat_config_file}"
251         else
252                 echo "[${abi}]" >> "${D}/${gnat_config_file}"
253                 var="CTARGET_${abi}"
254                 if [[ -n ${!var} ]] ; then
255                         echo "  ctarget=${!var}" >> "${D}/${gnat_config_file}"
256                 else
257                         var="CHOST_${abi}"
258                         if [[ -n ${!var} ]] ; then
259                                 echo "  ctarget=${!var}" >> "${D}/${gnat_config_file}"
260                         else
261                                 echo "  ctarget=${CTARGET}" >> "${D}/${gnat_config_file}"
262                         fi
263                 fi
264         fi
265
266         var="CFLAGS_${abi}"
267         if [[ -n ${!var} ]] ; then
268                 echo "  cflags=${!var}" >> "${D}/${gnat_config_file}"
269         fi
270 }
271
272 create_eselect_conf() {
273         local abi
274
275         dodir ${CONFIG_PATH}
276
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}"
285
286         for abi in $(get_all_abis) ; do
287                 add_profile_eselect_conf "${gnat_config_file}" "${abi}"
288         done
289 }
290
291 should_we_eselect_gnat() {
292         # we only want to switch compilers if installing to / or /tmp/stage1root
293         [[ ${ROOT} == "/" ]] || return 1
294
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
297         local curr_config
298         curr_config=$(eselect --colour=no gnat show | grep ${CTARGET} | awk '{ print $1 }') || return 0
299         [[ -z ${curr_config} ]] && return 0
300
301         # The logic is basically "try to keep the same profile if possible"
302
303         if [[ ${curr_config} == ${CTARGET}-${PN}-${SLOT} ]] ; then
304                 return 0
305         else
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"
309                 elog "following:"
310                 echo
311                 elog "eselect gnat set <profile>"
312                 echo
313                 ebeep
314                 return 1
315         fi
316 }
317
318 # active compiler selection, called from pkg_postinst
319 do_gnat_config() {
320         eselect gnat set ${CTARGET}-${PN}-${SLOT} &> /dev/null
321
322         elog "The following gnat profile has been activated:"
323         elog "${CTARGET}-${PN}-${SLOT}"
324         elog ""
325         elog "The compiler has been installed as gnatgcc, and the coverage testing"
326         elog "tool as gnatgcov."
327         elog ""
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"
332 }
333
334
335 # Taken straight from the toolchain.eclass. Only removed the "obsolete hunk"
336 #
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.
342 #
343 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
344 #
345 disgusting_gcc_multilib_HACK() {
346         local config
347         local libdirs
348         if has_multilib_profile ; then
349                 case $(tc-arch) in
350                         amd64)
351                                 config="i386/t-linux64"
352                                 libdirs="../$(get_abi_LIBDIR amd64) ../$(get_abi_LIBDIR x86)" \
353                         ;;
354                         ppc64)
355                                 config="rs6000/t-linux64"
356                                 libdirs="../$(get_abi_LIBDIR ppc64) ../$(get_abi_LIBDIR ppc)" \
357                         ;;
358                 esac
359         else
360                 die "Your profile is no longer supported by portage."
361         fi
362
363         einfo "updating multilib directories to be: ${libdirs}"
364         sed -i -e "s:^MULTILIB_OSDIRNAMES.*:MULTILIB_OSDIRNAMES = ${libdirs}:" "${S}"/gcc/config/${config}
365 }
366
367
368 #---->> pkg_* <<----
369 gnatbuild-r1_pkg_setup() {
370         debug-print-function ${FUNCNAME} $@
371
372         # Setup variables which would normally be in the profile
373         if is_crosscompile ; then
374                 multilib_env ${CTARGET}
375         fi
376
377         # we dont want to use the installed compiler's specs to build gnat!
378         unset GCC_SPECS
379         unset LANGUAGES #265283
380 }
381
382 gnatbuild-r1_pkg_postinst() {
383         if should_we_eselect_gnat; then
384                 do_gnat_config
385         else
386                 eselect gnat update
387         fi
388
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)
392         elog
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}."
397         fi
398         elog "Please edit ${PRIMELIST} and list there gnat profiles intended"
399         elog "for common use."
400 }
401
402
403 gnatbuild-r1_pkg_postrm() {
404         # "eselect gnat update" now removes the env.d file if the corresponding
405         # gnat profile was unmerged
406         eselect gnat update
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"
410 }
411 #---->> pkg_* <<----
412
413 #---->> src_* <<----
414
415 # common unpack stuff
416 gnatbuild-r1_src_unpack() {
417         debug-print-function ${FUNCNAME} $@
418
419         [ -z "$1" ] &&  gnatbuild-r1_src_unpack all
420
421         while [ "$1" ]; do
422         case $1 in
423                 base_unpack)
424                         unpack ${A}
425                         pax-mark E $(find ${GNATBOOT} -name gnat1)
426
427                         cd "${S}"
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
436
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
440                         fi
441                         #
442                         # then per SLOT
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
446                         fi
447
448                         # add hardening as per toolchain eclass
449                         make_gcc_hard
450
451                         # Replacing obsolete head/tail with POSIX compliant ones
452                         ht_fix_file */configure
453
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"
457 #                       fi
458
459                         # Fixup libtool to correctly generate .la files with portage
460                         cd "${S}"
461                         elibtoolize --portage --shallow --no-uclibc
462
463                         gnuconfig_update
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"
470                                 eend $?
471                         done
472
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
477
478                         [[ ${CHOST} == ${CTARGET} ]] && epatch "${FILESDIR}"/gcc-spec-env-r1.patch
479
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
483 #                               eautoconf
484 #                       popd &> /dev/null
485                 ;;
486
487                 common_prep)
488                         # Prepare the gcc source directory
489                         cd "${S}/gcc"
490                         touch cstamp-h.in
491                         touch ada/[es]info.h
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}; \
496                         done
497                         # add -fPIC flag to shared libs for 3.4* backend
498                         if [ "3.4" == "${GCCBRANCH}" ] ; then
499                                 cd ada
500                                 epatch "${FILESDIR}"/gnat-Make-lang.in.patch
501                         fi
502
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
508                         fi
509
510                         find "${S}" -name Makefile.in \
511                                 -exec sed -i '/^pkgconfigdir/s:=.*:=$(toolexeclibdir)/pkgconfig:' {} +
512
513                         mkdir -p "${GNATBUILD}"
514                 ;;
515
516                 all)
517                         gnatbuild-r1_src_unpack base_unpack common_prep
518                 ;;
519         esac
520         shift
521         done
522 }
523
524 # for now just dont run default configure
525 gnatbuild-r1_src_configure() {
526         :
527 }
528
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} $@
536
537         if [[ -z "$1" ]]; then
538                 gnatbuild-r1_src_compile all
539                 return $?
540         fi
541
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
546
547         else
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
554                         case $(tc-arch) in
555                                 arm)
556                                         GNATLIB="${GNATBOOT}/lib/gcc/${BOOT_TARGET}/${BOOT_SLOT}"
557                                         ;;
558                                 x86|amd64)
559                                         GNATLIB="${GNATBOOT}/lib/gcc/${BOOT_TARGET}/${BOOT_VER}"
560                                         ;;
561                                 *)
562                                         GNATLIB="${GNATBOOT}/lib"
563                                         ;;
564                         esac
565                 else
566                         GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_SLOT}"
567                 fi
568
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"
577                 LIB_DIR="${GNATLIB}"
578                 LDFLAGS="${LDFLAGS} -L${GNATLIB}"
579
580                 # additional vars from gnuada and elsewhere
581                 export LIBRARY_PATH="${GNATLIB}"
582
583                 STDCXX_INCDIR="${LIBPATH}/include/g++-v${SLOT/\.*/}"
584
585                 export ADA_OBJECTS_PATH="${GNATLIB}/adalib"
586                 export ADA_INCLUDE_PATH="${GNATLIB}/adainclude"
587
588                 while [ "$1" ]; do
589                 case $1 in
590                         configure)
591                                 debug-print-section configure
592
593                                 # Configure gcc
594                                 local confgcc
595                                 confgcc="${confgcc} --host=${CHOST}"
596
597                                 # some cross-compile logic from toolchain
598                                 if is_crosscompile || tc-is-cross-compiler ; then
599                                         confgcc="${confgcc} --target=${CTARGET}"
600                                 fi
601                                 [[ -n ${CBUILD} ]] && confgcc="${confgcc} --build=${CBUILD}"
602
603                                 # Native Language Support
604                                 if use nls ; then
605                                         confgcc="${confgcc} --enable-nls --without-included-gettext"
606                                 else
607                                         confgcc="${confgcc} --disable-nls"
608                                 fi
609
610                                 # bug 586538: extra lto-wrapper dorks up system gcc
611                                 confgcc="${confgcc} --disable-lto"
612
613                                 # setup multilib abi stuff
614                                 gcc-multilib-configure
615
616                                 use hardened && confgcc="${confgcc} --enable-esp"
617
618                                 # reasonably sane globals (from toolchain)
619                                 # also disable mudflap and ssp
620                                 confgcc="${confgcc} \
621                                         --enable-languages="c,ada,c++" \
622                                         --with-gcc \
623                                         --with-system-zlib \
624                                         --enable-obsolete \
625                                         --enable-secureplt \
626                                         --disable-werror \
627                                         --enable-checking=release \
628                                         --enable-libstdcxx-time \
629                                         --disable-libmudflap \
630                                         --disable-libssp \
631                                         --disable-altivec \
632                                         --disable-fixed-point \
633                                         --disable-libgcj \
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"
640
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
648                                         then
649                                                 case $(tc-arch) in
650                                                         arm)
651                                                                 confgcc="${confgcc} --disable-libgomp"
652                                                                 ;;
653                                                         *)
654                                                                 if use openmp ; then
655                                                                         confgcc="${confgcc} --enable-libgomp"
656                                                                 else
657                                                                         confgcc="${confgcc} --disable-libgomp"
658                                                                 fi
659                                                                 ;;
660                                                 esac
661                                         else
662                                                 # Force disable as the configure script can be dumb #359855
663                                                 confgcc="${confgcc} --disable-libgomp"
664                                         fi
665                                 else
666                                         # For gcc variants where we don't want openmp (e.g. kgcc)
667                                         confgcc="${confgcc} --disable-libgomp"
668                                 fi
669
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"
673 #                               else
674 #                                       einfo "ACT's gnat-gpl does not like libada, disabling"
675 #                                       confgcc="${confgcc} --disable-libada"
676                                 fi
677
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"
687                                 else
688                                         confgcc="${confgcc} --enable-threads=posix"
689                                 fi
690
691                                 # harfloat vs soft
692                                 case $(tc-is-softfloat) in
693                                 yes)    confgcc="${confgcc} --with-float=soft" ;;
694                                 softfp) confgcc="${confgcc} --with-float=softfp" ;;
695                                 *)
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" ;;
700                                         esac
701                                 esac
702
703                                 # multilib and arch support
704                                 case $(tc-arch) in
705                                 arm)
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}}
711                                                         break
712                                                 fi
713                                         done
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
719                                         then
720                                                 confgcc="${confgcc} --with-arch=${arm_arch}"
721                                         fi
722
723                                         # Make default mode thumb for microcontroller classes #418209
724                                         [[ ${arm_arch} == *-m ]] && confgcc="${confgcc} --with-mode=thumb"
725
726                                         # Enable hardvfp
727                                         if [[ $(tc-is-softfloat) == "no" ]] && \
728                                            [[ ${CTARGET} == armv[67]* ]]
729                                         then
730                                                 # Follow the new arm hardfp distro standard by default
731                                                 confgcc="${confgcc} --with-float=hard"
732                                                 case ${CTARGET} in
733                                                 armv6*) confgcc="${confgcc} --with-fpu=vfp" ;;
734                                                 armv7*) confgcc="${confgcc} --with-fpu=vfpv3-d16" ;;
735                                                 esac
736                                         fi
737                                         ;;
738                                 mips)
739                                         # Add --with-abi flags to set default ABI
740                                         confgcc="${confgcc} --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI})"
741                                         ;;
742                                 ppc)
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"
746                                         ;;
747                                 amd64)
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})"
752                                                 fi
753                                         else
754                                                 confgcc="${confgcc} --disable-multilib"
755                                         fi
756                                         ;;
757                                 x86)
758                                         confgcc="${confgcc} --with-arch=${CTARGET%%-*}"
759                                         confgcc="${confgcc} --disable-multilib"
760                                         ;;
761                                 esac
762
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"
768                                 fi
769
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
774
775                                 # need to strip graphite/lto flags or we'll get the
776                                 # dreaded C compiler cannot create executables...
777                                 # error.
778 #                               filter-flags -floop-interchange -floop-strip-mine -floop-block
779 #                               filter-flags -fuse-linker-plugin -flto*
780                                 strip-flags
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
785
786                                 # gold linker barfs on some arches/configs :/
787                                 #tc-ld-is-gold && tc-ld-disable-gold
788
789                                 case $(tc-arch) in
790                                         amd64|x86)
791                                                 filter-flags '-mcpu=*'
792                                                 ;;
793                                         *)
794                                                 ;;
795                                 esac
796
797 #                               strip-unsupported-flags
798
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"
803
804                                 einfo "Environment vars:
805         CC=${CC},
806         CXX=${CXX},
807         CTARGET=${CTARGET}
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},
815         PATH=${PATH}"
816
817                                 confgcc="${confgcc} ${EXTRA_ECONF}"
818                                 einfo "Configuring with confgcc=${confgcc}"
819
820                                 pushd "${GNATBUILD}" > /dev/null
821                                 CC="${CC}" CXX="${CXX}" \
822                                         LDFLAGS="${LDFLAGS}" \
823                                         CFLAGS="${CFLAGS}" \
824                                         CXXFLAGS="${CFLAGS}" \
825                                         "${S}"/configure \
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"
835                                 popd > /dev/null
836                         ;;
837
838                         make-tools)
839                                 debug-print-section make-tools
840                                 # Compile helper tools
841                                 cd "${GNATBOOT}"
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  .
851                                 fi
852
853                                 gnatmake xtreeprs  && \
854                                 gnatmake xsinfo  && \
855                                 gnatmake xeinfo  && \
856                                 gnatmake xnmake || die "building helper tools"
857
858                                 mv xeinfo xnmake xsinfo xtreeprs bin/
859                         ;;
860
861                         bootstrap)
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
868
869                                 emake \
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}" \
876                                         bootstrap-lean \
877                                         || die "bootstrap failed"
878
879                                 popd >/dev/null
880                         ;;
881
882                         gnatlib_and_tools)
883                                 debug-print-section gnatlib_and_tools
884                                 einfo "building gnatlib_and_tools"
885                                 cd "${GNATBUILD}"
886                                 emake -j1 -C gcc gnatlib_and_tools || \
887                                         die "gnatlib_and_tools failed"
888                         ;;
889
890                         gnatlib-shared)
891                                 debug-print-section gnatlib-shared
892                                 einfo "building shared lib"
893                                 cd "${GNATBUILD}"
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"
898                         ;;
899
900                 esac
901                 shift
902                 done # while
903         fi   # "all" == "$1"
904 }
905 # -- end gnatbuild-r1_src_compile
906
907
908 gnatbuild-r1_src_install() {
909         debug-print-function ${FUNCNAME} $@
910
911         if [[ -z "$1" ]] ; then
912                 gnatbuild-r1_src_install all
913                 return $?
914         fi
915
916         while [ "$1" ]; do
917         case $1 in
918         install) # runs provided make install
919                 debug-print-section install
920
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}"
930                 else
931                         GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_SLOT}"
932                 fi
933
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"
940
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
944
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}" \
949                                 && rm -f "${x}"
950                 done
951
952
953                 cd "${GNATBUILD}"
954                 make -j1 DESTDIR="${D}" install || die
955
956                 find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;
957                 find "${D}" -name libiberty.a -delete
958
959                 # Disable RANDMMAP so PCH works. #301299
960                 pax-mark r "${D}${LIBEXECPATH}"/{gnat1,cc1,cc1plus}
961
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}
966                 #else
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"
970                 #fi
971 #               export QA_EXECSTACK="${BINPATH:1}/gnatls ${BINPATH:1}/gnatname
972 #                       ${BINPATH:1}/gnatmake ${BINPATH:1}/gnatclean ${BINPATH:1}/gnat"
973
974                 use hardened && pax-mark E "${D}${BINPATH}"/{gnatmake,gnatname,gnatls,gnatclean,gnat}
975
976                 if use doc ; then
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
981                         fi
982                 fi
983                 ;;
984
985         move_libs)
986                 debug-print-section move_libs
987
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
994
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
998                         case $(tc-arch) in
999                                 amd64)
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
1004                                 ;;
1005                                 ppc64)
1006                                         # not supported yet, will have to be adjusted when we
1007                                         # actually build gnat for that arch
1008                                 ;;
1009                         esac
1010                 else
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
1017                 fi
1018
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
1026                         rm "${py}" || die
1027                 done
1028                 popd >/dev/null
1029                 ;;
1030
1031         cleanup)
1032                 debug-print-section cleanup
1033
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
1037                 cd "${D}${BINPATH}"
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
1042 #! /bin/bash
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
1047 # any location
1048 \${BINDIR}/gnatgcc_2wrap -specs="${LIBPATH}/specs" -I"${LIBPATH}/include" \$@
1049 EOF
1050                         chmod a+x gnatgcc
1051                 else
1052                         local i
1053                         for i in cpp gcc gcov c++ g++ ; do
1054                                 ln -s ${i} gnat${i}
1055                         done
1056                 fi
1057
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}"
1062
1063                 rm -rf "${D}${LIBPATH}"/install-tools "${D}${LIBEXECPATH}"/install-tools
1064
1065                 # remove duplicate docs
1066                 rm -rf  "${D}${DATAPATH}"/info
1067                 rm -rf "${D}${DATAPATH}"/man
1068
1069                 # fix .la path for lto plugin
1070                 [ -f "${D}${LIBEXECPATH}"/liblto_plugin.la ] &&
1071                         sed -i -e \
1072                                 "/libdir=/c\libdir='${LIBEXECPATH}'" \
1073                                 "${D}${LIBEXECPATH}"/liblto_plugin.la
1074
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
1078
1079                 # add hardening spec stuff
1080                 if use hardened ; then
1081                         insinto "${LIBPATH}"
1082                         doins "${WORKDIR}"/specs/*.specs || die "failed to install specs"
1083                 fi
1084                 ;;
1085
1086         prep_env)
1087                 # instead of putting junk under /etc/env.d/gnat we recreate env files as
1088                 # needed with eselect
1089                 create_eselect_conf
1090                 ;;
1091
1092         all)
1093                 # remove the move to test new install paths # move_libs
1094                 gnatbuild-r1_src_install install move_libs cleanup prep_env
1095                 ;;
1096         esac
1097         shift
1098         done # while
1099 }
1100 # -- end gnatbuild-r1_src_install