# Description: Network Time Protocol software
# URL:         http://www.ntp.org
# Maintainer:  Thomas Penteker, tek at serverop dot de
# Packager:    James Mills, prologic at shortcircuit dot net dot au
# Depends on:  openssl

name=ntp
version=4.2.4p7
release=2
source=(http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/$name-$version.tar.gz
        ntpd
        ntpdate
        ntp.conf
        ntp-64bit.diff)

build () {
   mkdir -p $PKG/etc/{rc.d,ntp} \
      $PKG/var/log \
      $PKG/var/run/ntp \
      $PKG/var/lib/ntp/stats \
      $PKG/usr/man/{man8,man5}

   cd $name-$version

   patch -p1 -i ../ntp-64bit.diff

   ./configure \
      --prefix=/usr \
      --with-sntp \
      --with-crypto \
      --enable-debugging=no \
      --enable-ntpdate-step \
      --enable-parse-clocks \
      --enable-all-clocks \
      CFLAGS="$CFLAGS" \
      LDFLAGS="$LDFLAGS" 

   # substitute the default configuration path
   sed -i -e 's;\(CONFIG_FILE[^"]*"\)/etc/ntp.conf;\1/etc/ntp/ntp.conf;' \
        include/ntp_config.h ntpdate/ntptime_config.c

   make
   make DESTDIR=$PKG install
   touch $PKG/var/log/ntp.log

   install -m 644 $SRC/ntp.conf $PKG/etc/ntp
   install -m 755 $SRC/ntpd $PKG/etc/rc.d
   install -m 755 $SRC/ntpdate $PKG/etc/rc.d

   # initialize ntp.drift file
   echo "0.0" > $PKG/var/lib/ntp/ntp.drift
}
