IGNOREPATH=/etc:/home:/dev:/boot:/root:/tmp:/usr/local:/sbin:/mnt:/usr/src
STRIPLIB=y
STRIPBIN=y

VERSION=4.2.1
PROGNAME="rpm $VERSION"
DESC="\
rpm                                                                 \n\
                                                                    \n\
RPM is a tool from Red Hat Software used to install and remove      \n\
packages in the .rpm format.  When installing RPM packages on       \n\
Slackware, you may need to use the --nodeps and --force options.    \n\
Before installing any binary package, it's wise to examine it to    \n\
see what it's going to do, and if it will overwrite any files.  You \n\
can use rpm2tgz to convert .rpm packages to .tgz packages so you    \n\
can look them over."

BUILD=1
MAINTAINER="Mark Post <mark.post@eds.com>"
SOURCE=ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.0.x/
PKGNAME=rpm-$VERSION-s390-$BUILD
TAG=OPT

compile() {
echo This package seems to have problems when either automake or autoconf are
echo installed. This may get fixed in the future, but be prepared to removepkg them
echo if problems still occur. The autoconf problem manifested itself as a gcc parse
echo error in popt/config.h.
#sleep 5
echo Ready?
#sleep 2
echo Here we go!
#sleep 1
   tar -yxvf $CWD/rpm-$VERSION.tar.bz2
   cd rpm-$VERSION/

   if [ ! -d $TMP/saved ]; then
     mkdir $TMP/saved
     cp -a ABOUT-NLS COPYING CREDITS GROUPS INSTALL README \
           README.amiga RPM-GPG-KEY RPM-PGP-KEY TODO doc/manual $TMP/saved
     rm -f $TMP/saved/manual/Makefile*
   fi

   # 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 \
               --with-pic \
               --without-python \
               --without-apidocs \
               --without-dmalloc \
               --without-efence \
               --program-prefix="" \
               --program-suffix="" \
               s390-rpm-linux
#  cat $CWD/makefile1.diff $CWD/makefile2.diff | patch -p0

   make -i
}

install() {
   cd $TMP/rpm-$VERSION/
   make -i install DESTDIR=/package-rpm

   mkdir -p /package-rpm/usr/doc/rpm-$VERSION
   cp -a $TMP/saved/* /package-rpm/usr/doc/rpm-$VERSION

   ( cd /package-rpm/usr/man
     for suffix in 1 3 8 ;do
        for dir in `find . -type d -name man$suffix`; do
          (cd $dir
           rm -f *.gz
           gzip -9 *.$suffix 2> /dev/null
          )
        done
     done
   )

   mkdir -p /package-rpm/var/lib/rpm/tmp/
   zcat $CWD/Packages.gz > /package-rpm/var/lib/rpm/tmp/Packages

   ( cd /package-rpm/usr/lib/
     rm librpm.a librpmbuild.a librpmdb.a librpmio.a
   )

   rm -f /package-rpm/usr/include/popt.h \
         /package-rpm/usr/man/man3/popt.3.gz \
         /package-rpm/usr/lib/libpopt.* \
         /package-rpm/usr/share/locale/*/LC_MESSAGES/popt.mo

   rmdir /package-rpm/var/tmp
}

attributes() {
   chown -R root.bin $PKG/package-rpm/bin \
                     $PKG/package-rpm/usr/bin/
}

special() {
   cd $PKG
   mv package-rpm/* ./
   rmdir package-rpm

   cd $CTL
   cat $CWD/slack-desc > slack-desc

   cat <<EOF >> doinst.sh
if [ ! -r var/lib/rpm/Packages ]; then
  ( cd var/lib/rpm/tmp ; cp -a * .. )
fi
( cd var/lib/rpm && rm -f tmp/* && rmdir tmp )
EOF

   sed -e 's%package-rpm/%%g' doinst.sh > doinst.sh.new
   cat doinst.sh.new > doinst.sh
   rm doinst.sh.new
}

