Subject: afnix: FTBFS: Add loongarch64 support

From: zhangdandan <[email-masked]>
Date: Thu, 16 Jan 2025 21:13:34 +0800

Source: afnix
Version: 3.8.0-1.1
Severity: normal
Tags: ftbfs patch
User: [email-masked]
Usertags: loong64
X-Debbugs-CC: [email-masked]

Dear maintainers,

Compiling the afnix failed for loong64 in the Debian Package 
Auto-Building environment.
The error log is as follows,
```
......
make[1]: Leaving directory '/<<PKGBUILDDIR>>'
    debian/rules override_dh_auto_build
make[1]: Entering directory '/<<PKGBUILDDIR>>'
/usr/bin/make world
make[2]: Entering directory '/<<PKGBUILDDIR>>'
make[3]: Entering directory '/<<PKGBUILDDIR>>/src'
make[4]: Entering directory '/<<PKGBUILDDIR>>/src/lib'
make[5]: Entering directory '/<<PKGBUILDDIR>>/src/lib/plt'
make[6]: Entering directory '/<<PKGBUILDDIR>>/src/lib/plt/acf'
make[6]: Leaving directory '/<<PKGBUILDDIR>>/src/lib/plt/acf'
make[6]: Entering directory '/<<PKGBUILDDIR>>/src/lib/plt/shl'
g++ -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong 
-Wformat -Werror=format-security   -g -O2 
-ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat 
-Werror=format-security -Wall -Werror -fno-builtin 
-Wno-error=overloaded-virtual -MMD -pthread -fPIC          -I. -I../acf 
-o cclk.o -c cclk.cxx
In file included from cclk.cxx:19:
cclk.hxx:25:2: error: #error "unknown processor type"
    25 | #error "unknown processor type"
       |  ^~~~~
make[6]: *** [../../../../cnf/mak/afnix-runx.mak:107: cclk.o] Error 1
make[6]: Leaving directory '/<<PKGBUILDDIR>>/src/lib/plt/shl'
```

The full build log can be found at 
https://buildd.debian.org/status/logs.php?pkg=afnix&ver=3.8.0-1.1&arch=loong64.

Please consider the patch I attached.
Based on the attached patch, I have built afnix 3.8.0-1.1+loong64 
successfully on local ENV.
```
    dh_builddeb
dpkg-deb: building package 'afnix-dbgsym' in 
'../afnix-dbgsym_3.8.0-1.1+loong64_loong64.deb'.
dpkg-deb: building package 'afnix' in 
'../afnix_3.8.0-1.1+loong64_loong64.deb'.
dpkg-deb: building package 'afnix-doc' in 
'../afnix-doc_3.8.0-1.1+loong64_all.deb'.
  dpkg-genbuildinfo -O../afnix_3.8.0-1.1+loong64_loong64.buildinfo
  dpkg-genchanges -O../afnix_3.8.0-1.1+loong64_loong64.changes
```

Best regards,
Dandan Zhang

Description: Add loongarch64 support.
 .
 afnix (3.8.0-1.1+loong64) unstable; urgency=medium
 .
   * Add loongarch64 support.
Author: Dandan Zhang <[email-masked]>

---
Last-Update: 2025-01-16

--- afnix-3.8.0.orig/cnf/bin/afnix-guess
+++ afnix-3.8.0/cnf/bin/afnix-guess
@@ -163,6 +163,7 @@ get_cpunam ()
 	    ppc)       cpunam=ppc;;
 	    ppc64le)   cpunam=ppc64el;;
 	    ppc64)     cpunam=ppc64;;
+	    loongarch64)   cpunam=loongarch64;;
 	    m68k)      cpunam=m68k;;
 	    mips)      cpunam=mips;;
 	    mipsel)    cpunam=mipsel;;
--- afnix-3.8.0.orig/src/lib/plt/acf/ccnf.cpp
+++ afnix-3.8.0/src/lib/plt/acf/ccnf.cpp
@@ -61,6 +61,7 @@
 #define AFNIX_PROCTYPE_RISCV32   19
 #define AFNIX_PROCTYPE_RISCV64   20
 #define AFNIX_PROCTYPE_PPC64     21
+#define AFNIX_PROCTYPE_LOONGARCH64     22
 
 // recognized processor name
 #define AFNIX_PROCNAME_UNKNOWN   "unknown"
@@ -71,6 +72,7 @@
 #define AFNIX_PROCNAME_PPC       "ppc"
 #define AFNIX_PROCNAME_PPC64EL   "ppc64el"
 #define AFNIX_PROCNAME_PPC64     "ppc64"
+#define AFNIX_PROCNAME_LOONGARCH64     "loongarch64"
 #define AFNIX_PROCNAME_M68K      "m68k"
 #define AFNIX_PROCNAME_MIPS      "mips"
 #define AFNIX_PROCNAME_MIPSEL    "mipsel"
@@ -155,6 +157,9 @@ static int get_procid (const char* proc)
   // ppc64el
   if (strcmp (proc, AFNIX_PROCNAME_PPC64EL) == 0)
     return AFNIX_PROCTYPE_PPC64EL;
+  // loongarch64
+  if (strcmp (proc, AFNIX_PROCNAME_LOONGARCH64) == 0)
+    return AFNIX_PROCTYPE_LOONGARCH64;
   // m68k
   if (strcmp (proc, AFNIX_PROCNAME_M68K) == 0) 
     return AFNIX_PROCTYPE_M68K;
@@ -216,6 +221,7 @@ static const char* get_procnm (const int
   if (id ==  AFNIX_PROCTYPE_AARCH64)  return AFNIX_PROCNAME_AARCH64;
   if (id ==  AFNIX_PROCTYPE_PPC)      return AFNIX_PROCNAME_PPC;
   if (id ==  AFNIX_PROCTYPE_PPC64EL)  return AFNIX_PROCNAME_PPC64EL;
+  if (id ==  AFNIX_PROCTYPE_LOONGARCH64)   return AFNIX_PROCNAME_LOONGARCH64;
   if (id ==  AFNIX_PROCTYPE_M68K)     return AFNIX_PROCNAME_M68K;
   if (id ==  AFNIX_PROCTYPE_MIPS)     return AFNIX_PROCNAME_MIPS;
   if (id ==  AFNIX_PROCTYPE_MIPSEL)   return AFNIX_PROCNAME_MIPSEL;
@@ -376,6 +382,8 @@ int main (int, char**) {
 	   AFNIX_PROCTYPE_PPC);
   fprintf (stdout, "#define  AFNIX_PROCTYPE_PPC64EL   %d\n",
 	   AFNIX_PROCTYPE_PPC64EL);
+  fprintf (stdout, "#define  AFNIX_PROCTYPE_LOONGARCH64   %d\n",
+	   AFNIX_PROCTYPE_LOONGARCH64);
   fprintf (stdout, "#define  AFNIX_PROCTYPE_M68K      %d\n",
 	   AFNIX_PROCTYPE_M68K);
   fprintf (stdout, "#define  AFNIX_PROCTYPE_MIPS      %d\n",
@@ -422,6 +430,8 @@ int main (int, char**) {
 	   AFNIX_PROCNAME_PPC);
   fprintf (stdout, "#define  AFNIX_PROCNAME_PPC64EL   \"%s\"\n",
 	   AFNIX_PROCNAME_PPC64EL);
+  fprintf (stdout, "#define  AFNIX_PROCNAME_LOONGARCH64   \"%s\"\n",
+	   AFNIX_PROCNAME_LOONGARCH64);
   fprintf (stdout, "#define  AFNIX_PROCNAME_M68K      \"%s\"\n",
 	   AFNIX_PROCNAME_M68K);
   fprintf (stdout, "#define  AFNIX_PROCNAME_MIPS      \"%s\"\n",