#!/bin/sh
exec >&2
printf "[libwolfsslcpu-crypto] Checking for Arm v8-A Cryptographic Extension support: "
if [ -n "${IPKG_INSTROOT}" ]; then
    printf "...[offline]... "
    eval "$(grep '^DISTRIB_TARGET=' "${IPKG_INSTROOT}/etc/openwrt_release")"
    echo "${DISTRIB_TARGET}" | grep '^bcm27xx/.*' > /dev/null && {
	echo "not supported"
	echo "Error: Target ${DISTRIB_TARGET} does not support Arm Cryptographic Extension."
	echo "Install the regular libwolfssl package instead of libwolfsslcpu-crypto."
	exit 1
    }
else
    grep -q '^Features.*\baes\b' /proc/cpuinfo || {
	echo "not supported"
	echo "Error: Arm v8-A Cryptographic Extension not supported."
	echo "Install the regular libwolfssl package instead of libwolfsslcpu-crypto."
	echo "Contents of /proc/cpuinfo:"
	cat /proc/cpuinfo
	exit 1
    }
fi
echo OK
exit 0
