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