# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id$

PortSystem              1.0
PortGroup               perl5 1.0

name                    net-snmp
version                 5.7.3
revision                6
categories              net
license                 BSD
platforms               darwin
maintainers             ryandesign openmaintainer
homepage                http://net-snmp.sourceforge.net/
master_sites            sourceforge:project/${name}/${name}/${version}

description             An extendable SNMP implementation

long_description        This is net-snmp, a derivative of CMU's SNMP \
                        package. Various tools relating to the Simple \
                        Network Management Protocol including: an extensible \
                        agent, an SNMP library, tools to request or set \
                        information from SNMP agents, tools to generate and \
                        handle SNMP traps, a version of the unix 'netstat' \
                        command using SNMP, a Tk/perl MIB browser.

checksums               rmd160  c5cf54d5723ee417e07f1f9fa3936aef505104a2 \
                        sha256  12ef89613c7707dc96d13335f153c1921efc9d61d3708ef09f3fc4a7014fb4f0

perl5.branches          5.24

depends_lib             port:bzip2 \
                        port:perl${perl5.major} \
                        port:zlib

post-extract {
    # darwin14.h and above do not exist in 5.7.3
    # https://sourceforge.net/p/net-snmp/bugs/2504/
    copy ${worksrcpath}/include/net-snmp/system/darwin13.h ${worksrcpath}/include/net-snmp/system/darwin14.h
    copy ${worksrcpath}/include/net-snmp/system/darwin13.h ${worksrcpath}/include/net-snmp/system/darwin15.h
    copy ${worksrcpath}/include/net-snmp/system/darwin13.h ${worksrcpath}/include/net-snmp/system/darwin16.h
    copy ${worksrcpath}/include/net-snmp/system/darwin13.h ${worksrcpath}/include/net-snmp/system/darwin17.h
    copy ${worksrcpath}/include/net-snmp/system/darwin13.h ${worksrcpath}/include/net-snmp/system/darwin18.h
}

patchfiles-append       patch-agent-mibgroup-mibII-icmp.h.diff
patchfiles-append       patch-configure.diff
patchfiles-append       patch-include-net-snmp-system-darwin11.h.diff
patchfiles-append       patch-include-net-snmp-system-darwin12.h.diff
patchfiles-append       patch-include-net-snmp-system-darwin13.h.diff
patchfiles-append       patch-include-net-snmp-system-darwin14.h.diff
patchfiles-append       patch-include-net-snmp-system-darwin15.h.diff
patchfiles-append       patch-include-net-snmp-system-darwin16.h.diff
patchfiles-append       patch-include-net-snmp-system-darwin17.h.diff
patchfiles-append       patch-include-net-snmp-system-darwin18.h.diff
patchfiles-append       patch-Makefile.in.diff
patchfiles-append       PR-52214.patch
patchfiles-append       0001-CHANGES-BUG-2712-Fix-Perl-module-compilation.patch

configure.env-append    PERLPROG=${perl5.bin}

configure.args          --with-defaults \
                        --with-sys-contact=nobody@no.where \
                        --with-persistent-directory=${prefix}/var/net-snmp \
                        --with-logfile=${prefix}/var/log \
                        --without-openssl \
                        --with-zlib=${prefix} \
                        --with-bzip2=${prefix} \
                        --with-install-prefix=${destroot} \
                        --without-elf \
                        --without-kmem-usage \
                        --enable-ipv6 \
                        --with-out-mib-modules=mibII/ipv6

variant ssl description {Enable ssl support} {
    depends_lib-append  path:lib/libssl.dylib:openssl
    configure.args-replace --without-openssl --with-openssl=${prefix}
}
default_variants +ssl

variant ksm description {Enable support for kerberos-based SNMP security} {
    depends_lib-append  port:kerberos5
    configure.args-append --with-security-modules="usm ksm"
}

post-build {
    reinplace -E {s|-arch [a-z0-9_]+||g} \
        ${worksrcpath}/net-snmp-config \
        ${worksrcpath}/net-snmp-create-v3-user
}

post-destroot {
    destroot.keepdirs ${destroot}${prefix}/var/net-snmp
    foreach packlist [exec find ${destroot} -name .packlist] {
        ui_info "Fixing packlist ${packlist}"
        reinplace "s|${destroot}||" ${packlist}
    }
    foreach badfile [exec find ${destroot} -name perllocal.pod] {
        ui_info "Removing ${badfile}"
        file delete ${badfile}
    }
}

startupitem.create      yes
startupitem.executable  ${prefix}/sbin/snmpd -f

livecheck.type          regex
livecheck.url           ${homepage}download.html
livecheck.regex         {net-snmp/([0-9.]+)/}