feather/contrib/depends/patches/sodium/ac.patch
2022-12-21 16:21:27 +01:00

110 lines
3.6 KiB
Diff

diff --git a/configure.ac b/configure.ac
index 9e2de27c..6b17c020 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,10 @@ AS_IF([pwd | fgrep ' ' > /dev/null 2>&1],
[AC_MSG_ERROR([The build directory contains whitespaces - This can cause tests/installation to fail due to limitations of some libtool versions])]
)
+AC_PROG_CC_C99
+AM_PROG_AS
+AC_USE_SYSTEM_EXTENSIONS
+
dnl Switches
AC_ARG_ENABLE(ssp,
@@ -210,17 +214,11 @@ AX_VALGRIND_CHECK
dnl Checks
-AC_PROG_CC_C99
-AM_PROG_AS
-AC_USE_SYSTEM_EXTENSIONS
AC_C_VARARRAYS
AC_CHECK_DEFINE([__wasi__], [WASI="yes"], [])
-AC_CHECK_DEFINE([_FORTIFY_SOURCE], [], [
- AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=2],
- [CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"])
-])
+AS_CASE([$host_os], [linux-gnu], [AX_ADD_FORTIFY_SOURCE], [ ])
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
[CFLAGS="$CFLAGS -fvisibility=hidden"])
@@ -343,9 +341,11 @@ AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wwrite-strings], [CWFLAGS="$CWFLAGS -Wwrite-strings"])
-AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
-AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
-AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
+AS_IF([test "x$EMSCRIPTEN" = "x"], [
+ AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
+ AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
+ AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
+])
AX_CHECK_CATCHABLE_SEGV
AX_CHECK_CATCHABLE_ABRT
@@ -362,10 +362,51 @@ AC_SUBST(LIBTOOL_DEPS)
AC_ARG_VAR([AR], [path to the ar utility])
AC_CHECK_TOOL([AR], [ar], [ar])
-dnl Checks for headers
+dnl Checks for headers and codegen feature flags
+
+target_cpu_aarch64=no
+AC_MSG_CHECKING(for ARM64 target)
+AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([
+#ifndef __aarch64__
+#error Not aarch64
+#endif
+#include <arm_neon.h>
+ ], [(void) 0])],
+ [AC_MSG_RESULT(yes)
+ target_cpu_aarch64=yes],
+ [AC_MSG_RESULT(no)
+ target_cpu_aarch64=no])
AS_IF([test "x$EMSCRIPTEN" = "x"], [
+ AS_IF([test "x$target_cpu_aarch64" = "xyes"], [
+ have_armcrypto=no
+ AC_MSG_CHECKING(for ARM crypto instructions set)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <arm_neon.h>]], [[ vaeseq_u8(vmovq_n_u8(0), vmovq_n_u8(__ARM_FEATURE_CRYPTO)) ]])],
+ [
+ AC_MSG_RESULT(yes)
+ have_armcrypto=yes
+ ],
+ [
+ AC_MSG_RESULT(no)
+ oldcflags="$CFLAGS"
+ AX_CHECK_COMPILE_FLAG([-march=armv8-a+crypto], [
+ CFLAGS="$CFLAGS -march=armv8-a+crypto"
+ AC_MSG_CHECKING(for ARM crypto instructions set with -march=armv8-a+crypto)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <arm_neon.h>]], [[ vaeseq_u8(vmovq_n_u8(0), vmovq_n_u8(__ARM_FEATURE_CRYPTO)) ]])],
+ [
+ AC_MSG_RESULT(yes)
+ have_armcrypto=yes
+ CFLAGS_ARMCRYPTO="-march=armv8-a+crypto"
+ ],
+ [AC_MSG_RESULT(no)])
+ CFLAGS="$oldcflags"
+ ])
+ ])
+ AS_IF([test "$have_armcrypto" = "yes"],[AC_DEFINE([HAVE_ARMCRYPTO], [1], [ARM crypto extensions are available])])
+ ])
+
oldcflags="$CFLAGS"
AX_CHECK_COMPILE_FLAG([-mmmx], [CFLAGS="$CFLAGS -mmmx"])
AC_MSG_CHECKING(for MMX instructions set)
@@ -542,6 +583,7 @@ __m512i y = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7),
])
+AC_SUBST(CFLAGS_ARMCRYPTO)
AC_SUBST(CFLAGS_MMX)
AC_SUBST(CFLAGS_SSE2)
AC_SUBST(CFLAGS_SSE3)