# -*- 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                wireshark22
version             2.2.17
revision            0
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/
# macOS 10.12 and later ones are supported with Wireshark 3.x/4.x; 10.11 and below are limited to 2.x.
# It is not clear which is the latest macOS which still allows to build Wireshark 2.x,
# but it is known to fail on the recent ones. Related info:
# https://gitlab.com/wireshark/wireshark/-/issues/19285
# https://www.wireshark.org/lists/wireshark-dev/202305/msg00004.html
# https://gitlab.com/wireshark/wireshark/-/wikis/Development/LifeCycle
platforms           {darwin < 16}

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_bzip2           yes

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

worksrcdir          wireshark-${version}

checksums           sha256  923d39ff9c6df83b9594868542061da33bf330e12526778a8cb3adcf912eebb0 \
                    rmd160  06086c787720d126be5d47411b601ff59d9f4ba9 \
                    size    32551027

conflicts           wireshark2 wireshark3 wireshark30 wireshark4

depends_build-append \
                    port:pkgconfig

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

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=OFF \
                    -DENABLE_GEOIP=OFF \
                    -DENABLE_GNUTLS=OFF \
                    -DENABLE_KERBEROS=OFF \
                    -DENABLE_LUA=OFF \
                    -DENABLE_NETLINK=OFF \
                    -DENABLE_PORTAUDIO=OFF \
                    -DENABLE_SMI=OFF \
                    -DENABLE_ZLIB=OFF \
                    -DBUILD_wireshark_gtk=OFF \
                    -DBUILD_wireshark=OFF

variant qt4 conflicts no_gui qt5 gtk2 gtk3 description {Build wireshark with a qt4 GUI} {
    PortGroup               qt4 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=OFF

    # post-destroot {
    #     ln -s ${prefix}/bin/dumpcap ${destroot}${prefix}/bin/wireshark.app/Contents/MacOS/
    #     file mkdir ${destroot}${prefix}/bin/wireshark.app/Contents/PlugIns
    #     ln -s ${prefix}/lib/wireshark/plugins/${version} ${destroot}${prefix}/bin/wireshark.app/Contents/PlugIns/wireshark
    #     file copy ${worksrcpath}/packaging/macosx/Resources ${destroot}${prefix}/bin/wireshark.app/Contents/
    #     file delete ${destroot}${prefix}/bin/wireshark.app/Contents/Info.plist
    #     file copy ${worksrcpath}/packaging/macosx/Info.plist ${destroot}${prefix}/bin/wireshark.app/Contents/
    #     move ${destroot}${prefix}/bin/wireshark.app ${destroot}${applications_dir}/Wireshark.app
    # }
    post-destroot {
        move ${destroot}${prefix}/bin/Wireshark.app ${destroot}${applications_dir}/Wireshark.app
    }
}

variant qt5 conflicts no_gui qt4 gtk2 gtk3 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 gtk2 conflicts no_gui qt4 qt5 gtk3 description {Build wireshark with a gtk2 GUI} {
    configure.args-replace  -DBUILD_wireshark_gtk=OFF -DBUILD_wireshark_gtk=ON
    configure.args-append   -DENABLE_GTK3=OFF
    depends_lib-append      path:lib/pkgconfig/gtk+-2.0.pc:gtk2
    
    # post-destroot {
    #         file mkdir ${destroot}${applications_dir}/Wireshark.app/Contents/MacOS
    #         ln -s ${prefix}/bin/wireshark-gtk ${destroot}${applications_dir}/Wireshark.app/Contents/MacOS/Wireshark
    #         ln -s ${prefix}/bin/dumpcap ${destroot}${applications_dir}/Wireshark.app/Contents/MacOS/dumpcap
    #         file mkdir ${destroot}${applications_dir}/Wireshark.app/Contents/PlugIns
    #         ln -s ${prefix}/lib/wireshark/plugins/${version} ${destroot}${applications_dir}/Wireshark.app/Contents/PlugIns/wireshark
    #         file copy ${worksrcpath}/packaging/macosx/Resources ${destroot}${applications_dir}/Wireshark.app/Contents/
    #         file copy ${worksrcpath}/packaging/macosx/Info.plist ${destroot}${applications_dir}/Wireshark.app/Contents/
    # }
}
variant gtk3 conflicts no_gui qt4 qt5 gtk2 description {Build wireshark with a gtk3 GUI} {
    configure.args-replace  -DBUILD_wireshark_gtk=OFF -DBUILD_wireshark_gtk=ON
    configure.args-append   -DENABLE_GTK3=ON
    depends_lib-append      path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                            port:adwaita-icon-theme
    post-destroot {
        file mkdir ${destroot}${applications_dir}/Wireshark.app/Contents/MacOS
        ln -s ${prefix}/bin/wireshark-gtk ${destroot}${applications_dir}/Wireshark.app/Contents/MacOS/Wireshark
        ln -s ${prefix}/bin/dumpcap ${destroot}${applications_dir}/Wireshark.app/Contents/MacOS/dumpcap
        file mkdir ${destroot}${applications_dir}/Wireshark.app/Contents/PlugIns
        ln -s ${prefix}/lib/wireshark/plugins/${version} ${destroot}${applications_dir}/Wireshark.app/Contents/PlugIns/wireshark
        file copy ${worksrcpath}/packaging/macosx/Resources ${destroot}${applications_dir}/Wireshark.app/Contents/
        file copy ${worksrcpath}/packaging/macosx/Info.plist ${destroot}${applications_dir}/Wireshark.app/Contents/
    }
}

variant no_gui conflicts qt4 qt5 gtk2 gtk3 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 portaudio description {Build with PortAudio support} {
    configure.args-replace  -DENABLE_PORTAUDIO=OFF -DENABLE_PORTAUDIO=ON
    depends_lib-append      port:portaudio
}

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

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 libgcrypt description {Build with GNU crypto support} {
    configure.args-replace  -DENABLE_GCRYPT=OFF -DENABLE_GCRYPT=ON
    depends_lib-append      port:libgcrypt
}

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
}

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

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

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

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 register.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       https://1.na.dl.wireshark.org/src/all-versions/
livecheck.regex     wireshark-(2\\.2(?:\\.\\d+)*).tar

#
##EOF
