# $Id: PKGBUILD 21345 2008-12-12 02:52:37Z allan $
# Maintainer: Allan McRae <allan@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

#
### Attention: remove old pkg before building - it links against itself! ###
#

pkgname=heimdal
pkgver=1.2.1
pkgrel=2
pkgdesc="Implementation of Kerberos V5 libraries"
arch=('i686' 'x86_64')
url="http://www.h5l.org/"
license=('custom')
depends=('db>=4.7' 'openssl' 'e2fsprogs')
backup=(etc/krb5.conf)
options=('!libtool' '!emptydirs')
install=$pkgname.install
source=(http://www.h5l.org/dist/src/${pkgname}-${pkgver}.tar.gz \
	002_all_heimdal-no_libedit.patch \
	003_all_heimdal-fPIC.patch \
	004_all_heimdal-rxapps.patch \
	heimdal-kdc.rc \
	kadmind.rc \
	kpasswd.rc)
md5sums=('6e5028077e2a6b101a4a72801ba71b9e'
         '1199c4a4a38e9c2b2c0a99bd5781767a'
         '3d0262aa218e1611500de735d3581e28'
         '0fe81cb1e33b2a2e60edaf47dfdfe4de'
         'e59650992b9541a30dfce727a194f6e0'
         '1f2f86a67bbfddb7af581d35fdca9627'
         'f8f1eca95b9d3f2b4ebf2417b71b81cf')

build() {
  [ -e /usr/lib/libasn1.so ] && echo "## remove old heimdal pkg first ##" && return 1

  cd ${srcdir}/heimdal-${pkgver}
  patch -Np0 -i ${srcdir}/002_all_heimdal-no_libedit.patch || return 1
  patch -Np0 -i ${srcdir}/003_all_heimdal-fPIC.patch || return 1
  patch -Np0 -i ${srcdir}/004_all_heimdal-rxapps.patch || return 1

  sed -i -e 's|var/heimdal|var/lib/heimdal|g' configure.in configure \
	doc/setup.texi doc/heimdal.info kadmin/kadmind.8 kdc/kdc.8 \
	lib/hdb/hdb.h lib/krb5/krb5.conf.5 lib/krb5/krb5.conf.cat5

  ./configure --prefix=/usr --enable-shared=yes --without-x \
	--sysconfdir=/etc  --mandir=/usr/share/man \
	--datadir=/var/lib/heimdal \
	--localstatedir=/var/lib/heimdal \
	--with-openssl=/usr \
	--with-readline-lib=/usr/lib \
	--with-readline-include=/usr/include/readline \
	--libexecdir=/usr/sbin --with-berkeley-db \
	--disable-krb4
	
  make || return 1
  make DESTDIR=${pkgdir} install || return 1

  for i in telnetd ftpd rshd; do
    mv ${pkgdir}/usr/share/man/man8/${i}.8 ${pkgdir}/usr/share/man/man8/k${i}.8
    mv ${pkgdir}/usr/sbin/${i} ${pkgdir}/usr/sbin/k${i}
  done
  
  for i in rcp rsh telnet ftp su login; do
    if [ -f ${pkgdir}/usr/share/man/man1/${i}.1 ]; then
      mv ${pkgdir}/usr/share/man/man1/${i}.1 ${pkgdir}/usr/share/man/man1/k${i}.1
    fi
    mv ${pkgdir}/usr/bin/${i} ${pkgdir}/usr/bin/k${i}
  done
  rm -rf ${pkgdir}/usr/share/man/cat{1,3,5,8}
  
  # Arch could be a KDC too
  mkdir -p ${pkgdir}/etc/rc.d
  install -m644 ${srcdir}/heimdal-${pkgver}/krb5.conf ${pkgdir}/etc
  for i in heimdal-kdc kadmind kpasswd; do
    install -m755 ${srcdir}/${i}.rc ${pkgdir}/etc/rc.d/${i}
  done

  # Remove conflicts 
  rm ${pkgdir}/usr/share/man/man5/ftpusers.5*		# man-pages
  rm ${pkgdir}/usr/share/info/dir

  # Compress info pages
  for page in heimdal hx509; do
    gzip -9 ${pkgdir}/usr/share/info/${page}.info
  done

  # Install the license
  install -D -m644 ${srcdir}/${pkgname}-${pkgver}/LICENSE \
  	${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
}