1.8. pass2-gcc-9.2.0

#!/bin/sh
# Copyright © 1999-2020 Gerard Beekmans
# Copyright © 2017-2020 Random Crew
# Distributed under the terms of MIT License.


MY_P="${P#pass2-}"
MY_PD="${MY_P}"

Additional source handling

src_postfetch()
{
    tar xf ${ANYSRCDIR}/mpfr-4.0.2.tar.xz
    mv mpfr-4.0.2 mpfr
    tar xf ${ANYSRCDIR}/gmp-6.2.0.tar.xz
    mv gmp-6.2.0 gmp
    tar xf ${ANYSRCDIR}/mpc-1.1.0.tar.gz
    mv mpc-1.1.0 mpc
}

Additional patches handling

src_postprepare()
{
    for file in gcc/config/{linux,i386/linux{,64}}.h
    do
        cp -u $file{,.orig}
        sed -e "s@/lib\(64\)\?\(32\)\?/ld@${PREFIX}&@g" \
            -e "s@/usr@${PREFIX}@g" \
            -e "s@/lib64@/lib@g" \
            $file.orig > $file
        echo "
    #undef STANDARD_STARTFILE_PREFIX_1
    #undef STANDARD_STARTFILE_PREFIX_2
    #define STANDARD_STARTFILE_PREFIX_1 \"${PREFIX}/lib/\"
    #define STANDARD_STARTFILE_PREFIX_2 \"\"" >> $file
        touch $file.orig
    done

    case $(uname -m) in
        x86_64)
            sed -e '/m64=/s/lib64/lib/' \
                -i.orig gcc/config/i386/t-linux64
        ;;
    esac
}

Configuration

As in pass1-gcc, additionally replace lib64 with lib:

    -e "s@/lib64@/lib@g" \

Pass macros HAVE_DECL_VASPRINTF to configure:

    CFLAGS="-DHAVE_DECL_VASPRINTF=1"                   \
    CXXFLAGS="-DHAVE_DECL_VASPRINTF=1"                 \

include/libiberty.h contains its own prototype of function vasprintf, which is incompatible with system prototype from glibc, located in file $PREFIX/include/stdio.h. At minimum, versions glibc-2.27 and higher are incompatible.

gcc-7 and gcc-8 ignore the incompatibility, but our self-built pass1-gcc-9 does not. That results in multiple failures during configuration tests of pass2-gcc and the further build is screwed.

The macros above turns off the usage of prototype variant from include/libiberty.h.

Why gcc-9 does not handle the situation with vasprintf itself? That't unclear.

src_config()
{
    sed -e '1161 s|^|//|' \
        -i libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc

    mkdir -v build
    cd build

    CC=${LFS_TGT}-gcc                                  \
    CXX=${LFS_TGT}-g++                                 \
    AR=${LFS_TGT}-ar                                   \
    RANLIB=${LFS_TGT}-ranlib                           \
    CFLAGS="-DHAVE_DECL_VASPRINTF=1"                   \
    CXXFLAGS="-DHAVE_DECL_VASPRINTF=1"                 \
    ../configure                                       \
        --prefix=${PREFIX}                             \
        --with-local-prefix=${PREFIX}                  \
        --with-native-system-header-dir=${PREFIX}/include \
        --enable-languages=c,c++                       \
        --disable-libstdcxx-pch                        \
        --disable-multilib                             \
        --disable-bootstrap                            \
        --disable-libgomp
}

Compilation

src_compile()
{
    make ${MAKEOPTS}
}

Installation

src_install()
{
    make install ${MAKEOPTS} DESTDIR=$D
    ln -s gcc ${D}/${PREFIX}/bin/cc
}

Links

url.lfs:
url.lfs.stage1: https://linuxfromscratch.org/lfs/view/9.1/chapter05/gcc-pass2.html