# $Id$ PNAME="glibc" PVER="2.16.0" PBUILD="r1" SPLIT_PACKAGES="glibc glibc-dev" PCAT="sys-libs" GLIBC_DEPEND=">= sys-apps/base-files-0.1" # we force headers to one specific version # (for x86_64 2.6.12.0-r2 bi-arch headers are needed!) SDEPEND="== sys-kernel/linux-libc-headers-3.4.4 ${GLIBC_DEPEND}" # 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 cleanutils alx 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.15-fix-res_query-assert.patch mirror://${PNAME}/${PNAME}-2.15-revert-c5a0802a.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 msetfeature "!strip" # gcc 3.0 - 3.3 needs this: export CFLAGS="${CFLAGS} -finline-limit=2000" export CXXFLAGS="${CFLAGS}" export LDFLAGS="${LDFLAGS//-Wl,--relax}" # 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=2.6.32 split_info_glibc() { DESCRIPTION="GNU libc6 (also called glibc2) C library with NPTL Threads." DEPEND="${GLIBC_DEPEND}" PROVIDE="virtual/glibc" } split_info_glibc-dev() { DESCRIPTION="Development files for sys-libs/glibc-${PVER}." DEPEND="== sys-libs/glibc-${PVER}" } src_prepare() { munpack ${SRCFILE} || die cd ${SRCDIR} # fix res_query assertion # http://sourceware.org/bugzilla/show_bug.cgi?id=13013 mpatch ${PNAME}-2.15-fix-res_query-assert.patch || die # revert commit c5a0802a - causes various hangs # https://bugzilla.redhat.com/show_bug.cgi?id=769421 # Note: fedora may have actual fix (not submitted upstream yet...) # http://pkgs.fedoraproject.org/gitweb/?p=glibc.git;a=blob_plain;f=glibc-rh552960-2.patch mpatch ${PNAME}-2.15-revert-c5a0802a.patch || 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" # disable profiling myopts+=" --disable-profile" # enable addons myopts+=" --enable-add-ons=nptl,libidn" # enable tls myopts+=" --with-tls --with-__thread" # 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 obsolete rpc implementation myopts+=" --enable-obsolete-rpc" # 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 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 if [[ ${ARCH} = x86_64 ]]; then # make sure the -m64 libs goes really to /lib64 echo "slibdir=/$(mlibdir)" >> ${SRCDIR}/build/configparms || die fi # kernel-2.6 with nptl needs this ../configure \ --build=${CHOST} \ --host=${CHOST} \ --libdir=/usr/$(mlibdir) \ --libexecdir=/usr/$(mlibdir)/glibc \ ${myopts} \ || die make PARALLELMFLAGS="${MAKEOPTS}" || die } src_install_glibc() { if [[ ${ARCH} = x86_64 ]] then # install -m32 libs cd ${SRCDIR}/build-m32 make PARALLELMFLAGS="${MAKEOPTS}" install_root=${BINDIR} slibdir=/usr/lib rootsbindir=/usr/sbin install || die fi cd ${SRCDIR}/build make PARALLELMFLAGS="${MAKEOPTS}" install_root=${BINDIR} slibdir=/usr/$(mlibdir) rootsbindir=/usr/sbin install || die # cleanup zapmost ${BINDIR} usr/$(mlibdir)/*.so \ usr/$(mlibdir)/*.so.* \ $([[ ${ARCH} = x86_64 ]] && echo 'usr/lib/*.so usr/lib/*.so.*') \ usr/sbin/ldconfig \ usr/bin/iconv \ usr/bin/locale \ usr/$(mlibdir)/gconv/IBM850.so \ usr/$(mlibdir)/gconv/ISO8859-1.so \ usr/$(mlibdir)/gconv/ISO8859-15.so \ usr/$(mlibdir)/gconv/UNICODE.so \ usr/$(mlibdir)/gconv/gconv-modules \ $([[ ${ARCH} = x86_64 ]] && echo 'usr/lib/gconv/IBM850.so') \ $([[ ${ARCH} = x86_64 ]] && echo 'usr/lib/gconv/ISO8859-1.so') \ $([[ ${ARCH} = x86_64 ]] && echo 'usr/lib/gconv/ISO8859-15.so') \ $([[ ${ARCH} = x86_64 ]] && echo 'usr/lib/gconv/UNICODE.so') \ $([[ ${ARCH} = x86_64 ]] && echo 'usr/lib/gconv/gconv-modules') \ || die # nsswitch configuration file minstalletc ${SRCDIR}/nss/nsswitch.conf || 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} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded || die # strip all libraries # want to be safe here; --strip-unneeded seems to cause pthread problems # strip all but libpthread install -d ${BUILDDIR}/thread-backup || die mv ${BINDIR}/usr/$(mlibdir)/lib{pthread,thread_db}* ${BUILDDIR}/thread-backup/ || die # now strip find ${BINDIR} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded || die mv -f ${BUILDDIR}/thread-backup/* ${BINDIR}/usr/$(mlibdir)/ || die # 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 } src_install_glibc-dev() { if [[ ${ARCH} = x86_64 ]] then # install -m32 libs cd ${SRCDIR}/build-m32 make PARALLELMFLAGS="${MAKEOPTS}" install_root=${BINDIR} slibdir=/usr/lib rootsbindir=/usr/sbin install || die fi cd ${SRCDIR}/build make PARALLELMFLAGS="${MAKEOPTS}" install_root=${BINDIR} slibdir=/usr/$(mlibdir) rootsbindir=/usr/sbin install || die # cleanup -> in glibc rm -r ${BINDIR}/usr/$(mlibdir)/*.so || die rm ${BINDIR}/usr/$(mlibdir)/*.so.* || die rm ${BINDIR}/usr/$(mlibdir)/gconv/IBM850.so || die rm ${BINDIR}/usr/$(mlibdir)/gconv/ISO8859-1.so || die rm ${BINDIR}/usr/$(mlibdir)/gconv/ISO8859-15.so || die rm ${BINDIR}/usr/$(mlibdir)/gconv/UNICODE.so || die rm ${BINDIR}/usr/$(mlibdir)/gconv/gconv-modules || die if [[ ${ARCH} = x86_64 ]] then rm -r ${BINDIR}/usr/lib/*.so || die rm ${BINDIR}/usr/lib/*.so.* || die rm ${BINDIR}/usr/lib/gconv/IBM850.so || die rm ${BINDIR}/usr/lib/gconv/ISO8859-1.so || die rm ${BINDIR}/usr/lib/gconv/ISO8859-15.so || die rm ${BINDIR}/usr/lib/gconv/UNICODE.so || die rm ${BINDIR}/usr/lib/gconv/gconv-modules || die fi rm ${BINDIR}/usr/sbin/ldconfig || die rm ${BINDIR}/usr/bin/iconv || die rm ${BINDIR}/usr/bin/locale || 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 # nscd configuration file minstalletc ${SRCDIR}/nscd/nscd.conf || die # gai configuration file minstalletc ${SRCDIR}/posix/gai.conf || die # busybox compat local args if [[ $(readlink /bin/cp) = */busybox ]] then args="-f" else args="--remove-destination" fi # we use Berlin as default 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; } # strip all binaries find ${BINDIR} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded || die # strip all libraries find ${BINDIR} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded || 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 /$(mlibdir)/incoming from db-entry '${i}' ..." # /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:/$(mlibdir)/incoming:/$(mlibdir):g" \ -e "s:/$(mlibdir)/incoming.*::g" \ -e '/^$/d' ${DB_ENTRY}/${i} done } preinstall_glibc() { add_conf_prot_mask /etc/env.d /etc/nsswitch.conf } postinstall_glibc() { # 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 /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: /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) /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 # now we must fix the mage db files # to stop the annoying errors messages fix_db_files } postinstall_glibc-dev() { 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 [[ $(basename $(readlink /sbin/init)) != busybox ]] then # reloading init echo " Reloading init ..." [[ -z ${MROOT} ]] && /sbin/init U &> /dev/null fi # generating user def locales echo " Generating user defined locales ..." [[ -z ${MROOT} ]] && /usr/sbin/locale-gen }