#!/bin/bash

# infozip.SlackBuild
# by Stuart Winter <mozes@slackware.com> for the Slackware porting Project.
# Heavily based on the original Slackware build script.
# 30-May-2004

# Record toolchain & other info for the build log:
slackbuildinfo

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/$PKGSERIES/$PKGNAM
export PORTCWD=$PWD

# Temporary build locations:
export TMPBUILD=$TMP/build-$PKGNAM
export PKG=$TMP/package-$PKGNAM
mkpkgdirs # Delete and re-create temporary directories

# Determine the CFLAGS for the known architectures:
case $ARCH in
   arm)     SLKCFLAGS="-O2 -march=armv4t -DACORN_FTYPE_NFS -DFORRISCOS" ;;
   powerpc) SLKCFLAGS="-O2" ;;
   sparc)   SLKCFLAGS="-O2" ;;
   *)       SLKCFLAGS="-O2" ;;
esac

############ Build zip ###########################################################

# Extract source:
tar xvvf $CWD/zip*.tar.?z*
cd zip* || exit 1
slackhousekeeping
pwd

# Grab Zip version from its extracted dir:
#ZIPVER=$( ls -d ../zip* | cut -d/ -f2 )
ZIPVER=3.0

# Apply RISC OS filetype patch:
# Doesn't apply to zip 3.0, and we don't support RISC OS anymore..
#bzcat $PORTCWD/sources/acorn-fstypes.patch.bz2 | patch -p1 --verbose || failpatch

# Build:
make $NUMJOBS CC="gcc $SLKCFLAGS" -f unix/Makefile generic || failmake

# Install binaries:
mkdir -p $PKG/usr/bin
install -m755 zipnote zipsplit zipcloak zip $PKG/usr/bin

# Install man pages:
mkdir -p $PKG/usr/man/man1
install -m644 man/*.1 $PKG/usr/man/man1

# Install docs:
mkdir -p $PKG/usr/doc/zip-$ZIPVER
cp -fav BUGS CHANGES INSTALL LICENSE README* TODO US* WHATSNEW WHERE \
        $PKG/usr/doc/zip-$ZIPVER

############ Build unzip ###########################################################

# Extract source:
cd $TMPBUILD
tar xvvf $CWD/unzip*.tar.?z*
cd unzip* || exit 1
slackhousekeeping

# Grab unzip version number from extracted dir:
#UNZIPVER=$( ls -d ../unzip* | cut -d/ -f2 )
UNZIPVER=$VERSION

# Build:
#make $NUMJOBS CFLAGS="$SLKCFLAGS -I." -f unix/Makefile LF2="" unzips || failmake
make $NUMJOBS CFLAGS="$SLKCFLAGS -I." -f unix/Makefile LF2="" generic || failmake

# Install binaries:
install -m755 unzip unzipsfx funzip unix/zipgrep  $PKG/usr/bin
( cd $PKG/usr/bin && ln -sf unzip zipinfo )

# Install man pages:
install -m644 man/*.1 $PKG/usr/man/man1

# Install docs:
mkdir -p $PKG/usr/doc/unzip-$UNZIPVER
cp -a BUGS COPYING* Contents History.* INSTALL LICENSE README ToDo WHERE \
      $PKG/usr/doc/unzip-$UNZIPVER

#####################################################################################

# If necessary, start the fakeroot server so we can set file/dir ownerships:
start_fakeroot

# Apply generic Slackware packaging policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh
slackmp         # run makepkg -l y -c n

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links
