#!/bin/sh
## build glibc-crypt-2.x package (descrypt.tgz) for Slackware
## by Patrick J. Volkerding <volkerdi@slackware.com>
CWD=`pwd`

# Figure out the name of the crypt library tarball.  You'll have to
# supply this yourself somehow.
if [ -r /tmp/glibc-crypt-2*.tar.gz ]; then
  CRYPTLIB=/tmp/glibc-crypt-2*.tar.gz
elif [ -r /root/glibc-crypt-2*.tar.gz ]; then
  CRYPTLIB=/root/glibc-crypt-2*.tar.gz
elif [ -r $CWD/glibc-crypt-2*.tar.gz ]; then
  CRYPTLIB=$CWD/glibc-crypt-2*.tar.gz
else
  cat << EOF
Before you can build the descrypt.tgz glibc-crypt package, you must locate
a suitable version of the glibc-crypt-2.*.tar.gz source archive, and put it
in /tmp, /root, or this directory.
EOF
  exit
fi

cd /tmp
tar xzvf $CWD/glibc-2.1.3.tar.gz
cd glibc-2.1.3
tar xzvf $CWD/glibc-linuxthreads-2.1.3.tar.gz

## configure for glibc2 with DES crypt(), if you have glibc-crypt-2.x.tar.gz.
## To use this, drop glibc-crypt-2.x.tar.gz into the current directory,
## uncomment these lines, comment out the lines above to build the library
## without DES crypt(), and rebuild the library with 'sh COMPILE'.
##
## If you can find a glibc-crypt based /usr/include/crypt.h and
## /lib/libcrypt-2.*.so you can simply copy them to your /lib and
## /usr/include, and then things linked with the standard (MD5) crypt()
## that comes with glibc2 will be able to use either MD5 or DES.

tar xzvf $CRYPTLIB

PKG=/tmp/package-descrypt
rm -rf $PKG
mkdir -p $PKG
mkdir -p $PKG/usr/doc/`basename $CRYPTLIB .tar.gz`
( cd crypt
  cp -a Banner COPYING.LIB ChangeLog README README.ufc-crypt \
     crypt.texi examples $PKG/usr/doc/`basename $CRYPTLIB .tar.gz` )
chown -R root.root $PKG/usr/doc/`basename $CRYPTLIB .tar.gz`

./configure --prefix=/usr \
            --enable-add-ons=linuxthreads,crypt \
            --without-cvs \
            i386-slackware-linux
make
mkdir -p $PKG/usr/include/gnu
cp -a /usr/include/gnu/stubs.h $PKG/usr/include/gnu
# This removes des_crypt from the fake function list in gnu/stubs.h:
( cd $PKG/usr/include/gnu ; zcat $CWD/stubs.h.glibc-crypt.diff.gz | patch -p0 )
cp -a crypt/sysdeps/unix/crypt.h $PKG/usr/include/crypt.h
mkdir -p $PKG/lib $PKG/usr/lib
cp -a md5-crypt/libcrypt.so $PKG/lib/libcrypt-2.1.3.so
cp -a md5-crypt/libcrypt.a $PKG/usr/lib/libcrypt.a
cp -a md5-crypt/libcrypt_p.a $PKG/usr/lib/libcrypt_p.a
chown -R root.root $PKG
chmod 755 $PKG/lib/libcrypt-2.1.3.so
chmod 644 $PKG/usr/lib/libcrypt.a $PKG/usr/lib/libcrypt_p.a
( cd $PKG/lib ; ldconfig . )
( cd $PKG/usr/lib ; ln -sf ../../lib/libcrypt.so.1 libcrypt.so )

# Build the package:

cd $PKG

echo "y
n" | makepkg /tmp/descrypt.tgz