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

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

# Note: 2.01 seems to fix the bug, so we'll use it...

VERSION=2.01
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
chown -R root.root .
find . -perm 775 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
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
mkdir -p $PKG/usr/lib
cp -a libsyslinux.a $PKG/usr/lib
mkdir -p $PKG/usr/include
cp -a syslinux.h $PKG/usr/include
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
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