SUMMARY="The OpenSource Disassembler"
DESCRIPTION="REDasm is a cross platform disassembler with a modern codebase useful from the hobbist to the professional reverse engineer"
HOMEPAGE="https://redasm.io/"
COPYRIGHT="Antonio Davide"
LICENSE="GNU GPL v3
	GNU LGPL v3"
REVISION="1"
SOURCE_URI="https://github.com/REDasmOrg/REDasm/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="2fdd97822279791688b761af66564429727867523cfc31c7018da54d101f0ce3"
SOURCE_DIR="REDasm-$portVersion"
srcGitRev_2="b59bdc39df31bf9696823b8fd36d8ca8b3a0e49e"
SOURCE_URI_2="https://github.com/REDasmOrg/REDasm-Library/archive/$srcGitRev_2.tar.gz"
CHECKSUM_SHA256_2="aa5ee27519bcfdc7463d5b4fe79282d43423e899830b96ad5550a503919d481e"
SOURCE_FILENAME_2="REDasm-Library-$srcGitRev_2.tar.gz"
srcGitRev_3="4524ca368221c2883a0743d77412fbcfe6fe457b"
SOURCE_URI_3="https://github.com/Dax89/QHexView/archive/$srcGitRev_3.tar.gz"
CHECKSUM_SHA256_3="8f577a96342c1104e6566beb4d7d47eed5935f2ce5fd25a21230fa0919f8c4d6"
SOURCE_FILENAME_3="QHexView-$srcGitRev_3.tar.gz"
srcGitRev_4="4948fd1b56bb32634ec17d214de99bda7db410eb"
SOURCE_URI_4="https://github.com/aquynh/capstone/archive/$srcGitRev_4.tar.gz"
CHECKSUM_SHA256_4="f68af0b8ee3181fac19e986920a4dbd020bd1bf7db127a91000ee05971215b7b"
SOURCE_FILENAME_4="capstone-$srcGitRev_4.tar.gz"

PATCHES="redasm-$portVersion.patchset"
PATCHES_2="redasm-$portVersion-libredasm.patchset"

ADDITIONAL_FILES="
	redasm.rdef.in
	icons.zip
	"

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

PROVIDES="
	redasm$secondaryArchSuffix = $portVersion
	app:REDasm = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:cmake
	cmd:make
	"

PATCH()
{
	unzip -o $sourceDir/../../additional-files/icons.zip -d $sourceDir/res
}

BUILD()
{
	# link submodules
	rm -rf $sourceDir/LibREDasm
	ln -sfn $sourceDir2/REDasm-Library-$srcGitRev_2 $sourceDir/LibREDasm
	rm -rf $sourceDir/QHexView
	ln -sfn $sourceDir3/QHexView-$srcGitRev_3 $sourceDir/QHexView
	rm -rf $sourceDir/LibREDasm/depends/capstone
	ln -sfn $sourceDir4/capstone-$srcGitRev_4 $sourceDir/LibREDasm/depends/capstone

	mkdir -p build
	cd build

	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$appsDir/REDasm \
		-DCMAKE_BUILD_TYPE=Release

	make $jobArgs
}

INSTALL()
{
	mkdir -p  $appsDir/REDasm/lib
	cp build/REDasm $appsDir/REDasm
	cp build/LibREDasm.so $appsDir/REDasm/lib

	local APP_SIGNATURE="application/x-vnd.redasm"
	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/redasm.rdef.in > $sourceDir/redasm.rdef

	addResourcesToBinaries $sourceDir/redasm.rdef $appsDir/REDasm/REDasm
	addAppDeskbarSymlink $appsDir/REDasm/REDasm
}
