#!/bin/sh

[ -z $PREPKG ] && exit 1

PACKAGE=gpsd
VERSION=2.95
FILES=$(cd $(dirname $0) ; pwd)

mkdir -p \
  $PREPKG/{install,etc/default,lib/udev/rules.d,usr/{doc/$PACKAGE-$VERSION,share/{applications,gpsd}}}/

chmod -R \
  u+w,go-w .
chown -R \
  root:root .
CFLAGS="-O2 -march=i486 -mtune=i686" \
CXXFLAGS="-O2 -march=i486 -mtune=i686" \
  ./configure \
  --prefix=/usr \
  --datarootdir=/usr \
  --enable-bluetooth \
  --enable-dbus \
  --build=i486-slackware-linux &> configure.output || exit 1
make $MAKEJOBS &> make.output || exit 1
make DESTDIR=$PREPKG --no-print-directory install \
  &> make_install.output || exit 1

cp -p \
  packaging/deb/etc_default_gpsd \
  $PREPKG/etc/default/gpsd
cp -p \
  gpsd.hotplug* \
  $PREPKG/lib/udev/
chmod a+x \
  $PREPKG/lib/udev/gpsd.hotplug*
# long after usb & bluetooth are handled (experimental)
cp -p \
  gpsd.rules \
  $PREPKG/lib/udev/rules.d/98-gpsd.rules
cp -p \
  AUTHORS COPYING INSTALL NEWS README TODO packaging/deb/etc_init.d_gpsd \
  $PREPKG/usr/doc/$PACKAGE-$VERSION/
cp -p \
  packaging/X11/*.desktop \
  $PREPKG/usr/share/applications/
cp -p \
  packaging/X11/gpsd-logo.png \
  $PREPKG/usr/share/gpsd/
gzip -r9 \
  $PREPKG/usr/man/

cp \
  $FILES/slack-desc \
  $PREPKG/install/

find $PREPKG -exec file {} \; \
  | awk -F : '/ ELF / {print $1}' \
  | xargs strip -p --strip-unneeded
