# Maintainer: Sébastien Luttringer

pkgname=ucarp
pkgver=1.5.2
pkgrel=8
pkgdesc='Userspace implementation of the CARP protocol'
arch=('x86_64')
url='https://www.pureftpd.org/project/ucarp'
license=('GPL2')
depends=('libpcap')
optdepends=('iproute2')
source=("https://download.pureftpd.org/pub/$pkgname/$pkgname-$pkgver.tar.gz"{,.sig}
        "$pkgname.service"
        "$pkgname.8"
        '01-fix-getopt.patch'
        '02-fix-downscript-on-error.patch')
validpgpkeys=('54A2B8892CC3D6A597B92B6C210627AABA709FE1') # Frank Denis
md5sums=('e3caa733316a32c09e5d3817617e9145'
         'SKIP'
         'fdc72a8d6f89224b40c78705df1f46f9'
         '2ccfdc464b88c437b38bd0324cf1fef3'
         '3f20699aaf2ef8139dcd337f1e7f06ab'
         '09d26233c37956cf08e629554a91b8cd')

prepare() {
  cd $pkgname-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local filename
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      msg2 "Applying patch ${filename##*/}"
      patch -p1 -N -i "$srcdir/${filename##*/}"
    fi
  done
  :
}

build() {
  cd $pkgname-$pkgver
  CFLAGS+=' -fcommon' # https://wiki.gentoo.org/wiki/Gcc_10_porting_notes/fno_common
  ./configure --prefix=/usr --sbindir=/usr/bin
  make

}

package() {
  pushd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  # install examples files
  install -D -m 644 examples/linux/vip-down.sh \
    "$pkgdir/usr/share/doc/$pkgname/examples/vip-down.sh"
  install -D -m 644 examples/linux/vip-up.sh \
    "$pkgdir/usr/share/doc/$pkgname/examples/vip-up.sh"
  # install README
  install -D -m 644 README "$pkgdir/usr/share/doc/$pkgname/README"
  popd
  # add manpage
  install -D -m 644 $pkgname.8 "$pkgdir/usr/share/man/man8/$pkgname.8"
  # systemd
  install -D -m 644 $pkgname.service \
    "$pkgdir/usr/lib/systemd/system/$pkgname.service"

}

# vim:set ts=2 sw=2 et:
