SUMMARY="A fork of the radare2 reverse engineering framework"
DESCRIPTION="Rizin is a fork of the radare2 reverse engineering framework \
with a focus on usability, working features and code cleanliness.

Rizin is portable and it can be used to analyze binaries, disassemble code, \
debug programs, as a forensics tool, as a scriptable command-line hexadecimal \
editor able to open disk files, and much more!"
HOMEPAGE="https://github.com/rizinorg/rizin"
COPYRIGHT="2021 RizinOrg et all"
LICENSE="Apache v2
	CC-BY-SA-4.0
	CC0 1.0
	BSD (3-clause)
	GNU LGPL v3
	MIT
	MPL v1.1
	NCSA
	RSA-MD"
REVISION="1"
SOURCE_URI="https://github.com/rizinorg/rizin/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="ae607179eb289bcdd101d0db51e08658b1c57aba99155b82533f8fa587cacd86"
SOURCE_FILENAME="rizin-v$portVersion.tar.gz"

ARCHITECTURES="!x86_gcc2 x86_64"
SECONDARY_ARCHITECTURES="x86"

libVersion="0.3.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	rizin$secondaryArchSuffix = $portVersion
	cmd:rizin
	cmd:rz_agent
	cmd:rz_asm
	cmd:rz_ax
	cmd:rz_bin
	cmd:rz_diff
	cmd:rz_find
	cmd:rz_gg
	cmd:rz_hash
	cmd:rz_pm
	cmd:rz_run
	cmd:rz_sign
	cmd:rz_test
	lib:librz_analysis$secondaryArchSuffix = $portVersion
	lib:librz_asm$secondaryArchSuffix = $portVersion
	lib:librz_bin$secondaryArchSuffix = $portVersion
	lib:librz_bp$secondaryArchSuffix = $portVersion
	lib:librz_config$secondaryArchSuffix = $portVersion
	lib:librz_cons$secondaryArchSuffix = $portVersion
	lib:librz_core$secondaryArchSuffix = $portVersion
	lib:librz_crypto$secondaryArchSuffix = $portVersion
	lib:librz_debug$secondaryArchSuffix = $portVersion
	lib:librz_diff$secondaryArchSuffix = $portVersion
	lib:librz_egg$secondaryArchSuffix = $portVersion
	lib:librz_flag$secondaryArchSuffix = $portVersion
	lib:librz_hash$secondaryArchSuffix = $portVersion
	lib:librz_io$secondaryArchSuffix = $portVersion
	lib:librz_lang$secondaryArchSuffix = $portVersion
	lib:librz_magic$secondaryArchSuffix = $portVersion
	lib:librz_main$secondaryArchSuffix = $portVersion
	lib:librz_parse$secondaryArchSuffix = $portVersion
	lib:librz_reg$secondaryArchSuffix = $portVersion
	lib:librz_search$secondaryArchSuffix = $portVersion
	lib:librz_socket$secondaryArchSuffix = $portVersion
	lib:librz_syscall$secondaryArchSuffix = $portVersion
	lib:librz_type$secondaryArchSuffix = $portVersion
	lib:librz_util$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcapstone$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libexecinfo$secondaryArchSuffix
	lib:liblz4$secondaryArchSuffix
	lib:liblzma$secondaryArchSuffix
	lib:libmagic$secondaryArchSuffix
	lib:libpython3.7m$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libtree_sitter$secondaryArchSuffix
	lib:libuv$secondaryArchSuffix
	lib:libxxhash$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzip$secondaryArchSuffix
	"

PROVIDES_devel="
	rizin${secondaryArchSuffix}_devel = $portVersion
	devel:librz_analysis$secondaryArchSuffix = $portVersion
	devel:librz_asm$secondaryArchSuffix = $portVersion
	devel:librz_bin$secondaryArchSuffix = $portVersion
	devel:librz_bp$secondaryArchSuffix = $portVersion
	devel:librz_config$secondaryArchSuffix = $portVersion
	devel:librz_cons$secondaryArchSuffix = $portVersion
	devel:librz_core$secondaryArchSuffix = $portVersion
	devel:librz_crypto$secondaryArchSuffix = $portVersion
	devel:librz_debug$secondaryArchSuffix = $portVersion
	devel:librz_diff$secondaryArchSuffix = $portVersion
	devel:librz_egg$secondaryArchSuffix = $portVersion
	devel:librz_flag$secondaryArchSuffix = $portVersion
	devel:librz_hash$secondaryArchSuffix = $portVersion
	devel:librz_io$secondaryArchSuffix = $portVersion
	devel:librz_lang$secondaryArchSuffix = $portVersion
	devel:librz_magic$secondaryArchSuffix = $portVersion
	devel:librz_main$secondaryArchSuffix = $portVersion
	devel:librz_parse$secondaryArchSuffix = $portVersion
	devel:librz_reg$secondaryArchSuffix = $portVersion
	devel:librz_search$secondaryArchSuffix = $portVersion
	devel:librz_socket$secondaryArchSuffix = $portVersion
	devel:librz_syscall$secondaryArchSuffix = $portVersion
	devel:librz_type$secondaryArchSuffix = $portVersion
	devel:librz_util$secondaryArchSuffix = $portVersion
	"
REQUIRES_devel="
	rizin$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	pyyaml_python3
	devel:libcapstone$secondaryArchSuffix
	devel:libbz2$secondaryArchSuffix
	devel:libexecinfo$secondaryArchSuffix
	devel:liblz4$secondaryArchSuffix
	devel:liblzma$secondaryArchSuffix
	devel:libmagic$secondaryArchSuffix
	devel:libpython3.7m$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libtree_sitter$secondaryArchSuffix
	devel:libuv$secondaryArchSuffix
	devel:libxxhash$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzip$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:git
	cmd:make
	cmd:meson
	cmd:ninja
	cmd:gcc$secondaryArchSuffix
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	cmd:tree_sitter
	cmd:xxhsum
	"

BUILD()
{
	meson build \
		--prefix=$prefix \
		--datadir=$dataDir \
		--libdir=$libDir \
		--includedir=$includeDir \
		--mandir=$manDir \
		-D use_sys_capstone=enabled \
		-D use_sys_magic=enabled \
		-D use_sys_libzip=enabled \
		-D use_sys_zlib=enabled \
		-D use_sys_lz4=enabled \
		-D use_sys_xxhash=enabled \
		-D use_sys_openssl=enabled \
		-D use_sys_tree_sitter=enabled \
		-D use_libuv=true
	ninja -C build
}

INSTALL()
{
	ninja -C build install

	prepareInstalledDevelLibs \
		librz_analysis \
		librz_asm \
		librz_bin \
		librz_bp \
		librz_config \
		librz_cons \
		librz_core \
		librz_crypto \
		librz_debug \
		librz_diff \
		librz_egg \
		librz_flag \
		librz_hash \
		librz_io \
		librz_lang \
		librz_magic \
		librz_main \
		librz_parse \
		librz_reg \
		librz_search \
		librz_socket \
		librz_syscall \
		librz_type \
		librz_util
	fixPkgconfig

	packageEntries devel \
		$developDir
}

TEST()
{
	#some test will fail, so far 3 tests crash also
	#export PATH=$PATH/$sourceDir/build/binrz/rizzin
	meson test --no-rebuild -v -C build
}
