# Maintainer: LoveSy <shana@zju.edu.cn>

pkgname="openbsd-netcat"
pkgver=1.229_1
pkgrel=1
pkgdesc="TCP/IP swiss army knife. OpenBSD variant."
arch=('i686' 'x86_64')
url="https://packages.debian.org/sid/netcat-openbsd"
license=('BSD')
depends=('libbsd')
makedepends=('make' 'gcc' 'pkgconf')
provides=('netcat')
conflicts=('gnu-netcat')
source=("https://salsa.debian.org/debian/netcat-openbsd/-/archive/debian/${pkgver/_/-}/netcat-openbsd-debian-${pkgver/_/-}.tar.gz"
        "001-msys2-build-fix.patch")
sha256sums=('4984c52882affcc638678a887964f7ab1d21901a2c5c37a38363138370d4dbda'
            '60d725e13cebeb3b40574d41f0218f89c4fe2982118fb80c4ecc9c19b3df9892')

prepare() {
  cd netcat-openbsd-debian-${pkgver/_/-}
  for i in `cat debian/patches/series`; do
    echo "** patch $i" 1>&2
    cat "debian/patches/$i"
  done | patch -p1

  patch -p1 -i "${srcdir}/001-msys2-build-fix.patch"
}

build() {
  cd netcat-openbsd-debian-${pkgver/_/-}

  make \
    CFLAGS="$CFLAGS -DDEBIAN_VERSION=\"\\\"${pkgrel}\\\"\"" \
    LDFLAGS="$LDFLAGS -lbsd"
}

package() {
  cd netcat-openbsd-debian-${pkgver/_/-}
  install -Dm0755 nc "$pkgdir"/usr/bin/nc
  ln -s nc "$pkgdir"/usr/bin/netcat
  install -Dm0644 nc.1 "$pkgdir"/usr/share/man/man1/nc.1
  install -dm0755 "$pkgdir"/usr/share/licenses/$pkgname/
  head -n28 netcat.c | tail -n+2 >"$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
