#!/bin/sh
## build glibc-2.2.3 for Slackware
## by Patrick J. Volkerding <volkerdi@slackware.com>
CWD=`pwd`
export PKG=/tmp/package-glibc

#if [ -d /usr/include/sys ]; then
#  cat << EOF
#*** WARNING:  It's a good idea to move /usr/include out of the way if
#you're planning to extract this as a binary package.  Otherwise some of
#the include files may not be replaced.
#
#Press enter to continue, or control-c to abort.
#EOF
#  read junk_input;
#fi

# Empty this first:
rm -rf $PKG
mkdir -p $PKG/lib
mkdir -p $PKG/sbin
mkdir -p $PKG/usr/bin
mkdir -p $PKG/usr/lib
mkdir -p $PKG/usr/sbin
mkdir -p $PKG/usr/include
mkdir -p $PKG/usr/doc
mkdir -p $PKG/usr/man
mkdir -p $PKG/usr/share

cd /tmp
tar xzvf $CWD/glibc-2.2.3.tar.gz
cd glibc-2.2.3
zcat $CWD/glibc-2.2.3-nss.diff.gz | patch -p0 --verbose
tar xzvf $CWD/glibc-linuxthreads-2.2.3.tar.gz

./configure --prefix=/usr \
            --enable-add-ons=linuxthreads \
            --without-cvs \
            i386-slackware-linux

make
make install install_root=$PKG
make localedata/install-locales install_root=$PKG

mkdir -p $PKG/etc
cat nscd/nscd.conf > $PKG/etc/nscd.conf-sample

# Since GNU does not provide man pages, I put some together:
mkdir -p $PKG/usr/man/man1
cat $CWD/ldd.1.gz > $PKG/usr/man/man1/ldd.1.gz
# This is now in the man-pages package.
#mkdir -p $PKG/usr/man/man1
#cat $CWD/ldconfig.8.gz > $PKG/usr/man/man1/ldconfig.8.gz

# Not a bad idea to have this here as well:
( cd $PKG ; tar xzvf $CWD/timezone-scripts.tar.gz )

## Install docs:
( mkdir -p $PKG/usr/doc/glibc-2.2.3
  cp -a BUGS CONFORMANCE COPYING COPYING.LIB FAQ INSTALL INTERFACE \
    NAMESPACE NEWS NOTES PROJECTS README README.libm $PKG/usr/doc/glibc-2.2.3
  cd linuxthreads
  mkdir -p $PKG/usr/doc/glibc-2.2.3/linuxthreads
  cp -a Banner FAQ.html LICENSE README README.Xfree3.2 linuxthreads.texi \
    Examples $PKG/usr/doc/glibc-2.2.3/linuxthreads
  cd man
  mkdir $PKG/usr/man/man3
  for file in *.man ; do
    cat $file | gzip -9c > $PKG/usr/man/man3/`basename $file .man`.3.gz
  done 
  chown -R root.root $PKG/usr/doc/glibc-2.2.3 
  find $PKG/usr/doc/glibc-2.2.3 -type d | xargs chmod 755 
  find $PKG/usr/doc/glibc-2.2.3 -type f | xargs chmod 644 )

### If you want glibc-2.2.3 installed, uncomment the lines below.
## Save the ldd from ldso.tgz:
#mv /usr/bin/ldd /usr/bin/ldd-ldso
#make install
#make localedata/install-locales
#mv /usr/bin/ldd /usr/bin/ldd-glibc
#mv /usr/bin/ldd-ldso /usr/bin/ldd


# Don't forget to add the /usr/share/zoneinfo/localtime -> /etc/localtime symlink! :)
if [ ! -r $PKG/usr/share/zoneinfo/localtime ]; then
  ( cd $PKG/usr/share/zoneinfo ; ln -sf /etc/localtime . )
fi

echo "Building Berkeley DB libraries..."
sleep 5
cd $CWD
./bsd_db.build

echo "Building nss_db-2.2..."
sleep 5
cd $CWD
./nss_db.build
