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

VERSION=4.2.52
PROGNAME="db4 $VERSION"
DESC="\
db4 (Berkeley database library version 4)                              \n\
                                                                       \n\
The Berkeley Database (Berkeley DB) library provides embedded database \n\
support for both traditional and client/server applications.           \n\
                                                                       \n\
This package should be installed if compatibility is needed with       \n\
databases created with the Berkeley DB version 4."

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

compile() {
   tar -yxvf $CWD/db-$VERSION.tar.bz2
   cd db-$VERSION/
   zcat $CWD/patch.4.2.52.1.gz | patch -p0 --verbose
   zcat $CWD/patch.4.2.52.2.gz | patch -p0 --verbose
   chown -R root.root .
   find . -perm 664 -exec chmod 644 {} \;
   find . -perm 600 -exec chmod 644 {} \;
   find . -perm 444 -exec chmod 644 {} \;
   find . -perm 400 -exec chmod 644 {} \;
   find . -perm 440 -exec chmod 644 {} \;
   find . -perm 777 -exec chmod 755 {} \;
   find . -perm 775 -exec chmod 755 {} \;
   find . -perm 511 -exec chmod 755 {} \;
   find . -perm 711 -exec chmod 755 {} \;
   find . -perm 555 -exec chmod 755 {} \;
   mkdir build-dir
   cd build-dir
   CFLAGS=-O2 \
   CXXFLAGS=-O2 \
   ../dist/configure --prefix=/usr \
               --enable-compat185 \
               --enable-shared \
               --enable-rpc \
               --enable-compat185 \
               --build=s390-slackware-linux \
               --host=s390-slackware-linux \
               --target=s390-slackware-linux
   make
}

install() {
   cd $TMP/db-$VERSION/build-dir/
   make install DESTDIR=/package-db4

   # Remove WAY TOO LARGE (and misplaced) docs:
   rm -rf /package-db4/usr/docs
   mkdir -p /package-db4/usr/doc/db-$VERSION
   cp -a ../LICENSE ../README \
      /package-db4/usr/doc/db-$VERSION
   cat << EOF > /package-db4/usr/doc/db-$VERSION/README-DOCS

  For a ton of additional documentation (too large to include
  here) on writing source code that uses libdb4, please see
  the source tarball db-$VERSION.tar.bz2, which can be found
  in the Slackware source tree in source/l/db4/, or on
  Sleepycat's web site:  http://www.sleepycat.com.

EOF

   # Put libdb-4.2.so into /lib since it might be needed
   # before /usr is mounted (eg, nssswitch.conf requires it)
   mkdir /package-db4/lib
   mv /package-db4/usr/lib/libdb-4.2.so /package-db4/lib/
   ( cd /package-db4/usr/lib
     ln -sf /lib/libdb-4.2.so .
     ln -sf libdb-4.so libdb4.so
   )

   ( cd /package-db4/usr/lib
     rm libdb.so libdb.a
     rm -rf libdb-4.a ; ln -sf libdb-4.2.a libdb-4.a
     rm -rf libdb4.a  ; ln -sf libdb-4.a libdb4.a
  )

   ( cd /package-db4/usr/bin
     mv berkeley_db_svc berkeley_db4_svc
     for file in db_* ; do
       mv $file db4_`echo $file | cut -f 2- -d _`
     done
   )

   ( cd /package-db4/usr/include
     mkdir db4
     mv *.h db4/
     # If/when this becomes the default DB, do these as well
#    ln -sf db4/db.h .
#    ln -sf db4/db_185.h .
#    ln -sf db4/db_cxx.h .
   )
}

attributes() {
   chown -R root.bin $PKG/package-db4/usr/bin
   chmod 755 $PKG/package-db4/usr/bin/*
   chmod 644 $PKG/package-db4/usr/include/db4/*
}

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

   cd $CTL
   cat $CWD/slack-desc > slack-desc
   sed -e 's%package-db4/%%g' doinst.sh > doinst.sh.new
   cat doinst.sh.new > doinst.sh
   rm doinst.sh.new
}

