#!/bin/sh
# Build RPM (of all things) for Slackware.
CWD=`pwd`
cd /tmp
tar xzvf $CWD/rpm-3.0.2.tar.gz
cd rpm-3.0.2
# Install the docs before mangling them with our filters:
mkdir -p /usr/doc/rpm-3.0.2
cp -a ABOUT-NLS CHANGES COPYING CREDITS GROUPS INSTALL README \
  README.amiga RPM-PGP-KEY TODO docs/* /usr/doc/rpm-3.0.2
chown root.root /usr/doc/rpm-3.0.2/*
chmod 644 /usr/doc/rpm-3.0.2/*
# Change the /usr/src/redhat path to /usr/src/rpm.  This ain't redhat.
find . -name "*.orig" | xargs rm --verbose
for file in `find . -type f` ; do
  echo "Filtering /src/redhat path in $file..."
  cp -a $file $file.orig
  cat $file.orig | sed "/\/src\/redhat/s//\/src\/rpm/" > $file
done
for file in `find . -type f` ; do
  echo "Filtering {_usrsrc}/redhat path in $file..."
  cp -a $file $file.orig
  cat $file.orig | sed "/{_usrsrc}\/redhat/s//{_usrsrc}\/rpm/" > $file
done
find . -name "*.orig" | xargs rm --verbose
./configure --prefix=/usr i386-slackware-linux
make CFLAGS="-O2 -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wno-char-subscripts"
make CFLAGS="-O2 -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wno-char-subscripts" install
gzip -9 --force /usr/man/man3/popt.3 \
  /usr/man/man8/rpm.8 \
  /usr/man/man8/rpm2cpio.8
strip /bin/rpm /usr/bin/rpm2cpio
( cd /usr/lib/rpm
  if diff rpmgettext rpmputtext ; then
    ln -sf rpmgettext rpmputtext
  fi
  strip rpmgettext rpmputtext
)