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

# Using version 1.67 for now, because newer versions have a bug
# where kernels around 1145000 bytes will not load from floppy

VERSION=1.67
ARCH=i386
BUILD=1

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

echo "+===================+"
echo "| syslinux-$VERSION |"
echo "+===================+"
cd $TMP
tar xjvf $CWD/syslinux-$VERSION.tar.bz2
cd syslinux-$VERSION
mkdir -p $PKG/usr/bin
cp -a syslinux gethostip ppmtolss16 lss16toppm $PKG/usr/bin
chmod 755 $PKG/usr/bin/*
chown -R root.bin $PKG/usr/bin
mkdir -p $PKG/usr/share/syslinux
cp -a \
  pxelinux.0 isolinux.bin isolinux-debug.bin syslinux.com copybs.com memdisk/memdisk \
  $PKG/usr/share/syslinux
chmod 644 $PKG/usr/share/syslinux/*
chown -R root.root $PKG/usr/share/syslinux
mkdir -p $PKG/usr/doc/syslinux-$VERSION
cp -a \
  COPYING NEWS README TODO distrib.doc isolinux.doc pxelinux.doc syslinux.doc memdisk/memdisk.doc \
  $PKG/usr/doc/syslinux-$VERSION
chmod 644 $PKG/usr/doc/syslinux-$VERSION/*
chown -R root.root $PKG/usr/doc/syslinux-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/syslinux-$VERSION-$ARCH-$BUILD.tgz

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