name=gcc
version=14.1.0
revision=1
tarball_url="https://ftp.gnu.org/gnu/gcc/gcc-${version}/gcc-${version}.tar.xz"
tarball_blake2b="7efd6574b8bca081de6e31480ec0565c6d7fb773383e8e1fdcc17e35bba2bf44b3f4f995cdbcccd001689926e96a6563ef3d099902fe3b37ab09dcf553ab0596"
source_hostdeps="automake autoconf-2.69 libtool pkg-config"
source_imagedeps="git"
hostdeps="gcc autoconf-2.69 automake libtool pkg-config"
deps="core-libs binutils zlib gmp mpfr mpc gettext"
imagedeps="gcc"

regenerate() {
    for i in "${base_dir}"/patches/gcc-host/*; do
        patch -p1 < "$i"
    done

    autotools_recursive_regen -I"$(realpath ./config)"

    cp -pv /usr/local/share/libtool/build-aux/{config.sub,config.guess,install-sh} libiberty/
}

build() {
        CXXFLAGS_FOR_TARGET="$CFLAGS" \
        CFLAGS_FOR_TARGET="$CFLAGS" \
    autotools_configure \
        --target=${OS_TRIPLET} \
        --with-sysroot=/ \
        --with-build-sysroot=${sysroot_dir} \
        --enable-languages=c,c++,lto \
        --enable-initfini-array \
        --disable-multilib \
        --with-system-zlib \
        --enable-host-shared

    make -j${parallelism} all-gcc
}

package() {
    DESTDIR="${dest_dir}" make install-gcc

    ln -s gcc "${dest_dir}${prefix}"/bin/cc
    # Remove static libraries
    rm -rf "${dest_dir}${prefix}"/lib/*.a

    post_package_strip
}
