Bug#1057140: libemf: FTBFS: error: #error Unknown CPU architecture

2023-11-30 Thread Barak A. Pearlmutter
Thanks.

Please feel free to just fix and upload stuff like this, push fix to salsa
git repo. I absolutely don't mind. If you don't I'll get to it in a few
days.


Bug#1057140: libemf: FTBFS: error: #error Unknown CPU architecture

2023-11-30 Thread zhangdandan

Source: libemf
Version: 1.0.13-5
Severity: wishlist
Tags: patch
User: debian-loonga...@lists.debian.org
Usertags: loong64

Dear maintainers,

The package libemf failed to compile loong64 rootfs environment. The 
error messages are as follows,

```
...
In file included from ../include/libEMF/wine/windef.h:16,
 from ../include/libEMF/emf.h:27,
 from libemf.h:33,
 from libemf.cpp:24:
../include/libEMF/wine/winnt.h:77:3: error: #error Unknown CPU architecture!
   77 | # error Unknown CPU architecture!
  |   ^
../include/libEMF/wine/winnt.h:1589:16: warning: extra tokens at end of 
#ifdef directive

 1589 | #ifdef __riscv && __riscv_xlen==64
  |    ^~
../include/libEMF/wine/winnt.h:1661:2: error: #error You need to define 
a CONTEXT for your CPU

 1661 | #error You need to define a CONTEXT for your CPU
  |  ^
...
```

After applying the attached patch, the keyman source package was 
compiled successfully on my local loong64 rootfs environment.

Please consider the patch I have attached.

thanks,
Dandan Zhang

Description: Add support for loongarch64 
Last-Update: 2023-11-9

--- libemf-1.0.13.orig/include/libEMF/wine/winnt.h
+++ libemf-1.0.13/include/libEMF/wine/winnt.h
@@ -49,6 +49,10 @@
 # undef  WORDS_BIGENDIAN
 # undef  BITFIELDS_BIGENDIAN
 # undef  ALLOW_UNALIGNED_ACCESS
+#elif defined(__loongarch64)
+# undef  WORDS_BIGENDIAN
+# undef  BITFIELDS_BIGENDIAN
+# undef  ALLOW_UNALIGNED_ACCESS
 #elif defined(__sparc__)
 # define WORDS_BIGENDIAN
 # define BITFIELDS_BIGENDIAN
@@ -1024,6 +1028,76 @@ typedef struct _CONTEXT
 
 #endif  /* _ALPHA_ */
 
+#ifdef __loongarch64
+/*
+ * FIXME:
+ *
+ * There is not yet an official CONTEXT structure defined for the
+ * loongarch64 architecture (64-bit LE), so I just made one up.
+ *
+ */
+
+#define CONTEXT_LOONGARCH64 0x400
+#define CONTEXT_CONTROL (CONTEXT_LOONGARCH64 | 0x0001)
+#define CONTEXT_INTEGER (CONTEXT_LOONGARCH64 | 0x0002)
+#define CONTEXT_FLOATING_POINT  (CONTEXT_LOONGARCH64 | 0x0004)
+#define CONTEXT_DEBUG_REGISTERS (CONTEXT_LOONGARCH64 | 0x0008)
+
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER)
+
+#define EXCEPTION_READ_FAULT0
+#define EXCEPTION_WRITE_FAULT   1
+#define EXCEPTION_EXECUTE_FAULT 8
+
+typedef struct _CONTEXT {
+ULONG ContextFlags;
+
+/* This section is specified/returned if the ContextFlags word contains
+   the flag CONTEXT_INTEGER. */
+ULONGLONG X0;
+ULONGLONG X1;
+ULONGLONG X2;
+ULONGLONG X3;
+ULONGLONG X4;
+ULONGLONG X5;
+ULONGLONG X6;
+ULONGLONG X7;
+ULONGLONG X8;
+ULONGLONG X9;
+ULONGLONG X10;
+ULONGLONG X11;
+ULONGLONG X12;
+ULONGLONG X13;
+ULONGLONG X14;
+ULONGLONG X15;
+ULONGLONG X16;
+ULONGLONG X17;
+ULONGLONG X18;
+ULONGLONG X19;
+ULONGLONG X20;
+ULONGLONG X21;
+ULONGLONG X22;
+ULONGLONG X23;
+ULONGLONG X24;
+ULONGLONG X25;
+ULONGLONG X26;
+ULONGLONG X27;
+ULONGLONG X28;
+ULONGLONG X29;
+ULONGLONG X30;
+ULONGLONG X31;
+
+/* These are selected by CONTEXT_CONTROL */
+ULONGLONG Sp;
+ULONGLONG Pc;
+ULONGLONG PState;
+
+/* These are selected by CONTEXT_FLOATING_POINT */
+/* FIXME */
+} CONTEXT;
+
+#endif /* __loongarch64 */
+
 /* Mips context definitions */
 #if defined(_MIPS_) || defined(__MIPS__) || defined(__mips__)