SUMMARY="GUI to profilers such as Valgrind"
DESCRIPTION="QCachegrind is a Qt GUI to visualize profiling data.
It's mainly used as visualization frontend for data measured
by Cachegrind/Callgrind tools from the Valgrind package, but
there are converters for other measurement tools available.

Features

* direct support for profiles generated by Cachegrind/Callgrind
* support for arbitrary event types and derived event types
* sorted function list, with grouping according to ELF object/source
  file/symbol namespace (such as C++ classes)
* correct handling of recursive cycles (similar to GProf)
* various visualization views for a selected function, such as
  - treemap in caller/callee direction
  - call graph around function
  - source & assembly annotation"
HOMEPAGE="https://github.com/KDE/kcachegrind"
COPYRIGHT="2010-2020 KDE Organisation"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/KDE/kcachegrind/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="f5696891680058229351a721c06cfec4d4417a2293e90133bb8ce3652db85ab0"
SOURCE_DIR="kcachegrind-$portVersion"
ADDITIONAL_FILES="qcachegrind.rdef.in"

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

PROVIDES="
	qcachegrind$secondaryArchSuffix = $portVersion
	app:QCachegrind$secondaryArchSuffix = $portVersion
	cmd:cgview
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:dbus_launch
	lib:libGL$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5DBus$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:qmake
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage qcachegrind$secondaryArchSuffix \
	"$binDir"/cgview \
	"$appsDir"/QCachegrind

BUILD()
{
	mkdir -p build
	cd build

	qmake ..
	make $jobArgs
}

INSTALL()
{
	cd build
	mkdir $appsDir $binDir
	cp -R cgview/cgview $binDir
	cp -R qcachegrind/qcachegrind $appsDir/QCachegrind

	local APP_SIGNATURE="application/x-vnd.kde-qcachegrind"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/qcachegrind.rdef.in > qcachegrind.rdef

	addResourcesToBinaries qcachegrind.rdef $appsDir/QCachegrind
	addAppDeskbarSymlink $appsDir/QCachegrind
}
