# Maintainer: PktSurf <smlinux@pktsurf.in>
app=net-snmp
version=5.8
build=1sml
homepage="http://www.net-snmp.org/"
download="https://sourceforge.net/projects/net-snmp/files/net-snmp/$version/net-snmp-$version.tar.gz"
desc="Collection of tools for implementing SNMP version 1 and up"
requires="libpcap pcre python3"
# net-snmp does not like our custom config.cache
noautoconfsite=1

prepbuilddir() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version 
  fixbuilddirpermissions

  applypatch $srcdir/fix-includes.patch
  applypatch $srcdir/netsnmp-swinst-crash.patch
  applypatch $srcdir/report-empty-strings-correctly.patch
}

build() {
  ./configure \
    --prefix="/" \
    --sbindir=/bin \
    --sysconfdir=/etc/snmp \
    --mandir=/share/man \
    --with-default-snmp-version="3" \
    --with-sys-contact="root@localhost" \
    --with-sys-location="Unknown" \
    --with-logfile="/var/log/snmpd.log" \
    --with-persistent-directory="/var/lib/net-snmp" \
    --with-openssl \
    --enable-ipv6 \
    --enable-as-needed \
    --with-perl-modules="INSTALLDIRS=vendor" \
    --disable-embedded-perl \
    --disable-debugging \
    --without-rpm \
    --program-suffix= \
    --program-prefix= \
    --enable-static=no \
    --build=arm-musl-linux

  make 
  sed -i 's@INSTALLMAN3DIR = none@INSTALLMAN3DIR = $(DESTDIR)$(INSTALLMAN3DIR)@g' perl/SNMP/Makefile
  make install DESTDIR=$pkg

  install -Dm 755 $srcdir/rc.snmpd $pkg/etc/rc.d/rc.snmpd.new
  install -Dm 644 $srcdir/snmpd.conf $pkg/etc/snmp/snmpd.conf.new

  cp COPYING $pkgdocs/

  mkfinalpkg
}

sha512sums="
4b6cf8866c85c296cefab6a409c6c01ddbdee1e053cad6d4663816249b24e4f82cad41056d62a736ae0b4be06dc186b0843eaf0217ffd0a2ccb2b944c35e6e39  net-snmp-5.8.tar.lz
87a552bd2e41684bba6e87fbcf6454a85ee912d7a339411fda24cebddf7661f0856729e076a917920a542cf84b687ffd90a091daa15f2c48f0ff64f3a53c0ddb  fix-includes.patch
4ad92f50b14d5e27ba86256cc532a2dd055502f4d5fbb1700434f9f01f881fd09bb1eadb94e727554e1470f036707558314c64a66d0376b54e71ab31d5e4baa3  netsnmp-swinst-crash.patch
633fbf574a76f63b0ae5340cd86439ca89ef2621b890917c35a884fe2d41052d4ec65c88f0d3f94f2bb3481b2bc1989647d3e697f7995b72abee47799300c26b  report-empty-strings-correctly.patch
"
