# -*- 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

PortSystem              1.0
PortGroup               perl5 1.0

name                    net-snmp
version                 5.9.4
revision                0
checksums               rmd160  f889d5aafce06974756503fe2beb109f5a2081a8 \
                        sha256  8b4de01391e74e3c7014beb43961a2d6d6fa03acc34280b9585f4930745b0544 \
                        size    6681606

categories              net
license                 BSD
maintainers             {ryandesign @ryandesign} openmaintainer
homepage                https://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.

perl5.branches          5.28 5.30 5.32 5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}

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

patchfiles-append       configure-frameworks.patch
patchfiles-append       fix-order-of-L-flags.patch
patchfiles-append       Makefile.top-libtool-tag.patch
# https://trac.macports.org/ticket/70165
patchfiles-append       patch-legacy-compat.diff

post-patch {
    # https://github.com/net-snmp/net-snmp/issues/646
    reinplace "s|5\\.9\\.4\\.pre2|${version}|g" ${worksrcpath}/configure
}

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

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

# For perl modules.
build.args              CC="${configure.cc}" \
                        LD="${configure.cc}"

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"
    configure.args-append --with-krb5=${prefix}
}

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

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.]+)/}
