#!/bin/sh
name="glibc"
short_desc="GNU C Library"
desc="The GNU C Library (glibc) is a C library uses as the libc of most Linux distributions.
Not only does it contain a libc, it also contains locale configuration."
category="system"
version="2.38"
maintainer="ffqq@danwin1210.de"
www="https://www.gnu.org/software/libc/"
master_site="ftp://ftp.gnu.org/gnu/libc"
source_name="$name-$version.tar.gz"
license_logic="single" # accepted values: single, and, or
licenses=("GPLv3+")

build_dependencies=("lang/gcc" "lang/gawk" "lang/python3" "textproc/sed" "devel/bison" "devel/binutils" "devel/gmake")
run_dependencies=()

build_process() {
    cd $name-$version || exit 1
    patch -Np1 -i $TAMANDUA_FILES_DIR/glibc-2.38-memalign_fix-1.patch || exit 1
    patch -Np1 -i $TAMANDUA_FILES_DIR/glibc-2.38-fhs-1.patch || exit 1
    echo "rootsbindir=/usr/sbin" > configparms || exit 1
    mkdir -p build || exit 1
    cd build || exit 1
    ../configure --prefix=/usr  \
    --disable-werror            \
    --disable-nscd              \
    --enable-kernel=4.14        \
    --with-headers=/usr/include \
    --enable-stack-protector=strong \
    libc_cv_slibdir=/usr/lib || exit 1
    make -j$(nproc) || exit 1
    sed '/test-installation/s@$(PERL)@echo not running@' -i ../Makefile || exit 1
    make DESTDIR="$TAMANDUA_STAGE_DIR" install || exit 1
    sed '/RTLDLIST=/s@/usr@@g' -i $TAMANDUA_STAGE_DIR/usr/bin/ldd || exit 1
    # locale-gen
    chmod +x $TAMANDUA_FILES_DIR/locale-gen
    cp $TAMANDUA_FILES_DIR/locale-gen $TAMANDUA_STAGE_DIR/usr/bin/locale-gen
    echo "# locale-gen configuration file
#
# The locale-gen utility is a utility that will generate locales and place them
# in /usr/lib/locale.
#
# Uncomment your desired locales, and run locale-gen to generate them.
#" > $TAMANDUA_STAGE_DIR/etc/locale.gen
    sed -e '1,3d' -e 's|/| |g' -e 's|\\| |g' -e 's|^|#|g' \
        $TAMANDUA_BUILD_DIR/$name-$version/localedata/SUPPORTED >> $TAMANDUA_STAGE_DIR/etc/locale.gen
    # ld-linux
    mkdir -p $TAMANDUA_STAGE_DIR/lib64
    mkdir -p $TAMANDUA_STAGE_DIR/usr/lib/locale
    ln -sv /usr/lib/ld-linux-x86-64.so.2 $TAMANDUA_STAGE_DIR/lib64/ld-linux-x86-64.so.2
    rm -r $TAMANDUA_STAGE_DIR/usr/share/info
}