#!/bin/sh

source /home/build/armedslack-current/source/armslack-utils/armedenvs.sh
PACKAGE=grep
VERSION=2.5.1
BUILD=1
PKGSERIES=a # the name of the Slackware 'disk set' or 'series' to which this pkg belongs

PKG=${PKG}${PACKAGE}
rm -rf ${TMP}/${PACKAGE}* $PKG ; mkdir -p $PKG

cd ${TMP} # enter the temporary path into which we unarchive the goods

# Sometimes Debian contain a source ball within the '.orig.' tar.gz
# They usually do this if there is more than one program that makes up
# the named package.
cat ${ORIGPATH}/source/grep*orig* | tar -zxOf - | tar -zxf -

cd ${PACKAGE}* # enter into source code's dir
slackddiff     # patch the Debian diff into the unarchived source
for i in debian/patches/*.patch ; do patch -p0 < $i ; done

CFLAGS="-O2 ${ARMCFLAGS}" \
./configure --prefix=/usr || { failconfig ; exit 1; }
make || { failmake ; exit 1 ; }

start_fakeroot # start the fake root server so we can get the perms & ownerships we need

make install-strip DESTDIR=${PKG}

# Imitate the Slackware package:
( cd $PKG/usr/bin
  mkdir -p $PKG/bin
  rm -f egrep fgrep bzgrep # these work fine as symlinks to grep
  mv -f grep ../../bin/
  ln -fs ../../bin/grep .
  ln -fs ../../bin/grep egrep
  ln -fs ../../bin/grep fgrep
  cd ../../bin
  ln -fs grep egrep 
  ln -fs grep fgrep 
  cd $PKG/usr/man/man1
  ln -fs grep.1 egrep.1 # these can be symlinks too
  ln -fs grep.1 fgrep.1 )

# Install the docs:
mkdir -p $PKG/usr/doc/grep-$VERSION
cp -fa  ABOUT-NLS AUTHORS COPYING ChangeLog INSTALL NEWS README README-alpha README.DOS THANKS TODO \
        $PKG/usr/doc/${PACKAGE}-$VERSION


cd $PKG         # enter the package's root directory
slackx86        # search for any Intel x86 binaries
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackstripall   # strip *everything* that can be stripped
#slackstripso   # strip .so files only
#slackstripar   # strip .a files only
#slackstripbin  # strip binaries in usr/bin, usr/sbin, sbin and bin 
slackslack      # set all files to root.root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh
slackmp         # run makepkg
slackipkg       # install new package (removepkg runs first)
slackhlinks     # search for any hard links
shortwords

