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

name                wireshark30
version             3.0.9
revision            3
categories          net
license             {GPL-2 GPL-3}
maintainers         {darkart.com:opendarwin.org @ghosthound}
description         Graphical network analyzer and capture tool
homepage            https://www.wireshark.org/
platforms           darwin

long_description    A network analyzer that lets you capture and \
                    interactively browse Ethernet frames. \
                    Packet data can be read from a file, or live from a local \
                    network interface.

master_sites        https://www.wireshark.org/download/src/ \
                    https://www.wireshark.org/download/src/all-versions/

use_xz              yes

distfiles           wireshark-${version}${extract.suffix}

worksrcdir          wireshark-${version}

checksums           sha256  bb4697ead91824b1fa33ffbe6643f6193459a66c906910a7611d5b26ff32aa04 \
                    rmd160  a2f75c6eb08f920ec42d515f2039630b8ac0e752 \
                    sha1    60d5dfeac1b75d813ffee049ca3fd393e9c9890f \
                    size    30860760

conflicts           wireshark2 wireshark22 wireshark3 wireshark4

depends_build-append \
                    port:pkgconfig

depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/libssl.dylib:openssl \
                    port:libgcrypt \
                    port:libpcap \
                    port:lz4

configure.args-append \
                    -DCMAKE_INSTALL_RPATH:STRING="${prefix}/lib" \
                    -DCMAKE_INSTALL_NAME_DIR:STRING="${prefix}/lib" \
                    -DENABLE_APPLICATION_BUNDLE=OFF \
                    -DENABLE_ADNS=OFF \
                    -DENABLE_CARES=OFF \
                    -DENABLE_GCRYPT=ON \
                    -DENABLE_GEOIP=OFF \
                    -DENABLE_GNUTLS=OFF \
                    -DENABLE_KERBEROS=OFF \
                    -DENABLE_LIBXML2=OFF \
                    -DENABLE_LUA=OFF \
                    -DENABLE_LZ4=ON \
                    -DENABLE_MINIZIP=OFF \
                    -DENABLE_NETLINK=OFF \
                    -DENABLE_SMI=OFF \
                    -DENABLE_SNAPPY=OFF \
                    -DENABLE_ZLIB=OFF \
                    -DBUILD_wireshark=OFF

variant qt5 conflicts no_gui description {Build wireshark with a qt5 GUI} {
    PortGroup               qt5 1.0
    configure.args-replace  -DENABLE_APPLICATION_BUNDLE=OFF -DENABLE_APPLICATION_BUNDLE=ON
    configure.args-replace  -DBUILD_wireshark=OFF -DBUILD_wireshark=ON
    configure.args-append   -DENABLE_QT5=ON
    qt5.depends_component   qtbase \
                            qtmacextras \
                            qtmultimedia \
                            qtsvg \
                            qttranslations

    post-destroot {
        move ${destroot}${prefix}/bin/Wireshark.app ${destroot}${applications_dir}/Wireshark.app
    }
}

variant no_gui conflicts qt5 description {do not build the wireshark GUI} {
    ## initial settings (above) handle this
}

variant adns conflicts cares description {use adns library for async. dns resolution} {
    configure.args-replace  -DENABLE_ADNS=OFF -DENABLE_ADNS=ON
    depends_lib-append      port:adns
}

variant zlib description {Build with zlib compression support} {
    configure.args-replace  -DENABLE_ZLIB=OFF -DENABLE_ZLIB=ON
    depends_lib-append      port:zlib
}

variant minizip description {Build with minizip support} {
    configure.args-replace -DENABLE_MINIZIP=OFF -DENABLE_MINIZIP=ON
    depends_lib-append      port:minizip
}

variant lua description {Build with Lua dissector support} {
    configure.args-replace  -DENABLE_LUA=OFF -DENABLE_LUA=ON
    depends_lib-append      port:lua52
}

variant libsmi description {Build with libsmi snmp support} {
    configure.args-replace  -DENABLE_SMI=OFF -DENABLE_SMI=ON
    depends_lib-append      port:libsmi
}

variant gnutls description {Build with GNU TLS support} {
    configure.args-replace  -DENABLE_GNUTLS=OFF -DENABLE_GNUTLS=ON
    depends_lib-append      path:lib/pkgconfig/gnutls.pc:gnutls
}

variant cares conflicts adns description description {Build with c-ares support} {
    configure.args-replace  -DENABLE_CARES=OFF -DENABLE_CARES=ON
    depends_lib-append      port:c-ares
}

variant kerberos5 description {Build with Kerberos support} {
    configure.args-replace  -DENABLE_KERBEROS=OFF -DENABLE_KERBEROS=ON \
    configure.args-append   -DCMAKE_SHARED_LINKER_FLAGS="-lk5crypto"
    depends_lib-append      port:kerberos5
}

variant geoip description {Build with GeoIP support} {
    configure.args-replace  -DENABLE_GEOIP=OFF -DENABLE_GEOIP=ON
    depends_lib-append      port:libgeoip
}

variant chmodbpf description {Enable Wireshark to acces macOS capture devices} {
    depends_run             port:wireshark-chmodbpf
}

variant python35 description {Use python35 during build} {
    depends_build-append    port:python35
}

variant python36 description {Use python36 during build} {
    depends_build-append    port:python36
}

variant python37 description {Use python37 during build} {
    depends_build-append    port:python37
}

default_variants +zlib +libsmi +gnutls +geoip +kerberos5 +chmodbpf

if {![variant_isset qt5] && ![variant_isset no_gui]} {
    default_variants-append +qt5
}

if {![variant_isset adns] && ![variant_isset cares]} {
    default_variants-append +cares
}

## if no python3* variant is specified, add +python37
## XYZZY: it would be better to detect which python3* is already installed and use that...
if {![variant_isset python35] && ![variant_isset python36] && \
    ![variant_isset python37]} {
    default_variants-append +python37
}

post-destroot {
    xinstall -d ${destroot}${prefix}/include/wireshark/epan/crypt/
    xinstall -d ${destroot}${prefix}/include/wireshark/epan/dfilter/
    xinstall -d ${destroot}${prefix}/include/wireshark/epan/dissectors/
    xinstall -d ${destroot}${prefix}/include/wireshark/epan/ftypes/
    xinstall -d ${destroot}${prefix}/include/wireshark/wiretap/
    xinstall -m 644 -W ${worksrcpath}/ config.h ${destroot}${prefix}/include/wireshark/
    xinstall -m 644 {*}[glob ${worksrcpath}/epan/*.h] ${destroot}${prefix}/include/wireshark/epan/
    xinstall -m 644 {*}[glob ${worksrcpath}/epan/crypt/*.h] ${destroot}${prefix}/include/wireshark/epan/crypt/
    xinstall -m 644 {*}[glob ${worksrcpath}/epan/dfilter/*.h] ${destroot}${prefix}/include/wireshark/epan/dfilter/
    xinstall -m 644 {*}[glob ${worksrcpath}/epan/dissectors/*.h] ${destroot}${prefix}/include/wireshark/epan/dissectors/
    xinstall -m 644 {*}[glob ${worksrcpath}/epan/ftypes/*.h] ${destroot}${prefix}/include/wireshark/epan/ftypes/
    xinstall -m 644 {*}[glob ${worksrcpath}/wiretap/*.h] ${destroot}${prefix}/include/wireshark/wiretap/
}

livecheck.type      regex
livecheck.url       ${homepage}download.html
livecheck.regex     "Stable Release \\((\\d+(?:\\.\\d+)*)"

