# Description: Network Sniffer
# URL: https://www.wireshark.org
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: c-ares hicolor-icon-theme libgcrypt libpcap qt6-5compat qt6-multimedia qt6-translations

name=wireshark
version=4.0.7
release=1
source=(https://www.wireshark.org/download/src/$name-$version.tar.xz)

build() {
  prt-get isinst ccache && PKGMK_WIRESHARK+=' -D ENABLE_CCACHE=ON' && \
    PATH="$(echo ${PATH} | awk -v RS=: -v ORS=: '/ccache/ {next} {print}' | sed 's/:*$//')"

  # lto only works well with lld due to a ld bug
  prt-get isinst clang lld && \
    export CC='clang' && \
    export CXX='clang++' && \
    export AR=llvm-ar NM=llvm-nm RANLIB=llvm-ranlib && \
    export LDFLAGS+=' -fuse-ld=lld -flto=thin'
  prt-get isinst clang lld && PKGMK_WIRESHARK+=' -D ENABLE_LTO=ON '

  cmake -S $name-$version -B build -G Ninja $PKGMK_WIRESHARK \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
    -D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -D USE_qt6=ON

  cmake --build build
  DESTDIR=$PKG cmake --install build

  chown root:wireshark $PKG/usr/bin/dumpcap
  chmod u+s $PKG/usr/bin/dumpcap

  # Don't remove these files, they are read by wiresharks about box.
  #rm -f $PKG/usr/share/$name/{AUTHORS-SHORT,COPYING}
}
