#!/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

############ 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

# 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

# Apply patches:
zcat $CWD/unzip.use.system.libbz2.diff.gz | patch -p1 --verbose || exit 1
zcat $CWD/unzip.process.c.diff.gz | patch -p1 --verbose || exit 1
zcat $CWD/unzip.git.archive.fix.diff.gz | patch -p0 --verbose || exit 1

# 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="" LOCAL_UNZIP=-DIZ_HAVE_UXUIDGID 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
