#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-qcam

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_qcam.tar.gz

echo "+============+"
echo "| qcam-0.91j |"
echo "+============+"
cd $TMP
tar xzvf $CWD/qcam-0.91j.tgz
cd qcam-0.91j
zcat $CWD/Makefile.diff.gz | patch
make
strip qcam
strip qcam-simple
strip xqcam
strip probeqcam
strip make.darkmask
cat qcam > $PKG/usr/bin/qcam
cat qcam-simple > $PKG/usr/bin/qcam-simple
cat xqcam > $PKG/usr/X11R6/bin/xqcam
cat probeqcam > $PKG/usr/sbin/probeqcam
cat make.darkmask > $PKG/usr/bin/make.darkmask
cat qcam.1 | gzip -9c > $PKG/usr/man/man1/qcam.1.gz
cat libqcam.a > $PKG/usr/lib/libqcam.a
cat libqcamip.a > $PKG/usr/lib/libqcamip.a
cp -a qcam.conf $PKG/etc/qcam.conf
chown root.root $PKG/etc/qcam.conf
chmod 644 $PKG/etc/qcam.conf
cp -a qcam-Linux.h qcam.h qcamip.h $PKG/usr/include
( cd $PKG/usr/include ; ln -s qcam-Linux.h qcam-os.h )
chown root.root $PKG/usr/include/*
chmod 644 $PKG/usr/include/*
mkdir -p $PKG/usr/doc/qcam-0.91j
chown root.root $PKG/usr/doc/qcam-0.91j
chmod 755 $PKG/usr/doc/qcam-0.91j
cp -a BUGS CHANGES ChangeLog INFO README README.JPEG To-Do \
   $CWD/README.BW quickcam.tex $PKG/usr/doc/qcam-0.91j
chown root.root $PKG/usr/doc/qcam-0.91j/*
chmod 644 $PKG/usr/doc/qcam-0.91j/*

# Build the package:
cd $PKG
echo "n" | makepkg $TMP/qcam.tgz

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/qcam-0.91j
  rm -rf $PKG
fi