#!/bin/sh

# Slackware build script for libpng-legacy12

# Written by B. Watson (yalhcru@gmail.com)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

PRGNAM=libpng-legacy12
VERSION=${VERSION:-1.2.57}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

UPSTREAM_VER=${UPSTREAM_VER:-1.4.20}
UPSTREAM_BUILD=${UPSTREAM_BUILD:-1}
UPSTREAM_TAG=${UPSTREAM_TAG:-_slack14.1}

# N.B. do NOT change i486 to i586 here, since this is a repack
# of a Slack 14.1 package.
if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i486 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

# We reset ARCH to i486 if it's i586 or i686, to match Slack 14.1's ARCH.
case "$ARCH" in
   i?86) LIBDIRSUFFIX=""; ARCH=i486 ;;
 x86_64) LIBDIRSUFFIX="64" ;;
      *) echo "Warning: unrecognized ARCH '$ARCH'" ;;
esac

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

UPSTREAM=libpng-$UPSTREAM_VER-$ARCH-$UPSTREAM_BUILD$UPSTREAM_TAG

set -e

rm -rf $PKG
mkdir -p $TMP/$PRGNAM $PKG $OUTPUT
rm -rf $TMP/$PRGNAM
mkdir -p $TMP/$PRGNAM
cd $TMP/$PRGNAM
tar xvf $CWD/$UPSTREAM.txz

# Include only the shared lib, plus SBo-specific docs.
mkdir -p $PKG/usr/lib$LIBDIRSUFFIX
cp -a \
  ./usr/lib$LIBDIRSUFFIX/libpng12.so.*.*.* \
  ./usr/lib$LIBDIRSUFFIX/libpng12.la \
  $PKG/usr/lib$LIBDIRSUFFIX

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/README > $PKG/usr/doc/$PRGNAM-$VERSION/README
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# make our doinst.sh from upstream's
grep libpng12.so ./install/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
