SUMMARY="UNIX-like reverse engineering framework and commandline tools"
DESCRIPTION="Forensics tool, scriptable commandline hexadecimal editor, \
able to open disk files, analyzing binaries in several common and less common \
formats, disassemble code for several CPU architectures, debug programs, \
attach to remote GDB servers, and much more."
HOMEPAGE="https://radare.org/"
COPYRIGHT="2007-2021 pancake
	2007-2015 Skia
	2012-2015 pof
	2008-2015 nibble
	2007-2015 ret2libc
	2009-2016 defragger
	2005-2006 Matt Mackall
	2009-2015 earada
	2009-2015 Jody Frankowski
	2009-2015 Anton Kochkov
	2011-2015 RoValles
	2009-2015 dso
	2013-2016 condret
	2012-2015 Fedor Sakharov
	2012-2015 Bhootravi
	2013-2015 th0rpe
	2015 julien (jvoisin) voisin
	2014-2015 jn
	2009-2015 montekki
	2009-2015 ninjahacker
	2015 riq
	2015 qnix
	2015 danielps
	2015 dkreuter
	2015 ampotos
	2008 Anant Narayanan
	2008-2015 inisider
	2015 nodepad
	2008-2013 xvilka
	2013-2015 sghctoma
	2013-2014 batchdrake
	2010-2015 Adam Pridgen
	2010-2013 eloi
	2014 jfrankowski
	2009-2015 The Lemon Man
	2013-2015 fenugrec
	2004 Philippe Biondi
	2015 aaronpuchert
	2010-2015 dark_k3y
	2015 Felix Held
	2012-2013 Alexander
	2014 Jonathan Neuschöfer
	2016 bobby.smiles
	2015-2016 oddcoder
	2009-2016 Alexandru Caciulescu
	2015-2016 javierprtd
	2016 SkUaTeR
	2009-2016 madprogrammer
	2016 moritz
	2016 n4x0r
	2016 soez
	2013 Daniel Holden
	2010 Bean Lee
	2014-2016 defragger
	2014-2016 madprogrammer
	1986-2016 Free Software Foundation, Inc.
	2005 QNX Software Systems.
	2001-2004 Fabrice Bellard
	2009 Intel Corporation
	1988-2004 Keith Packard
	1988-2004 Bart Massey
	2007-2015 dso
	2002-2013 Vivek Thampi
	1999-2013 Dieter Baron and Thomas Klausner
	1995-2013 Jean-loup Gailly
	2012 Alexander Demin
	2005 Jan Wilmans
	2002-2009 Bas Wijnen
	2014-2016 condret
	2016 unlogic
	2012 Karl Hobley
	2007 Vanya A. Sergeev
	2007-2012 Synopsys Inc
	1994-1995 Myricom, Inc.
	1986-1995 Ian F. Darwin
	2003 Christos Zoulas
	1992-1994 Henry Spencer
	2011 Remy Oukaour
	2000-2001 Markus Friedl
	2008 Nadia Heninger
	2008 J. Alex Halderman
	2003-2010 University of Illinois at Urbana-Champaign
	1987-1994 The Regents of the University of California
	2000-2001 Aaron D. Gifford
	1991-1992 RSA Data Security, Inc.
	2012 Yann Collet
	1995-1999 Cryptography Research, Inc. All
	1997-1998 Andrew Tridgell
	2002-2003 Steve French
	2010-2016 Sebastian Reichel"
LICENSE="GNU GPL v3
	GNU LGPL v3"
REVISION="3"
SOURCE_URI="https://github.com/radare/radare2/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="21ddae80a18d5ceef4bcd3a7cae1ba09d14b510d68ac9134681e1e9967123b23"

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

commandBinDir=$binDir
commandSuffix=$secondaryArchSuffix
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandBinDir=$prefix/bin
	commandSuffix=
fi

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

PROVIDES="
	radare2$secondaryArchSuffix = $portVersion
	cmd:r2$commandSuffix = $portVersion
	cmd:r2agent$commandSuffix = $portVersion
	cmd:r2p$commandSuffix = $portVersion
	cmd:r2pm$commandSuffix = $portVersion
	cmd:r2r$commandSuffix = $portVersion
	cmd:rabin2$commandSuffix = $portVersion
	cmd:radare2$commandSuffix = $portVersion
	cmd:radiff2$commandSuffix = $portVersion
	cmd:rafind2$commandSuffix = $portVersion
	cmd:ragg2$commandSuffix = $portVersion
	cmd:ragg2_cc$commandSuffix = $portVersion
	cmd:rahash2$commandSuffix = $portVersion
	cmd:rasign2$commandSuffix = $portVersion
	cmd:rarun2$commandSuffix = $portVersion
	cmd:rasm2$commandSuffix = $portVersion
	cmd:ravc2$commandSuffix = $portVersion
	cmd:rax2$commandSuffix = $portVersion
	lib:libr_anal$secondaryArchSuffix = $libVersionCompat
	lib:libr_asm$secondaryArchSuffix = $libVersionCompat
	lib:libr_bin$secondaryArchSuffix = $libVersionCompat
	lib:libr_bp$secondaryArchSuffix = $libVersionCompat
	lib:libr_config$secondaryArchSuffix = $libVersionCompat
	lib:libr_cons$secondaryArchSuffix = $libVersionCompat
	lib:libr_core$secondaryArchSuffix = $libVersionCompat
	lib:libr_crypto$secondaryArchSuffix = $libVersionCompat
	lib:libr_debug$secondaryArchSuffix = $libVersionCompat
	lib:libr_egg$secondaryArchSuffix = $libVersionCompat
	lib:libr_flag$secondaryArchSuffix = $libVersionCompat
	lib:libr_fs$secondaryArchSuffix = $libVersionCompat
	lib:libr_hash$secondaryArchSuffix = $libVersionCompat
	lib:libr_io$secondaryArchSuffix = $libVersionCompat
	lib:libr_lang$secondaryArchSuffix = $libVersionCompat
	lib:libr_magic$secondaryArchSuffix = $libVersionCompat
	lib:libr_main$secondaryArchSuffix = $libVersionCompat
	lib:libr_parse$secondaryArchSuffix = $libVersionCompat
	lib:libr_reg$secondaryArchSuffix = $libVersionCompat
	lib:libr_search$secondaryArchSuffix = $libVersionCompat
	lib:libr_socket$secondaryArchSuffix = $libVersionCompat
	lib:libr_syscall$secondaryArchSuffix = $libVersionCompat
	lib:libr_util$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcapstone$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libexecinfo$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libmagic$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libxxhash$secondaryArchSuffix
	"

PROVIDES_devel="
	radare2${secondaryArchSuffix}_devel = $portVersion
	devel:arm64dis$secondaryArchSuffix
	devel:libr_anal$secondaryArchSuffix = $libVersionCompat
	devel:libr_asm$secondaryArchSuffix = $libVersionCompat
	devel:libr_bin$secondaryArchSuffix = $libVersionCompat
	devel:libr_bp$secondaryArchSuffix = $libVersionCompat
	devel:libr_config$secondaryArchSuffix = $libVersionCompat
	devel:libr_cons$secondaryArchSuffix = $libVersionCompat
	devel:libr_core$secondaryArchSuffix = $libVersionCompat
	devel:libr_crypto$secondaryArchSuffix = $libVersionCompat
	devel:libr_debug$secondaryArchSuffix = $libVersionCompat
	devel:libr_egg$secondaryArchSuffix = $libVersionCompat
	devel:libr_flag$secondaryArchSuffix = $libVersionCompat
	devel:libr_fs$secondaryArchSuffix = $libVersionCompat
	devel:libr_hash$secondaryArchSuffix = $libVersionCompat
	devel:libr_io$secondaryArchSuffix = $libVersionCompat
	devel:libr_lang$secondaryArchSuffix = $libVersionCompat
	devel:libr_magic$secondaryArchSuffix = $libVersionCompat
	devel:libr_main$secondaryArchSuffix = $libVersionCompat
	devel:libr_parse$secondaryArchSuffix = $libVersionCompat
	devel:libr_reg$secondaryArchSuffix = $libVersionCompat
	devel:libr_search$secondaryArchSuffix = $libVersionCompat
	devel:libr_socket$secondaryArchSuffix = $libVersionCompat
	devel:libr_syscall$secondaryArchSuffix = $libVersionCompat
	devel:libr_util$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	radare2${secondaryArchSuffix} == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcapstone$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libexecinfo$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:liblua$secondaryArchSuffix
	devel:libmagic$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libxxhash$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:git
	cmd:make
	cmd:sh
	cmd:patch
	cmd:pkg_config$secondaryArchSuffix
	"

# What happend with libr2.so?
defineDebugInfoPackage radare2$secondaryArchSuffix \
	"$commandBinDir"/r2agent \
	"$commandBinDir"/rabin2 \
	"$commandBinDir"/radare2 \
	"$commandBinDir"/radiff2 \
	"$commandBinDir"/rafind2 \
	"$commandBinDir"/ragg2 \
	"$commandBinDir"/rahash2 \
	"$commandBinDir"/rarun2 \
	"$commandBinDir"/rasm2 \
	"$commandBinDir"/ravc2\
	"$commandBinDir"/rax2 \
	"$libDir"/libr_anal.so.$libVersion \
	"$libDir"/libr_asm.so.$libVersion \
	"$libDir"/libr_bin.so.$libVersion \
	"$libDir"/libr_bp.so.$libVersion \
	"$libDir"/libr_config.so.$libVersion \
	"$libDir"/libr_cons.so.$libVersion \
	"$libDir"/libr_core.so.$libVersion \
	"$libDir"/libr_crypto.so.$libVersion \
	"$libDir"/libr_debug.so.$libVersion \
	"$libDir"/libr_egg.so.$libVersion \
	"$libDir"/libr_flag.so.$libVersion \
	"$libDir"/libr_fs.so.$libVersion \
	"$libDir"/libr_hash.so.$libVersion \
	"$libDir"/libr_io.so.$libVersion \
	"$libDir"/libr_lang.so.$libVersion \
	"$libDir"/libr_magic.so.$libVersion \
	"$libDir"/libr_main.so.$libVersion \
	"$libDir"/libr_parse.so.$libVersion \
	"$libDir"/libr_reg.so.$libVersion \
	"$libDir"/libr_search.so.$libVersion \
	"$libDir"/libr_socket.so.$libVersion \
	"$libDir"/libr_syscall.so.$libVersion \
	"$libDir"/libr_util.so.$libVersion

BUILD()
{
	CFLAGS="-lbsd" LDFLAGS="-lbsd" \
		runConfigure --omit-dirs docdir,datarootdir,bindir ./configure \
		--bindir=$commandBinDir \
		--with-sysmagic \
		--with-syscapstone \
		--with-sysxxhash \
		--with-openssl
	make $jobArgs
}

INSTALL()
{
	make install
	cp libr/*/libr_*.so $libDir

	mkdir -p `dirname $docDir`
	mv $prefix/data/radare2 $docDir
	rm -rf $prefix/share

	prepareInstalledDevelLibs arm64dis libr_anal libr_asm libr_bin \
	libr_bp libr_config libr_cons libr_core libr_crypto libr_debug libr_egg \
	libr_flag libr_fs libr_hash libr_io libr_lang libr_magic libr_main \
	libr_parse libr_reg libr_search libr_socket libr_syscall libr_util

	fixPkgconfig

	packageEntries devel \
		$developDir
}

TEST()
{
	# Be warned, it will clone the regressions repo with git.
	# It will try to use the installed radare2 executable, which is
	# not available in PATH in chroot.
	make tests
}
