git: 1ebb93fd8095 - main - emulators/qmc2: fix build on armv7 and arm64

From: Robert Clausecker <fuz_at_FreeBSD.org>
Date: Mon, 26 Jun 2023 23:30:41 UTC
The branch main has been updated by fuz:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1ebb93fd8095f4cc77bd8f0681580e9ef747b965

commit 1ebb93fd8095f4cc77bd8f0681580e9ef747b965
Author:     Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2023-06-25 16:55:58 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-06-26 23:30:28 +0000

    emulators/qmc2: fix build on armv7 and arm64
    
    Port now bundles LZMA with known build issues.  Import patch set from
    archivers/7-zip to fix the build on armv7 and arm64.
    
    PR:             271987
    Approved by:    portmgr (build fix blanket)
    Obtained from:  archivers/7-zip
---
 emulators/qmc2/Makefile                         |  3 +-
 emulators/qmc2/files/patch-src_lzma_7zCrc.c     | 11 +++++++
 emulators/qmc2/files/patch-src_lzma_Aes.c       | 11 +++++++
 emulators/qmc2/files/patch-src_lzma_AesOpt.c    | 38 ++++++++++++++++++++++
 emulators/qmc2/files/patch-src_lzma_CpuArch.c   | 42 +++++++++++++++++++++++++
 emulators/qmc2/files/patch-src_lzma_Sha256Opt.c | 11 +++++++
 6 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/emulators/qmc2/Makefile b/emulators/qmc2/Makefile
index dd97ba72bf37..fa4715f69d1b 100644
--- a/emulators/qmc2/Makefile
+++ b/emulators/qmc2/Makefile
@@ -1,7 +1,7 @@
 PORTNAME=	qmc2
 PORTVERSION=	0.243
 DISTVERSIONPREFIX=	v
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	emulators games
 
 MAINTAINER=	agh@riseup.net
@@ -52,6 +52,7 @@ MAKE_ARGS=	ARCH="${OPSYS}" \
 		SYSCONFDIR="${PREFIX}/etc"
 
 ALL_TARGET=	all arcade tools
+CFLAGS_aarch64=	-march=armv8-a+crc+crypto
 
 OPTIONS_DEFINE=	DOCS EXAMPLES
 DOCS_DESC=	Comprehensive qmc2 documentaion
diff --git a/emulators/qmc2/files/patch-src_lzma_7zCrc.c b/emulators/qmc2/files/patch-src_lzma_7zCrc.c
new file mode 100644
index 000000000000..17f415efdd35
--- /dev/null
+++ b/emulators/qmc2/files/patch-src_lzma_7zCrc.c
@@ -0,0 +1,11 @@
+--- src/lzma/7zCrc.c.orig	2022-04-29 08:33:05 UTC
++++ src/lzma/7zCrc.c
+@@ -71,7 +71,7 @@ UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *
+ 
+ #ifdef MY_CPU_LE
+ 
+-#if defined(MY_CPU_ARM_OR_ARM64)
++#if defined(MY_CPU_ARM64)
+ 
+ // #pragma message("ARM*")
+ 
diff --git a/emulators/qmc2/files/patch-src_lzma_Aes.c b/emulators/qmc2/files/patch-src_lzma_Aes.c
new file mode 100644
index 000000000000..9df1e0134247
--- /dev/null
+++ b/emulators/qmc2/files/patch-src_lzma_Aes.c
@@ -0,0 +1,11 @@
+--- src/lzma/Aes.c.orig	2022-04-29 08:33:05 UTC
++++ src/lzma/Aes.c
+@@ -55,7 +55,7 @@ static Byte InvS[256];
+ 
+ #ifdef MY_CPU_X86_OR_AMD64
+   #define USE_HW_AES
+-#elif defined(MY_CPU_ARM_OR_ARM64) && defined(MY_CPU_LE)
++#elif defined(MY_CPU_ARM) && defined(MY_CPU_LE)
+   #if defined(__clang__)
+     #if (__clang_major__ >= 8) // fix that check
+       #define USE_HW_AES
diff --git a/emulators/qmc2/files/patch-src_lzma_AesOpt.c b/emulators/qmc2/files/patch-src_lzma_AesOpt.c
new file mode 100644
index 000000000000..3519cc5af7ce
--- /dev/null
+++ b/emulators/qmc2/files/patch-src_lzma_AesOpt.c
@@ -0,0 +1,38 @@
+--- src/lzma/AesOpt.c.orig	2022-04-29 08:33:05 UTC
++++ src/lzma/AesOpt.c
+@@ -506,7 +506,7 @@ VAES_COMPAT_STUB (AesCtr_Code_HW)
+ #endif // ! USE_INTEL_VAES
+ 
+ 
+-#elif defined(MY_CPU_ARM_OR_ARM64) && defined(MY_CPU_LE)
++#elif defined(MY_CPU_ARM64) && defined(MY_CPU_LE)
+ 
+   #if defined(__clang__)
+     #if (__clang_major__ >= 8) // fix that check
+@@ -773,4 +773,25 @@ AES_FUNC_START2 (AesCtr_Code_HW)
+ 
+ #endif // USE_HW_AES
+ 
+-#endif // MY_CPU_ARM_OR_ARM64
++#else
++
++/* no USE_HW_AES */
++
++#pragma message("AES  HW_SW stub was used")
++
++#define AES_TYPE_keys UInt32
++#define AES_TYPE_data Byte
++
++#define AES_FUNC_START(name) \
++    void MY_FAST_CALL name(UInt32 *p, Byte *data, size_t numBlocks) \
++
++#define AES_COMPAT_STUB(name) \
++    AES_FUNC_START(name); \
++    AES_FUNC_START(name ## _HW) \
++    { name(p, data, numBlocks); }
++
++AES_COMPAT_STUB (AesCbc_Encode)
++AES_COMPAT_STUB (AesCbc_Decode)
++AES_COMPAT_STUB (AesCtr_Code)
++
++#endif
diff --git a/emulators/qmc2/files/patch-src_lzma_CpuArch.c b/emulators/qmc2/files/patch-src_lzma_CpuArch.c
new file mode 100644
index 000000000000..ae35cfdfe082
--- /dev/null
+++ b/emulators/qmc2/files/patch-src_lzma_CpuArch.c
@@ -0,0 +1,42 @@
+--- src/lzma/CpuArch.c.orig	2022-04-29 08:33:05 UTC
++++ src/lzma/CpuArch.c
+@@ -417,6 +417,31 @@ BoolInt CPU_IsSupported_AES (void) { return APPLE_CRYP
+ 
+ #include <sys/auxv.h>
+ 
++#if defined(__FreeBSD__)
++static unsigned long get_hwcap(int aux) {
++  unsigned long hwcap;
++  if (elf_aux_info(aux, &hwcap, sizeof hwcap) != 0) {
++        return 0;
++  }
++  return hwcap;
++}
++
++#ifdef MY_CPU_ARM64
++BoolInt CPU_IsSupported_CRC32(void) { return get_hwcap(AT_HWCAP) & HWCAP_CRC32; }
++BoolInt CPU_IsSupported_NEON(void) { return 1; }
++BoolInt CPU_IsSupported_SHA1(void){ return get_hwcap(AT_HWCAP) & HWCAP_SHA1; }
++BoolInt CPU_IsSupported_SHA2(void) { return get_hwcap(AT_HWCAP) & HWCAP_SHA2; }
++BoolInt CPU_IsSupported_AES(void) { return get_hwcap(AT_HWCAP) & HWCAP_AES; }
++#else /* MY_CPU_ARM */
++BoolInt CPU_IsSupported_CRC32(void) { return get_hwcap(AT_HWCAP2) & HWCAP2_CRC32; }
++BoolInt CPU_IsSupported_NEON(void) { return get_hwcap(AT_HWCAP) & HWCAP_NEON; }
++BoolInt CPU_IsSupported_SHA1(void){ return get_hwcap(AT_HWCAP2) & HWCAP2_SHA1; }
++BoolInt CPU_IsSupported_SHA2(void) { return get_hwcap(AT_HWCAP2) & HWCAP2_SHA2; }
++BoolInt CPU_IsSupported_AES(void) { return get_hwcap(AT_HWCAP2) & HWCAP2_AES; }
++#endif
++
++#else // __FreeBSD__
++
+ #define USE_HWCAP
+ 
+ #ifdef USE_HWCAP
+@@ -450,6 +475,7 @@ MY_HWCAP_CHECK_FUNC (SHA1)
+ MY_HWCAP_CHECK_FUNC (SHA2)
+ MY_HWCAP_CHECK_FUNC (AES)
+ 
++#endif // FreeBSD
+ #endif // __APPLE__
+ #endif // _WIN32
+ 
diff --git a/emulators/qmc2/files/patch-src_lzma_Sha256Opt.c b/emulators/qmc2/files/patch-src_lzma_Sha256Opt.c
new file mode 100644
index 000000000000..2a1acdccd036
--- /dev/null
+++ b/emulators/qmc2/files/patch-src_lzma_Sha256Opt.c
@@ -0,0 +1,11 @@
+--- src/lzma/Sha256Opt.c.orig	2022-04-29 08:33:05 UTC
++++ src/lzma/Sha256Opt.c
+@@ -212,7 +212,7 @@ void MY_FAST_CALL Sha256_UpdateBlocks_HW(UInt32 state[
+ 
+ #endif // USE_HW_SHA
+ 
+-#elif defined(MY_CPU_ARM_OR_ARM64)
++#elif defined(MY_CPU_ARM64)
+ 
+   #if defined(__clang__)
+     #if (__clang_major__ >= 8) // fix that check