IGNOREPATH=/etc:/home:/dev:/boot:/root:/tmp:/usr/local:/sbin:/mnt:/usr/src:/var
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.2.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/
   chown -R root.root .
   find . -type d | xargs chmod 755
   find . -type f -perm 664 | xargs chmod 644

   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="" \
               --build=s390-rpm-linux \
               --host=s390-rpm-linux \
               --target=s390-rpm-linux
   # Use -i since debugedit won't compile without a lot more cruft, and we don't need it anyway.
   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
   )

   # Filter all .la files (thanks much to Mark Post for the sed script):
   ( cd /package-rpm
     for file in `find . -type f -name "*.la"` ; do
       cat $file | sed -e 's%-L/tmp/[[:graph:]]*%%g' > $TMP/tmp-la-file
       cat $TMP/tmp-la-file > $file
     done
     rm $TMP/tmp-la-file
   )

   ( cd /package-rpm/usr/lib/rpm
     rm -rf rpmpopt ; ln -sf rpmpopt-$VERSION rpmpopt
   )

   # I don't know why Pat doesn't need this symbolic link, but when I don't
   # have it, the rpm command complains.
   ( cd /package-rpm/usr/lib/
     rm -rf librpmio.so.0
     ln -s librpmio.so librpmio.so.0
   )

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

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

   rmdir /package-rpm/var/tmp \
         /package-rpm/usr/man/man3
}

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
}

