|
| 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 | +PATCH_GCC_VER="13.2.0" |
| 8 | +MUSL_GCC_VER="13.2.0" |
| 9 | +PATCH_VER="16" |
| 10 | +MUSL_VER="2" |
| 11 | +PYTHON_COMPAT=( python3_{10..12} ) |
| 12 | + |
| 13 | +if [[ ${PV} == *.9999 ]] ; then |
| 14 | + MY_PV_2=$(ver_cut 2) |
| 15 | + MY_PV_3=1 |
| 16 | + if [[ ${MY_PV_2} == 0 ]] ; then |
| 17 | + MY_PV_2=0 |
| 18 | + MY_PV_3=0 |
| 19 | + else |
| 20 | + MY_PV_2=$((${MY_PV_2} - 1)) |
| 21 | + fi |
| 22 | + |
| 23 | + # e.g. 12.2.9999 -> 12.1.1 |
| 24 | + TOOLCHAIN_GCC_PV=$(ver_cut 1).${MY_PV_2}.${MY_PV_3} |
| 25 | +elif [[ -n ${TOOLCHAIN_GCC_RC} ]] ; then |
| 26 | + # Cheesy hack for RCs |
| 27 | + MY_PV=$(ver_cut 1).$((($(ver_cut 2) + 1))).$((($(ver_cut 3) - 1)))-RC-$(ver_cut 5) |
| 28 | + MY_P=${PN}-${MY_PV} |
| 29 | + GCC_TARBALL_SRC_URI="mirror://gcc/snapshots/${MY_PV}/${MY_P}.tar.xz" |
| 30 | + TOOLCHAIN_SET_S=no |
| 31 | + S="${WORKDIR}"/${MY_P} |
| 32 | +fi |
| 33 | + |
| 34 | +inherit toolchain |
| 35 | + |
| 36 | +if tc_is_live ; then |
| 37 | + # Needs to be after inherit (for now?), bug #830908 |
| 38 | + EGIT_BRANCH=releases/gcc-$(ver_cut 1) |
| 39 | +elif [[ -z ${TOOLCHAIN_USE_GIT_PATCHES} ]] ; then |
| 40 | + # Don't keyword live ebuilds |
| 41 | + KEYWORDS="~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris" |
| 42 | +fi |
| 43 | + |
| 44 | +# use alternate source for Apple M1 (also works for x86_64) |
| 45 | +SRC_URI+=" elibc_Darwin? ( https://raw.githubusercontent.com/Homebrew/formula-patches/bda0faddfbfb392e7b9c9101056b2c5ab2500508/gcc/gcc-${PV}.diff -> gcc-${PV}-arm64-darwin.patch )" |
| 46 | +IUSE+=" bootstrap" |
| 47 | + |
| 48 | +if [[ ${CATEGORY} != cross-* ]] ; then |
| 49 | + # Technically only if USE=hardened *too* right now, but no point in complicating it further. |
| 50 | + # If GCC is enabling CET by default, we need glibc to be built with support for it. |
| 51 | + # bug #830454 |
| 52 | + RDEPEND="!prefix-guest? ( elibc_glibc? ( sys-libs/glibc[cet(-)?] ) )" |
| 53 | + DEPEND="${RDEPEND}" |
| 54 | + BDEPEND="amd64? ( >=${CATEGORY}/binutils-2.30[cet(-)?] ) |
| 55 | + kernel_Darwin? ( |
| 56 | + || ( ${CATEGORY}/binutils-apple ${CATEGORY}/native-cctools ) |
| 57 | + )" |
| 58 | +fi |
| 59 | + |
| 60 | +src_prepare() { |
| 61 | + # apply big arm64-darwin patch first thing |
| 62 | + use elibc_Darwin && eapply "${DISTDIR}"/gcc-${PV}-arm64-darwin.patch |
| 63 | + |
| 64 | + # make sure 64-bits native targets don't screw up the linker paths |
| 65 | + eapply "${FILESDIR}"/gcc-12-no-libs-for-startfile.patch |
| 66 | + |
| 67 | + if [[ ${CHOST} == *-darwin* ]] ; then |
| 68 | + # https://bugs.gentoo.org/898610#c17 |
| 69 | + # kill no_pie patch, it breaks things here |
| 70 | + rm "${WORKDIR}"/patch/09_all_nopie-all-flags.patch || die |
| 71 | + # fails on Darwin's sources |
| 72 | + rm "${WORKDIR}"/patch/8[12]_all_*match.pd*.patch || die |
| 73 | + rm "${WORKDIR}"/patch/86_all_*seq*.patch || die |
| 74 | + rm "${WORKDIR}"/patch/87_all_*MATCHPD*.patch || die |
| 75 | + rm "${WORKDIR}"/patch/90_all_*genemit*.patch || die |
| 76 | + fi |
| 77 | + |
| 78 | + toolchain_src_prepare |
| 79 | + |
| 80 | + # make it have correct install_names on Darwin |
| 81 | + eapply -p1 "${FILESDIR}"/4.3.3/darwin-libgcc_s-installname.patch |
| 82 | + |
| 83 | + if [[ ${CHOST} == powerpc*-darwin* ]] ; then |
| 84 | + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44107 |
| 85 | + sed -i -e 's|^ifeq (/usr/lib,|ifneq (/usr/lib,|' \ |
| 86 | + libgcc/config/t-slibgcc-darwin || die |
| 87 | + fi |
| 88 | + |
| 89 | + if [[ ${CHOST} == *-solaris* ]] ; then |
| 90 | + # madvise is not available in the compatibility mode GCC uses, |
| 91 | + # posix_madvise however, is |
| 92 | + sed -i -e 's/madvise/posix_madvise/' gcc/cp/module.cc || die |
| 93 | + fi |
| 94 | + |
| 95 | + if [[ ${CHOST} == *-darwin* ]] ; then |
| 96 | + use bootstrap && eapply "${FILESDIR}"/${PN}-13-darwin14-bootstrap.patch |
| 97 | + |
| 98 | + # our ld64 is a slight bit different, so tweak expression to not |
| 99 | + # get confused and break the build |
| 100 | + sed -i -e 's/grep ld64/grep :ld64/' gcc/configure || die |
| 101 | + |
| 102 | + # rip out specific macos version min |
| 103 | + sed -i -e 's/-mmacosx-version-min=11.0//' \ |
| 104 | + libgcc/config/aarch64/t-darwin \ |
| 105 | + libgcc/config/aarch64/t-heap-trampoline \ |
| 106 | + || die |
| 107 | + fi |
| 108 | + |
| 109 | + eapply "${FILESDIR}"/${PN}-13-fix-cross-fixincludes.patch |
| 110 | + eapply_user |
| 111 | +} |
| 112 | + |
| 113 | +src_configure() { |
| 114 | + local myconf=() |
| 115 | + case ${CTARGET}:" ${USE} " in |
| 116 | + powerpc*-darwin*) |
| 117 | + # bug #381179 |
| 118 | + filter-flags "-mcpu=*" "-mtune=*" |
| 119 | + # bug #657522 |
| 120 | + # A bug in configure checks whether -no-pie works, but the |
| 121 | + # compiler doesn't pass -no-pie onto the linker if -fno-PIE |
| 122 | + # isn't passed, so the configure check always finds -no-pie |
| 123 | + # is accepted. (Likewise, when -fno-PIE is passed, the |
| 124 | + # compiler passes -no_pie onto the linker.) |
| 125 | + # Since our linker doesn't grok this, avoid above checks to |
| 126 | + # be run |
| 127 | + # NOTE: later ld64 does grok -no_pie, not -no-pie (as checked) |
| 128 | + export gcc_cv_c_no_fpie=no |
| 129 | + export gcc_cv_no_pie=no |
| 130 | + ;; |
| 131 | + *-darwin20) |
| 132 | + # use sysroot with the linker, #756160 |
| 133 | + export gcc_cv_ld_sysroot=yes |
| 134 | + ;; |
| 135 | + *-solaris*) |
| 136 | + # todo: some magic for native vs. GNU linking? |
| 137 | + myconf+=( --with-gnu-ld --with-gnu-as --enable-largefile ) |
| 138 | + # Solaris 11 defines this in its headers, but that causes a |
| 139 | + # mismatch whilst compiling, bug #657514 |
| 140 | + #export ac_cv_func_aligned_alloc=no |
| 141 | + #export ac_cv_func_memalign=no |
| 142 | + #export ac_cv_func_posix_memalign=no |
| 143 | + ;; |
| 144 | + i[34567]86-*-linux*:*" prefix "*) |
| 145 | + # to allow the linux-x86-on-amd64.patch become useful, we need |
| 146 | + # to enable multilib, even if there is just one multilib option. |
| 147 | + myconf+=( --enable-multilib ) |
| 148 | + if [[ ${CBUILD:-${CHOST}} == "${CHOST}" ]]; then |
| 149 | + # we might be on x86_64-linux, but don't do cross-compile, so |
| 150 | + # tell the host-compiler to really create 32bits (for stage1) |
| 151 | + # (real x86-linux-gcc also accept -m32). |
| 152 | + append-flags -m32 |
| 153 | + fi |
| 154 | + ;; |
| 155 | + esac |
| 156 | + |
| 157 | + if [[ ${CHOST} == *-darwin ]] ; then |
| 158 | + # GCC' Darwin fork enables support for "-stdlib=libc++" |
| 159 | + # unconditionally, and its default include path is invalid, |
| 160 | + # causing package build failures due to missing header. |
| 161 | + # But more importantly, it breaks the assumption of many build |
| 162 | + # scripts and changes their CFLAGS and linking behaviors. The |
| 163 | + # situation is tricky and needs careful considerations. |
| 164 | + # For now, just disable support for "-stdlib=libc++". |
| 165 | + myconf+=( --with-gxx-libcxx-include-dir=no ) |
| 166 | + fi |
| 167 | + |
| 168 | + # Since GCC 4.1.2 some non-posix (?) /bin/sh compatible code is used, at |
| 169 | + # least on Solaris, and AIX /bin/sh is way too slow, |
| 170 | + # so force it to use $BASH (that portage uses) - it can't be EPREFIX |
| 171 | + # in case that doesn't exist yet |
| 172 | + export CONFIG_SHELL="${CONFIG_SHELL:-${BASH}}" |
| 173 | + toolchain_src_configure "${myconf[@]}" |
| 174 | +} |
0 commit comments