SUMMARY="A Qt and C++ GUI for rizin reverse engineering framework"
DESCRIPTION="Cutter is a free and open-source reverse engineering platform \
powered by rizin.
It aims at being an advanced and customizable reverse engineering platform \
while keeping the user experience in mind. Cutter is created by reverse \
engineers for reverse engineers."
HOMEPAGE="https://github.com/radareorg/cutter"
COPYRIGHT="2021 xarkes, thestr4ng3r, ballessay, Hugo Teso"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="$HOMEPAGE/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="b6ea21b8846c426ec17150ae5ef56e3e415c7e0b16190295b6bbdf367d4b755c"
SOURCE_FILENAME="cutter-$portVersion.tar.gz"
srcGitRev_2="974298653ba71b958e1b6c83f6011f5fefff6236"
SOURCE_URI_2="https://github.com/rizinorg/cutter-translations/archive/$srcGitRev_2.tar.gz"
CHECKSUM_SHA256_2="9a9d42769c1e9364dfc694968b05994d02ea840813a33b16ca6a6cbe80c90069"
SOURCE_FILENAME_2="translations-$srcGitRev_2.tar.gz"
ADDITIONAL_FILES="cutter.rdef.in"

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

PROVIDES="
	cutter$secondaryArchSuffix = $portVersion
	app:Cutter$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcapstone$secondaryArchSuffix
	lib:libgvc$secondaryArchSuffix
	lib:libpython3.9$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:librz_analysis$secondaryArchSuffix
	lib:librz_asm$secondaryArchSuffix
	lib:librz_bin$secondaryArchSuffix
	lib:librz_bp$secondaryArchSuffix
	lib:librz_config$secondaryArchSuffix
	lib:librz_cons$secondaryArchSuffix
	lib:librz_core$secondaryArchSuffix
	lib:librz_crypto$secondaryArchSuffix
	lib:librz_debug$secondaryArchSuffix
	lib:librz_diff$secondaryArchSuffix
	lib:librz_egg$secondaryArchSuffix
	lib:librz_flag$secondaryArchSuffix
	lib:librz_hash$secondaryArchSuffix
	lib:librz_io$secondaryArchSuffix
	lib:librz_lang$secondaryArchSuffix
	lib:librz_magic$secondaryArchSuffix
	lib:librz_main$secondaryArchSuffix
	lib:librz_parse$secondaryArchSuffix
	lib:librz_reg$secondaryArchSuffix
	lib:librz_search$secondaryArchSuffix
	lib:librz_socket$secondaryArchSuffix
	lib:librz_syscall$secondaryArchSuffix
	lib:librz_type$secondaryArchSuffix 
	lib:libssl$secondaryArchSuffix
	lib:libtree_sitter$secondaryArchSuffix
	lib:libuv$secondaryArchSuffix
	lib:libxxhash$secondaryArchSuffix
	lib:liblz4$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzip$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcapstone$secondaryArchSuffix
	devel:libgvc$secondaryArchSuffix
	devel:libpython3.9$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:librz_analysis$secondaryArchSuffix
	devel:librz_asm$secondaryArchSuffix
	devel:librz_bin$secondaryArchSuffix
	devel:librz_bp$secondaryArchSuffix
	devel:librz_config$secondaryArchSuffix
	devel:librz_cons$secondaryArchSuffix
	devel:librz_core$secondaryArchSuffix
	devel:librz_crypto$secondaryArchSuffix
	devel:librz_debug$secondaryArchSuffix
	devel:librz_diff$secondaryArchSuffix
	devel:librz_egg$secondaryArchSuffix
	devel:librz_flag$secondaryArchSuffix
	devel:librz_hash$secondaryArchSuffix
	devel:librz_io$secondaryArchSuffix
	devel:librz_lang$secondaryArchSuffix
	devel:librz_magic$secondaryArchSuffix
	devel:librz_main$secondaryArchSuffix
	devel:librz_parse$secondaryArchSuffix
	devel:librz_reg$secondaryArchSuffix
	devel:librz_search$secondaryArchSuffix
	devel:librz_socket$secondaryArchSuffix
	devel:librz_syscall$secondaryArchSuffix
	devel:librz_type$secondaryArchSuffix 
	devel:libssl$secondaryArchSuffix
	devel:libtree_sitter$secondaryArchSuffix
	devel:libuv$secondaryArchSuffix
	devel:libxxhash$secondaryArchSuffix
	devel:liblz4$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzip$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3.9
	cmd:qmake$secondaryArchSuffix >= 5
	"

BUILD()
{
	cp -rf $sourceDir2/cutter-translations-$srcGitRev_2/* src/translations

	cmake -B build -S . -DCMAKE_BUILD_TYPE=Release \
		$cmakeDirArgs \
		-DCMAKE_INSTALL_BINDIR=$appsDir \
		-DCUTTER_ENABLE_PYTHON=ON \
		-DCUTTER_USE_BUNDLED_RIZIN=OFF \
		-DCMAKE_CXX_FLAGS="-fpermissive"

	make -C build $jobArgs
}

INSTALL()
{
	make -C build install
	mv $appsDir/cutter $appsDir/Cutter

	# we are not linux
	rm -rf $prefix/share

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/cutter.rdef.in > cutter.rdef

	addResourcesToBinaries cutter.rdef \
		$appsDir/Cutter

	addAppDeskbarSymlink $appsDir/Cutter
}
