SUMMARY="American fuzzy lop, a security-oriented fuzzer"
DESCRIPTION="A fork of AFL, the popular compile-time instrumentation fuzzer"
HOMEPAGE="https://aflplus.plus/"
COPYRIGHT="2013-2016 Google Inc.
	2013-2016 Michał Zalewski
	2017-2021 Marc Heuse
	2017-2021 Heiko Eißfeldt
	2017-2021 Andrea Fioraldi
	2017-2021 Dominik Maier"
LICENSE="Apache v2"
REVISION="4"
SOURCE_URI="https://github.com/AFLplusplus/AFLplusplus/archive/refs/tags/$portVersion.tar.gz"
CHECKSUM_SHA256="0240d34a2f99d157063e31d0c2d2801a68bc015e09187d9cc197637ec8fda635"
SOURCE_FILENAME="aflplusplus-$portVersion.tar.gz"
SOURCE_DIR="AFLplusplus-$portVersion"
# Imported also Gentoo patches
PATCHES="aflplusplus-$portVersion.patchset
	aflplusplus-3.0c-CFLAGS.patch
	aflplusplus-3.0c-LDFLAGS.patch"
ADDITIONAL_FILES="create-aflplusplus-directory.sh"

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

POST_INSTALL_SCRIPTS="
	$relativePostInstallDir/create-aflplusplus-directory.sh
	"

PROVIDES="
	aflplusplus$secondaryArchSuffix = $portVersion
	cmd:afl_analyze = $portVersion
	cmd:afl_c++ = $portVersion
	cmd:afl_cc = $portVersion
	cmd:afl_clang++ = $portVersion
	cmd:afl_clang = $portVersion
	cmd:afl_cmin = $portVersion
	cmd:afl_cmin.bash = $portVersion
	cmd:afl_fuzz = $portVersion
	cmd:afl_g++ = $portVersion
	cmd:afl_gcc = $portVersion
	cmd:afl_gotcpu = $portVersion
	cmd:afl_plot = $portVersion
	cmd:afl_showmap = $portVersion
	cmd:afl_system_config = $portVersion
	cmd:afl_tmin = $portVersion
	cmd:afl_whatsup = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libpython3.7m$secondaryArchSuffix
	lib:libLLVM_9$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	gcc${secondaryArchSuffix}_syslibs_devel
	devel:libgmp$secondaryArchSuffix
	devel:libLLVM_9$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gawk
	cmd:clang >= 9.0.1
	cmd:make
	cmd:gcc$secondaryArchSuffix
	"

TEST_REQUIRES="
	cmd:diff
	devel:libcmocka$secondaryArchSuffix
	"

PATCH()
{
	# grabbed from Gentoo port
	sed -i -e 's/-O3 -fno-unroll-loops//' GNUmakefile
}

makeAfl()
{
	make -f GNUmakefile \
		PREFIX=$prefix \
		BIN_PATH=$prefix/bin \
		HELPER_PATH=$libDir/afl \
		DOC_PATH=$docDir \
		MISC_PATH=$dataDir/afl \
		MAN_PATH=$manDir/man8 \
		"$@" V=1
}

BUILD()
{
	makeAfl $jobArgs
}

INSTALL()
{
	makeAfl install
	mkdir -p $postInstallDir
	cp -f $portDir/additional-files/create-aflplusplus-directory.sh $postInstallDir
}

TEST()
{
	make tests
}
