|
| 1 | +# Copyright 1999-2024 Gentoo Authors |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +EAPI=8 |
| 5 | + |
| 6 | +TOOLCHAIN_PATCH_DEV="sam" |
| 7 | +TOOLCHAIN_HAS_TESTS=1 |
| 8 | +PATCH_GCC_VER="14.1.0" |
| 9 | +PATCH_VER="4" |
| 10 | +MUSL_VER="1" |
| 11 | +MUSL_GCC_VER="14.1.0" |
| 12 | +PYTHON_COMPAT=( python3_{10..12} ) |
| 13 | + |
| 14 | +if [[ -n ${TOOLCHAIN_GCC_RC} ]] ; then |
| 15 | + # Cheesy hack for RCs |
| 16 | + MY_PV=$(ver_cut 1).$((($(ver_cut 2) + 1))).$((($(ver_cut 3) - 1)))-RC-$(ver_cut 5) |
| 17 | + MY_P=${PN}-${MY_PV} |
| 18 | + GCC_TARBALL_SRC_URI="mirror://gcc/snapshots/${MY_PV}/${MY_P}.tar.xz" |
| 19 | + TOOLCHAIN_SET_S=no |
| 20 | + S="${WORKDIR}"/${MY_P} |
| 21 | +fi |
| 22 | + |
| 23 | +inherit toolchain |
| 24 | + |
| 25 | +if tc_is_live ; then |
| 26 | + # Needs to be after inherit (for now?), bug #830908 |
| 27 | + EGIT_BRANCH=releases/gcc-$(ver_cut 1) |
| 28 | +elif [[ -z ${TOOLCHAIN_USE_GIT_PATCHES} ]] ; then |
| 29 | + # Don't keyword live ebuilds |
| 30 | + KEYWORDS="~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris" |
| 31 | +fi |
| 32 | + |
| 33 | +# use alternate source for Apple M1 (also works for x86_64) |
| 34 | +SRC_URI+=" elibc_Darwin? ( https://raw.githubusercontent.com/Homebrew/formula-patches/d5dcb918a951b2dcf2d7702db75eb29ef144f614/gcc/gcc-14.2.0.diff -> gcc-14.2.0-arm64-darwin.patch )" |
| 35 | +IUSE+=" bootstrap" |
| 36 | + |
| 37 | +if [[ ${CATEGORY} != cross-* ]] ; then |
| 38 | + # Technically only if USE=hardened *too* right now, but no point in complicating it further. |
| 39 | + # If GCC is enabling CET by default, we need glibc to be built with support for it. |
| 40 | + # bug #830454 |
| 41 | + RDEPEND="!prefix-guest? ( elibc_glibc? ( sys-libs/glibc[cet(-)?] ) )" |
| 42 | + DEPEND="${RDEPEND}" |
| 43 | +fi |
| 44 | + |
| 45 | +src_prepare() { |
| 46 | + # apply big arm64-darwin patch first thing |
| 47 | + use elibc_Darwin && eapply "${DISTDIR}"/${P}-arm64-darwin.patch |
| 48 | + |
| 49 | + # make sure 64-bits native targets don't screw up the linker paths |
| 50 | + eapply "${FILESDIR}"/gcc-12-no-libs-for-startfile.patch |
| 51 | + |
| 52 | + local p upstreamed_patches=( |
| 53 | + # add them here |
| 54 | + ) |
| 55 | + for p in "${upstreamed_patches[@]}"; do |
| 56 | + rm -v "${WORKDIR}/patch/${p}" || die |
| 57 | + done |
| 58 | + |
| 59 | + toolchain_src_prepare |
| 60 | + # |
| 61 | + # make it have correct install_names on Darwin |
| 62 | + eapply -p1 "${FILESDIR}"/4.3.3/darwin-libgcc_s-installname.patch |
| 63 | + |
| 64 | + if [[ ${CHOST} == powerpc*-darwin* ]] ; then |
| 65 | + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44107 |
| 66 | + sed -i -e 's|^ifeq (/usr/lib,|ifneq (/usr/lib,|' \ |
| 67 | + libgcc/config/t-slibgcc-darwin || die |
| 68 | + fi |
| 69 | + |
| 70 | + if [[ ${CHOST} == *-solaris* ]] ; then |
| 71 | + # madvise is not available in the compatibility mode GCC uses, |
| 72 | + # posix_madvise however, is |
| 73 | + sed -i -e 's/madvise/posix_madvise/' gcc/cp/module.cc || die |
| 74 | + fi |
| 75 | + |
| 76 | + if [[ ${CHOST} == *-darwin* ]] ; then |
| 77 | + use bootstrap && eapply "${FILESDIR}"/${PN}-13-darwin14-bootstrap.patch |
| 78 | + |
| 79 | + # our ld64 is a slight bit different, so tweak expression to not |
| 80 | + # get confused and break the build |
| 81 | + sed -i -e "s/EGREP 'ld64|dyld'/& | head -n1/" \ |
| 82 | + gcc/configure{.ac,} || die |
| 83 | + |
| 84 | + # rip out specific macos version min |
| 85 | + sed -i -e 's/-mmacosx-version-min=11.0//' \ |
| 86 | + libgcc/config/aarch64/t-darwin \ |
| 87 | + libgcc/config/aarch64/t-heap-trampoline \ |
| 88 | + || die |
| 89 | + fi |
| 90 | + |
| 91 | + eapply "${FILESDIR}"/${PN}-13-fix-cross-fixincludes.patch |
| 92 | + eapply_user |
| 93 | +} |
| 94 | + |
| 95 | +src_configure() { |
| 96 | + local myconf=() |
| 97 | + case ${CTARGET}:" ${USE} " in |
| 98 | + powerpc*-darwin*) |
| 99 | + # bug #381179 |
| 100 | + filter-flags "-mcpu=*" "-mtune=*" |
| 101 | + # bug #657522 |
| 102 | + # A bug in configure checks whether -no-pie works, but the |
| 103 | + # compiler doesn't pass -no-pie onto the linker if -fno-PIE |
| 104 | + # isn't passed, so the configure check always finds -no-pie |
| 105 | + # is accepted. (Likewise, when -fno-PIE is passed, the |
| 106 | + # compiler passes -no_pie onto the linker.) |
| 107 | + # Since our linker doesn't grok this, avoid above checks to |
| 108 | + # be run |
| 109 | + # NOTE: later ld64 does grok -no_pie, not -no-pie (as checked) |
| 110 | + export gcc_cv_c_no_fpie=no |
| 111 | + export gcc_cv_no_pie=no |
| 112 | + ;; |
| 113 | + *-darwin20) |
| 114 | + # use sysroot with the linker, #756160 |
| 115 | + export gcc_cv_ld_sysroot=yes |
| 116 | + ;; |
| 117 | + *-solaris*) |
| 118 | + # todo: some magic for native vs. GNU linking? |
| 119 | + myconf+=( --with-gnu-ld --with-gnu-as --enable-largefile ) |
| 120 | + ;; |
| 121 | + i[34567]86-*-linux*:*" prefix "*) |
| 122 | + # to allow the linux-x86-on-amd64.patch become useful, we need |
| 123 | + # to enable multilib, even if there is just one multilib option. |
| 124 | + myconf+=( --enable-multilib ) |
| 125 | + if [[ ${CBUILD:-${CHOST}} == "${CHOST}" ]]; then |
| 126 | + # we might be on x86_64-linux, but don't do cross-compile, so |
| 127 | + # tell the host-compiler to really create 32bits (for stage1) |
| 128 | + # (real x86-linux-gcc also accept -m32). |
| 129 | + append-flags -m32 |
| 130 | + fi |
| 131 | + ;; |
| 132 | + esac |
| 133 | + |
| 134 | + # Since GCC 4.1.2 some non-posix (?) /bin/sh compatible code is used, at |
| 135 | + # least on Solaris, and AIX /bin/sh is way too slow, |
| 136 | + # so force it to use $BASH (that portage uses) - it can't be EPREFIX |
| 137 | + # in case that doesn't exist yet |
| 138 | + export CONFIG_SHELL="${CONFIG_SHELL:-${BASH}}" |
| 139 | + toolchain_src_configure "${myconf[@]}" |
| 140 | +} |
0 commit comments