# $Id$ PNAME="glibc" PVER="2.29" PBUILD="r12" PCAT="sys-libs" DESCRIPTION="GNU libc6 (also called glibc2) C library with NPTL Threads." HOMEPAGE="http://www.gnu.org/software/libc/libc.html" DEPEND=">= sys-apps/base-files-0.7 >= sys-libs/tzdata-2018" # we force headers to one specific version SDEPEND="== sys-kernel/linux-libc-headers-5.0.11" PROVIDE="virtual/glibc" # functions to include in the mage file SPECIAL_FUNCTIONS="fix_db_files" SRCFILE="glibc-${PVER}.tar.xz" SRCDIR="${BUILDDIR}/glibc-${PVER}" ENVD_REV="1.2" sminclude mtools SRC_URI=( ftp://sources.redhat.com/pub/glibc/releases/${SRCFILE} ftp://sources.redhat.com/pub/glibc/snapshots/${SRCFILE} gnu://${PNAME}/${SRCFILE} mirror://${PNAME}/${SRCFILE} mirror://${PNAME}/glibc.envd-${ENVD_REV} mirror://${PNAME}/locale.gen-header mirror://${PNAME}/locale-gen mirror://${PNAME}/${PNAME}-2.17-syscalld-infinite-loop.patch ) # sed line: on 2 digits add an zero: 2.7 -> 2.7.0 UP2DATE="updatecmd_gnu ${PNAME/-nptl/} | sed 's/^\([0-9]\.[0-9]\$\)/\1.0/'" # glibc don't like strong CFLAGS #export CFLAGS="${CFLAGS//-O?} -O2" # glibc -> nptl thread don't like striping # keep static libs to honor -static-pie or nptl/pthreads segfault may occur msetfeature "!strip static" # hack to fix NPTL issues with xen, only required on 32bit arches if [[ ${ARCH} = i*86 ]] then export CFLAGS="${CFLAGS} -mno-tls-direct-seg-refs" fi ## glibc-2.6.1 and above needs march CFLAGS: -march=${ARCH} -mtune=generic ## first filter -mtune and -march from flags #for flag in ${CFLAGS} #do # case ${flag} in # -mtune=*) continue ;; # -march=*) continue ;; # esac # newflags="${newflags} ${flag}" #done #export CFLAGS="${newflags}" # ## than add our defaults for glibc #[[ ${ARCH} = i*86 ]] && export CFLAGS="${CFLAGS} -march=${ARCH}" # only i*86 #export CFLAGS="${CFLAGS} -mtune=generic" # all arches #export CXXFLAGS="${CFLAGS}" # use other linux-headers [[ -z ${ALT_HEADERS} ]] && export ALT_HEADERS="/usr/include" # kernel support export ENABLE_KERNEL=3.2.0 src_prepare() { munpack ${SRCFILE} || die cd ${SRCDIR} # fix a test case that fails when built using gcc-5.x sed -i '/tst-audit2-ENV/i CFLAGS-tst-audit2.c += -fno-builtin' elf/Makefile || die # fixes an infinite loop while syscall.d creation # see: http://sourceware.org/bugzilla/show_bug.cgi?id=15711 mpatch ${PNAME}-2.17-syscalld-infinite-loop.patch || die # use 1.0 second instead of 0.5 (required by arch i686 builds on 64bit machines) sed -i 's:0.5 seconds ago:1.0 seconds ago:' ${SRCDIR}/Makerules || die # scripts/test-installation.pl sometime fails # # CC="gcc" /usr/bin/perl scripts/test-installation.pl # /usr/src/glibc-2.16.0.bld/ # Unmatched ( in regex; marked by <-- HERE in m/$( <-- HERE if $(abi-32-ld-soname),$(abi-32-ld-soname),ld/ at scripts/test-installation.pl line 172, # line 1 sed -i 's:CC="$(CC)" $(PERL) scripts/test-installation.pl $(common-objpfx)::' Makefile || die # binutils patch needs reconf # autoconf --force || die # fix permissions on some of the scripts chmod u+x ${SRCDIR}/scripts/*.sh || die install -d ${SRCDIR}/build || die cd ${SRCDIR}/build if [ ! -f /etc/ld.so.conf ] then touch /etc/ld.so.conf || die fi } src_compile() { local myopts # generic pathes myopts="--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info" myopts+=" --with-headers=/usr/include" # bugurl myopts+=" --with-bugurl=http://bugs.magellan-linux.de/" # disable profiling myopts+=" --disable-profile" # enable addons myopts+=" --enable-add-ons" # supported kernel-release myopts+=" --enable-kernel=${ENABLE_KERNEL}" # disable cvs and gd support myopts+=" --without-cvs --without-gd" # enable bindnow myopts+=" --enable-bind-now" # enable lock elision myopts+=" --enable-lock-elision" # disable -werror myopts+=" --disable-werror" # enable multi-arch myopts+=" --enable-multi-arch" # enable stackguard randomization myopts+=" --enable-stackguard-randomization" # enable stack protector myopts+=" --enable-stack-protector=strong" # enable static pie myopts+=" --enable-static-pie" # enable intel cet + branch tracking (IBT) and shadow stack (SHSTK) myopts+=" --enable-cet" # fortify_source not supported export CPPFLAGS=${CPPFLAGS/-D_FORTIFY_SOURCE=2/} # support multilib lib64 dir (x86_64 only) if [[ ${ARCH} = x86_64 ]] then # first build a -m32 version install -d ${SRCDIR}/build-m32 cd ${SRCDIR}/build-m32 # honor /usr move echo "rootsbindir=/usr/sbin" >> ${SRCDIR}/build-m32/configparms || die # make sure the -m32 libs goes really to /usr/lib echo "slibdir=/usr/lib" >> ${SRCDIR}/build-m32/configparms || die echo "rtlddir=/usr/lib" >> ${SRCDIR}/build-m32/configparms || die CC="gcc -m32" CXX="g++ -m32" \ CFLAGS="${CFLAGS//-march=${ARCH}} -march=i686" \ CXXFLAGS="${CXXFLAGS//-march=${ARCH}} -march=i686" \ ../configure \ --build=${CHOST} \ --host=i686-pc-linux-gnu \ --libdir=/usr/lib \ --libexecdir=/usr/lib/glibc \ ${myopts} \ || die make PARALLELMFLAGS="${MAKEOPTS}" || die fi cd ${SRCDIR}/build # honor /usr move echo "rootsbindir=/usr/sbin" >> ${SRCDIR}/build/configparms || die # make sure the -m64 libs goes really to /lib64 echo "slibdir=/usr/$(mlibdir)" >> ${SRCDIR}/build/configparms || die echo "rtlddir=/usr/$(mlibdir)" >> ${SRCDIR}/build/configparms || die ../configure \ --build=${CHOST} \ --host=${CHOST} \ --libdir=/usr/$(mlibdir) \ --libexecdir=/usr/$(mlibdir)/glibc \ ${myopts} \ || die make PARALLELMFLAGS="${MAKEOPTS}" || die } src_install() { if [[ ${ARCH} = x86_64 ]] then # install -m32 libs cd ${SRCDIR}/build-m32 make PARALLELMFLAGS="${MAKEOPTS}" install_root=${BINDIR} install || die fi cd ${SRCDIR}/build make PARALLELMFLAGS="${MAKEOPTS}" install_root=${BINDIR} install || die # do not generate the locales here, let it the user do with the locale-gen tool # make PARALLELMFLAGS="${MAKEOPTS}" install_root=${BINDIR} localedata/install-locales || die # install locales list and generate tools # generate locale.gen file from localedata/SUPPORTED file minstalletc locale.gen-header locale.gen || die sed \ -e 's:/: :g' \ -e 's:\\: :g' \ -e 's:SUPPORTED-LOCALES=::' \ -e 's:\ \ $::g' \ -e '/^#/d' \ -e 's:^:#:g' \ ${SRCDIR}/localedata/SUPPORTED \ >> ${BINDIR}/etc/locale.gen || die minstalldir /usr/sbin || die minstallexec -s locale-gen /usr/sbin || die # nsswitch configuration file minstalletc ${SRCDIR}/nss/nsswitch.conf || die # nscd configuration file minstalletc ${SRCDIR}/nscd/nscd.conf || die # systemd services, but do not include systemd.sminc to have a hard depend on systemd minstalldir /usr/lib/systemd/system || die minstallfile ${SRCDIR}/nscd/nscd.service /usr/lib/systemd/system || die minstalldir /etc/tmpfiles.d || die minstallfile ${SRCDIR}/nscd/nscd.tmpfiles /etc/tmpfiles.d/nscd.conf || die # gai configuration file minstalletc ${SRCDIR}/posix/gai.conf || die # now in tzdata ## we use Berlin as default ## busybox compat #local args #if need_busybox_support /bin/cp #then # args="-f" #else # args="--remove-destination" #fi #cp ${args} ${BINDIR}/usr/share/zoneinfo/Europe/Berlin ${BINDIR}/etc/localtime || die [ -f ${BINDIR}/etc/ld.so.conf ] && { rm -f ${BINDIR}/etc/ld.so.conf || die; } [ -e ${BINDIR}/etc/ld.so.cache ] && { rm -rf ${BINDIR}/etc/ld.so.cache || die; } # base environment minstallenv glibc.envd-${ENVD_REV} 00glibc || die if [[ ${ARCH} = x86_64 ]] then MCONFIG="/etc/env.d/00glibc" maddconfig "LDPATH=\"/$(mlibdir)\"" || die maddconfig "LDPATH=\"/usr/$(mlibdir)\"" || die maddconfig "LDPATH=\"/usr/local/$(mlibdir)\"" || die maddconfig "LDPATH=\"/opt/$(mlibdir)\"" || die fi # strip all binaries find ${BINDIR} ! -type d | xargs --no-run-if-empty file | grep -v "pie executable" | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip --strip-unneeded || die # strip all libraries # want to be safe here; --strip-unneeded seems to cause pthread problems # strip all but libpthread, libc and ld install -d ${BUILDDIR}/thread-backup/$(mlibdir) || die mv ${BINDIR}/usr/$(mlibdir)/lib{pthread,thread_db,c-}* ${BUILDDIR}/thread-backup/$(mlibdir)/ || die mv ${BINDIR}/usr/$(mlibdir)/ld-* ${BUILDDIR}/thread-backup/$(mlibdir)/ || die if [[ ${ARCH} = x86_64 ]] then install -d ${BUILDDIR}/thread-backup/lib || die mv ${BINDIR}/usr/lib/lib{pthread,thread_db,c-}* ${BUILDDIR}/thread-backup/lib/ || die mv ${BINDIR}/usr/lib/ld-* ${BUILDDIR}/thread-backup/lib/ || die fi # now strip but only debuging symbols find ${BINDIR} ! -type d | xargs --no-run-if-empty file | grep "[shared object|pie executable]" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip --strip-debug || die find ${BINDIR} ! -type d | xargs --no-run-if-empty file | grep "ar archive" | cut -f 1 -d : | xargs --no-run-if-empty strip --strip-debug || die mv -f ${BUILDDIR}/thread-backup/$(mlibdir)/* ${BINDIR}/usr/$(mlibdir)/ || die if [[ ${ARCH} = x86_64 ]] then mv -f ${BUILDDIR}/thread-backup/lib/* ${BINDIR}/usr/lib/ || die fi # remove stale directory rm -rf ${BUILDDIR}/thread-backup || die # prepare glibc for installation; slackware method minstalldir /incoming || die mv ${BINDIR}/usr/$(mlibdir)/*.so ${BINDIR}/incoming || die mv ${BINDIR}/usr/$(mlibdir)/*.so.* ${BINDIR}/incoming || die mv ${BINDIR}/incoming ${BINDIR}/usr/$(mlibdir)/incoming || die mv ${BINDIR}/usr/$(mlibdir)/incoming/libSegFault.so ${BINDIR}/usr/$(mlibdir) || die } fix_db_files() { local i local DB_ENTRY="${BUILDDIR}/${PKGNAME}" for i in .files .symlinks .dirs do [ ! -f ${DB_ENTRY}/${i} ] && continue [[ -z $(< ${DB_ENTRY}/${i}) ]] && continue echo " fixing /usr/$(mlibdir)/incoming from db-entry '${i}' ..." # /usr/lib/incoming -> empty line; sed2 removes all empty lines #sed -i -e "s:/$(mlibdir)/incoming.*::g" -e '/^$/d' ${DB_ENTRY}/${i} # do not simply emtpy the line, but change it the the correct path, # so no stale libs are around if the package gets updated! sed -i \ -e "s:/usr/$(mlibdir)/incoming:/usr/$(mlibdir):g" \ -e "s:/usr/$(mlibdir)/incoming.*::g" \ -e '/^$/d' ${DB_ENTRY}/${i} done } postinstall() { # first save the old libpthread.so.0; # it will later used to determinate that there are no stale # libpthreads that breaks ldconfig local OLD_PTHREAD OLD_PTHREAD="$(readlink ${MROOT}/usr/$(mlibdir)/libpthread.so.0)" # slackware install method # we cannot easily install the glibc libs, # because our tools for cp etc needs them to run local file echo " Switching to new glibc ..." # swap libraries on the fly: if [ -x /usr/sbin/ldconfig -a -d /usr/$(mlibdir)/incoming ] && [[ -z ${MROOT} ]] then # first create copies of the incoming libraries: cd /usr/$(mlibdir)/incoming for file in $(find /usr/$(mlibdir)/incoming -type f) do if [ ! -r "../$(basename ${file}).incoming" ] then cp -a ${file} ../$(basename ${file}).incoming fi done # then switch to them all at once: /usr/sbin/ldconfig -l /usr/$(mlibdir)/*.incoming 2> /dev/null # finally, rename them and clean up: cd /usr/$(mlibdir) for file in *.incoming do rm -f $(basename ${file} .incoming) cp -a ${file} $(basename ${file} .incoming) /usr/sbin/ldconfig -l $(basename ${file} .incoming) rm -f ${file} done # no ldconfig? # good, it's safe to just jam it on home (and make links below): else ( cd ${MROOT}/usr/$(mlibdir)/incoming for file in * do cp -a ${file} .. done local my_sym local my_dest # rebuild symlinks echo " Recreating Symlinks:" for i in $(find ${MROOT}/usr/$(mlibdir)/incoming -type l) do my_sym="$(readlink ${i})" my_dest="$(basename ${i})" echo " ${my_dest} -> ${my_dest}" # assure to remove the old ones; [ -L ${MROOT}/usr/$(mlibdir)/"${my_dest}" ] && \ rm ${MROOT}/usr/$(mlibdir)/"${my_dest}" ln -snf "${my_sym}" ${MROOT}/usr/$(mlibdir)/"${my_dest}" done ) fi # now, get rid of the temporary directory: rm -rf ${MROOT}/usr/$(mlibdir)/incoming # remove stale nptl libpthread-2.?.?.so, # fix only needed for glibc with linuxthreads; # prevent reloc errors such as: # ls: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory # get our new libpthread.so.0 local NEW_PTHREAD NEW_PTHREAD="$(readlink ${MROOT}/usr/$(mlibdir)/libpthread.so.0)" if [ "${NEW_PTHREAD}" != "${OLD_PTHREAD}" ] then echo " Removing stale libpthread libraries ..." for file in ${MROOT}/usr/$(mlibdir)/libpthread-* do if [ "$(basename ${file})" != "${NEW_PTHREAD}" ] then rm -f ${file} fi done #rm -f /lib/${OLD_PTHREAD} ln -snf ${NEW_PTHREAD} ${MROOT}/usr/$(mlibdir)/libpthread.so.0 fi if [ -x /usr/sbin/iconvconfig ] then # generate fastloading iconv module configuration file. echo " Generate iconv module config ..." /usr/sbin/iconvconfig --prefix=${MROOT}/ fi # not working with busybox if ! need_busybox_support /sbin/telinit then # reloading init echo " Reloading init ..." [[ -z ${MROOT} ]] && /sbin/telinit U &> /dev/null fi # generating user def locales echo " Generating user defined locales ..." [[ -z ${MROOT} ]] && /usr/sbin/locale-gen # now we must fix the mage db files # to stop the annoying errors messages fix_db_files }