#!/bin/sh
# Build RPM (of all things) for Slackware.
CWD=`pwd`
cd /tmp
tar xzvf $CWD/rpm-4.0.2.tar.gz
cd rpm-4.0.2
zcat $CWD/rpm-4.0.2.diff.gz | patch -p1
# Install the docs before mangling them with our filters:
mkdir -p /usr/doc/rpm-4.0.2
cp -a ABOUT-NLS CHANGES COPYING CREDITS GROUPS INSTALL README \
  README.amiga RPM-GPG-KEY RPM-PGP-KEY TODO /usr/doc/rpm-4.0.2
cp -a doc/manual /usr/doc/rpm-4.0.2
chown -R root.root /usr/doc/rpm-4.0.2
find /usr/doc/rpm-4.0.2 -type d | xargs chmod 755
find /usr/doc/rpm-4.0.2 -type f | xargs chmod 644
# 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
# Using "rpm" for the vendor name cures the /usr/src bug.
./configure --prefix=/usr i386-rpm-linux
make CFLAGS="-O2 -D_GNU_SOURCE -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wno-char-subscripts"
make 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
mkdir -p /var/lib/rpm/tmp
cat $CWD/Packages > /var/lib/rpm/tmp/Packages
mkdir -p /install
cat $CWD/doinst.sh > /install/doinst.sh
cat $CWD/slack-desc > /install/slack-desc
