SUMMARY="A network protocol analyzer formerly known as ethereal"
DESCRIPTION="Wireshark is a network traffic analyzer, or \"sniffer\", for Unix \
and Unix-like operating systems. It uses Qt, a graphical user interface \
library, and libpcap, a packet capture and filtering library.

The Wireshark distribution also comes with TShark, which is a \
line-oriented sniffer (similar to Sun's snoop, or tcpdump) that uses the \
same dissection, capture-file reading and writing, and packet filtering \
code as Wireshark, and with editcap, which is a program to read capture \
files and write the packets from that capture file, possibly in a \
different capture file format, and with some packets possibly removed \
from the capture."
HOMEPAGE="https://www.wireshark.org"
COPYRIGHT="1998-2020 Gerald Combs"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/wireshark/wireshark/archive/wireshark-$portVersion.tar.gz"
CHECKSUM_SHA256="fcbde722af8523d98844c981a3279a599311a93b87a4562bc5484b4d56b4f645"
SOURCE_DIR="wireshark-wireshark-$portVersion"
ADDITIONAL_FILES="wireshark.rdef"
PATCHES="wireshark-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2 ?x86"
SECONDARY_ARCHITECTURES="x86"

libwiresharkLibVersion="12.0.14"
libwiresharkLibVersionCompat="$libwiresharkLibVersion compat >= ${libwiresharkLibVersion%%.*}"

libwiretapLibVersion="9.0.14"
libwiretapLibVersionCompat="$libwiretapLibVersion compat >= ${libwiretapLibVersion%%.*}"

libwscodecsLibVersion="2.0.0"
libwscodecsLibVersionCompat="$libwscodecsLibVersion compat >= ${libwscodecsLibVersion%%.*}"

libwsutilLibVersion="10.0.0"
libwsutilLibVersionCompat="$libwsutilLibVersion compat >= ${libwsutilLibVersion%%.*}"

PROVIDES="
	wireshark$secondaryArchSuffix = $portVersion
	cmd:capinfos
	cmd:captype
	cmd:dumpcap
	cmd:editcap
	cmd:idl2wrs
	cmd:mergecap
	cmd:randpkt
	cmd:rawshark
	cmd:reordercap
	cmd:sharkd
	cmd:text2pcap
	cmd:tshark
	devel:libwireshark$secondaryArchSuffix = $libwiresharkLibVersionCompat
	devel:libwiretap$secondaryArchSuffix = $libwiretapLibVersionCompat
	devel:libwscodecs$secondaryArchSuffix = $libwscodecsLibVersionCompat
	devel:libwsutil$secondaryArchSuffix = $libwsutilLibVersionCompat
	lib:libwireshark$secondaryArchSuffix = $libwiresharkLibVersionCompat
	lib:libwiretap$secondaryArchSuffix = $libwiretapLibVersionCompat
	lib:libwscodecs$secondaryArchSuffix = $libwscodecsLibVersionCompat
	lib:libwsutil$secondaryArchSuffix = $libwsutilLibVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgcrypt$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgmodule_2.0$secondaryArchSuffix
	lib:libgpg_error$secondaryArchSuffix
	lib:libgthread_2.0$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libpcap$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_gui="
	wireshark${secondaryArchSuffix}_gui = $portVersion
	cmd:wireshark
	app:Wireshark
	"
REQUIRES_gui="
	haiku$secondaryArchSuffix
	wireshark${secondaryArchSuffix} == $portVersion base
	lib:libgcrypt$secondaryArchSuffix
	lib:libgmodule_2.0$secondaryArchSuffix
	lib:libpcap$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Multimedia$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libgcrypt$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgpg_error$secondaryArchSuffix
	devel:libpcap$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Multimedia$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:bison
	cmd:cmake
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python
	cmd:strip$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake .. $cmakeDirArgs \
		-DCMAKE_EXE_LINKER_FLAGS="-lnetwork" \
		-DCMAKE_BUILD_TYPE=Release
	make $jobArgs
}

INSTALL()
{
	make -C build install

	prepareInstalledDevelLibs libwireshark libwiretap libwscodecs libwsutil
	fixPkgconfig

	mkdir -p $appsDir
	ln -s $prefix/bin/wireshark $appsDir/Wireshark

	addResourcesToBinaries $portDir/additional-files/wireshark.rdef \
		$appsDir/Wireshark

	addAppDeskbarSymlink $appsDir/Wireshark

	packageEntries gui $appsDir $dataDir/deskbar $prefix/bin/wireshark
}
