infodir=/usr/share/info
filelist=(libc.info libc.info-1 libc.info-2 libc.info-3 libc.info-4 libc.info-5 libc.info-6 libc.info-7 
          libc.info-8 libc.info-9 libc.info-10 libc.info-11)

pre_upgrade() {
if [ "`uname -m`" = "x86_64" ]; then
 if [ "`vercmp $2 2.4`" -lt 0 ]; then
   cat << _EOF
  ==> glibc oldpkgver < 2.4 detected!
  ==> 
  ==> ATTENTION x86_64 USERS:
  ==>
  ==> We now switch from the former lib-linking to pure /lib support. To get rid
  ==> of all lib64 directories we have removed the link /lib -> /lib64 and
  ==> /usr/lib -> /usr/lib64.
  ==> 
  ==> We have also rebuilt all packages we know that still used lib64 directories.
  ==> Now all should go to /lib directories.
  ==> 
  ==> Internally we have removed the link and then mv /lib64 /lib. Same to /usr/lib64.
  ==> /lib64 and /usr/lib64 shouldn't exist anymore. If any package still installs to
  ==> /lib64 or /usr/lib64 let us know.
  ==>
_EOF

# now the moving
rm -rf /lib/tls && echo "/lib/tls removed"
ldconfig -r .
rm -f /usr/lib
mv /usr/lib64 /usr/lib && echo "/usr/lib64 moved"
rm -f /lib
mv /lib64 /lib && echo "/lib64 moved"

 fi
fi

 [ -x usr/bin/install-info ] || return 0
 for file in ${filelist[@]}; do
    usr/bin/install-info $infodir/$file $infodir/dir 2> /dev/null
 done
}

post_upgrade() {
  ldconfig -r .
  init u

  if [ "`vercmp $2 2.3.6`" -lt 0 ]; then
    cat << _EOF
  ==> ATTENTION INTERNATIONAL USERS:
  ==>
  ==> Locales are no longer included in the glibc package.
  ==> They are generated by /usr/sbin/locale-gen depending on the contents
  ==> of /etc/locale.gen.
  ==> glibc will try to autodetect the required locales now, if you need
  ==> additional locales, please enable them in /etc/locale.gen and run
  ==> /usr/sbin/locale-gen
  ==>  
_EOF
    # Check active locales, enable the ones that are in use
    loc=("$LANG"
         "`grep '^LOCALE=' etc/rc.conf | awk -F '=' '{ print $2 }'`")
    for l in "${loc[@]}"; do
      if [ ! -z "${l}" ]; then
        line="`grep -i "^#${l}[[:space:]]" etc/locale.gen`"
        if [ ! -z "${line}" ]; then
          sed -i -e "s|${line}|${line/\#/}|" etc/locale.gen
        fi
      fi
    done
  fi

  usr/sbin/locale-gen

# fix CHOST for arch64
if [ "`uname -m`" = "x86_64" ]; then
 if [ "`vercmp $2 2.4`" -lt 0 ]; then
  sed -i s/'x86_64-pc-linux-gnu'/'x86_64-unknown-linux-gnu'/ /etc/makepkg.conf && \
  echo "in /etc/makepkg.conf CHOST has been changed to \"x86_64-unknown-linux-gnu\""

  # we remove files from glibc 2.3.6 that are not removed automatically
  rm -f /lib/ld-2.3.* && echo "removing unneeded old files"
  rm -f /lib/libBrokenLocale-2.3.*
  rm -f /lib/libNoVersion*
  rm -f /lib/libanl-2.3.*
  rm -f /lib/libc-2.3.*
  rm -f /lib/libcidn-2.3.*
  rm -f /lib/libcrypt-2.3.*
  rm -f /lib/libdl-2.3.*
  rm -f /lib/libm-2.3.*
  rm -f /lib/libnsl-2.3.*
  rm -f /lib/libnss1*
  rm -f /lib/libnss_compat-2.3.*
  rm -f /lib/libnss_dns-2.3.*
  rm -f /lib/libnss_dns.so.1
  rm -f /lib/libnss_files-2.3.*
  rm -f /lib/libnss_files.so.1
  rm -f /lib/libnss_hesiod-2.3.*
  rm -f /lib/libnss_nis-2.3.*
  rm -f /lib/libnss_nis.so.1
  rm -f /lib/libnss_nisplus-2.3.*
  rm -f /lib/libpthread-0.10.so
  rm -f /lib/libresolv-2.3.*
  rm -f /lib/librt-2.3.*
  rm -f /lib/libutil-2.3.*
  rm -fR /lib/nosegneg
  #rm -fR /usr/include/asm
  #rm -fR /usr/include/linux
  rm -fR /usr/include/ntpl
  rm -f /usr/lib/libNoVersion*
  rm -f /usr/lib/libc_stubs.a
  rm -f /usr/lib/libnss1*
  rm -f /usr/lib/libnss_compat.so.1
  rm -f /usr/lib/libnss_dns.so.1
  rm -f /usr/lib/libnss_files.so.1
  rm -f /usr/lib/libnss_nis.so.1
  rm -fR /usr/lib/nptl
  rm -f /usr/sbin/nscd_nischeck
  rm -fR /usr/share/zoneinfo/SystemV
  rm -fR /usr/share/zoneinfo/posix/SystemV
  rm -fR /usr/share/zoneinfo/right/SystemV
  ldconfig -r .
 fi
fi

 [ -x usr/bin/install-info ] || return 0
 for file in ${filelist[@]}; do
    usr/bin/install-info $infodir/$file $infodir/dir 2> /dev/null
 done
}

pre_remove() {
  [ -x usr/bin/install-info ] || return 0
  for file in ${filelist[@]}; do
    usr/bin/install-info --delete $infodir/$file $infodir/dir 2> /dev/null
  done
}