#!/bin/sh
#
# Copyright 2004 Dagmar d'Surreal <rivyqntzne@tznvy.pbz>
# Available under the terms of the GNU GPL.
#

NAME="dhcp"
VERSION="3.0.3"
REVISION="2"

PKG_SOURCEURL='ftp://ftp.isc.org/isc/dhcp/dhcp-$VERSION.tar.gz'
PKG_PATCH[0]='dhcp-3.0.3-usrlocalremoval.diff'
PKG_PATCH[1]='default-dhclient.conf'
PKG_PATCH[2]='default-dhcpd.conf'

. $DLG_ROOT/config
. $DLG_ROOT/SCRIPTS/dropline-functions.sh

# This will make the package compatible for people stubborn enough to keep
# feeding electricity into hardware over a decade old.
PKG_ARCH="i486"
DLG_PKGER="dds"

PKG_DOCFILES="$PKG_DOCFILES RELNOTES"
# This one isn't really a configuration file but it has to be protected.
configfile /var/state/dhcp/dhcpd.leases
configfile /etc/dhclient.conf
configfile /etc/dhcpd.conf

# This thing basically ignores cflags.
prepare
analyzesource

applypatch 0 1

# This does what little we can to compensate for the cflags.
cd $PKG_BUILDROOT
if [ -z "$PKG_ARCH" ]; then
  sed -i -e "s/DEBUG = -g/DEBUG = -O2/;" Makefile.conf
else
  sed -i -e "s/DEBUG = -g/DEBUG = -O2 -march=$PKG_ARCH/;" Makefile.conf
fi

spewdo "cd $PKG_BUILDROOT"
spew 2 "Running the configure script..."
set_title "$NAME-$VERSION-$REVISION: configure phase"
loggedcommand configure "./configure"

make
makeinstall

spewdo "createdir $PKG_STAGEROOT$PKG_DOCDIR/examples/"
spewdo "cp $PKG_SRCROOT/client/dhclient.conf $PKG_STAGEROOT$PKG_DOCDIR/examples/"
spewdo "cp $PKG_SRCROOT/server/dhcpd.conf $PKG_STAGEROOT$PKG_DOCDIR/examples/"
tidydocumentation

# We save a *little* space this way, but not much.
spewdo "strip -g $PKG_STAGEROOT/sbin/* >/dev/null 2>&1"
spewdo "strip -g $PKG_STAGEROOT/usr/sbin/* >/dev/null 2>&1"

spewdo "createdir $PKG_STAGEROOT/etc"
findpatch dhclientconf ${PKG_PATCH[1]}
findpatch dhcpdconf ${PKG_PATCH[2]}
if [ ! -e $dhclientconf ]; then
  exit 1
elif [ ! -e $dhcpdconf ]; then
  exit 1
fi

spewdo "install -m 644 -o root -g root $dhclientconf $PKG_STAGEROOT/etc/dhclient.conf"
spewdo "install -m 644 -o root -g root $dhcpdconf $PKG_STAGEROOT/etc/dhcpd.conf"
spewdo "touch $PKG_STAGEROOT/var/state/dhcp/dhcpd.leases"

analyzebinaries
finalizepackage
packagize
cleanup
