default_pre_build  &&

#
# Set GLIBC_HEADERS_DIR for use later
#
persistent_add  GLIBC_HEADERS_DIR                                        &&
GLIBC_HEADERS_DIR=$SOURCE_DIRECTORY/linux-libc-headers-$HEADERS_VERSION  &&

#
# Set GLIBC_LIBIDN_DIR for use later; the variable was needlessly persistent
#
persistent_remove  GLIBC_LIBIDN_DIR                                      &&
local GLIBC_LIBIDN_DIR=$SOURCE_DIRECTORY/glibc-libidn-$VERSION           &&

if  [  "$GLIBC_NPTL"  =  "y"  ];  then
  cd      $SOURCE_DIRECTORY                           &&
  # fix for upstream bug http://sourceware.org/bugzilla/show_bug.cgi?id=2429
  patch  -p1  <  $SCRIPT_DIRECTORY/nisplus_fix.diff                      &&
  # fix for upstream bug https://bugzilla.samba.org/show_bug.cgi?id=3678
  patch  -p1  <  $SCRIPT_DIRECTORY/glibc-2.4-iconv_open.patch            &&

  if [ "$GLIBC_USEIDN" = "y" ]; then
    #
    # Unpack glibc-libidn
    #
    unpack_file 4                         &&
    mv $GLIBC_LIBIDN_DIR libidn
  fi &&

  #
  # Unpack glibc-kernel-headers
  #
  unpack_file 3                         &&
  cd  $GLIBC_HEADERS_DIR                              &&
  patch  -p1  <  $SCRIPT_DIRECTORY/config.h.patch     &&
  cd  $GLIBC_HEADERS_DIR/include                      &&
  # fix the agpgart.h header, this is needed for at least xorg 6.9.0
  sedit  '53i#include <asm/types.h>'  linux/agpgart.h &&
  chmod  -R  +r  *                                    &&
  find  .  -type  d  -exec  chmod  +x  '{}'  ';'
else
  cd      $SOURCE_DIRECTORY                         &&
  #
  # Now unpack the rest of glibc fixes in the normal location
  #
  unpack_file 3                       &&
  #
  # Unpack glibc-kernel-headers
  #
  mkdir  -p  $GLIBC_HEADERS_DIR/include             &&
  cd  $GLIBC_HEADERS_DIR/include                    &&
  unpack_file 5
fi  &&

#
# Now fixup the normal glibc
#
cd  $SOURCE_DIRECTORY                               &&
patch  -p1  <  $SCRIPT_DIRECTORY/glibcshared.patch  &&
patch  -p0  <  $SCRIPT_DIRECTORY/Makefile.patch     &&

# disabled libgd detection/building memusagestat for now until a better
# fix has been found, bug #8277
sedit  's/LIBGD=yes/LIBGD=no/'  $SOURCE_DIRECTORY/configure  &&

#
# Create the build directory
#
mk_source_dir  $SOURCE_DIRECTORY.bld &&

# fix #11832 - linking in /tmp doesn't work with grsecurity so do it elsewhere
local test_path=$SOURCE_DIRECTORY.bld/test-installation &&
mkdir $test_path &&
sed -i "s,/tmp,$test_path,g" scripts/test-installation.pl

