# Maintainer (aur): GI Jack <GI_Jack@hackermail.com>
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>

# parabola changes and rationale:
# - Added armv7h and i686 architectures
# - Added workaround for -fvar-tracking-assignments being in the
#   default /etc/makepkg.conf
# - Added depends=('lld' 'llvm') to be able to build llvm-lto

pkgname=aflplusplus
pkgver=4.00c
pkgrel=6
pkgdesc="afl++ is afl with community patches, AFLfast power schedules, qemu 3.1 upgrade + laf-intel support, MOpt mutators, InsTrim instrumentation, unicorn_mode and a lot more!"
arch=('armv7h' 'i686' 'x86_64')
url="https://github.com/AFLplusplus/AFLplusplus"
license=('Apache')
provides=('afl')
conflicts=('afl')
depends=('clang' 'lld')
makedepends=('llvm' 'python')
optdepends=('qemu: use QEMU with afl')
source=("https://github.com/AFLplusplus/AFLplusplus/archive/${pkgver}.tar.gz")
sha256sums=('f427294ed674e37d34a1b756a2190de17937e046ef21abb3ae37bba018a760f1')

# The Arch Linux wiki page on clang[1] has the following:
# "If you are building with debug, also remove
# -fvar-tracking-assignments from DEBUG_CFLAGS and DEBUG_CXXFLAGS as
# Clang does not support it."
# [1]https://wiki.archlinux.org/title/Clang
# And -fvar-tracking-assignments is by default in /etc/makepkg.conf
#
# And without that fix we have the following compilation error:
#     clang-13: error: unknown argument: '-fvar-tracking-assignments'
#     [...]
#     [-] Compiling afl-cc failed. You seem not to have a working compiler.
#     [...]
#     ==> ERROR: A failure occurred in build().
#
DEBUG_CFLAGS="$(echo ${DEBUG_CFLAGS} | sed 's/-fvar-tracking-assignments//')"
DEBUG_CXXFLAGS="$(echo ${DEBUG_CXXFLAGS} | sed 's/-fvar-tracking-assignments//')"

export DEBUG_CFLAGS
export DEBUG_CXXFLAGS

prepare() {
  cd "AFLplusplus-${pkgver}"
  make clean
}

build() {
  cd "AFLplusplus-${pkgver}"
  make PREFIX="/usr"
}

package() {
  cd "AFLplusplus-${pkgver}"
  make install PREFIX="/usr" DESTDIR="${pkgdir}"
}

