Subject: [bug#64304] [PATCH] gnu: a2jmidid: Fix building on riscv64-linux and use gexp.

From: Z572 <[email-masked]>
Date: Tue, 27 Jun 2023 00:56:23 +0800

* gnu/packages/music.scm(a2jmidid)[source]: add patch.
[arguments]: Use gexps.
* gnu/packages/patches/a2jmidid-enable-riscv-build.patch: new file.
* gnu/local.mk: register it.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/music.scm                        | 27 ++++++------
 .../patches/a2jmidid-enable-riscv-build.patch | 44 +++++++++++++++++++
 3 files changed, 59 insertions(+), 13 deletions(-)
 create mode 100644 gnu/packages/patches/a2jmidid-enable-riscv-build.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 4566f1b4a4..6833df10db 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -872,6 +872,7 @@ MODULES_NOT_COMPILED +=				\
 
 patchdir = $(guilemoduledir)/%D%/packages/patches
 dist_patch_DATA =						\
+  %D%/packages/patches/a2jmidid-enable-riscv-build.patch	\
   %D%/packages/patches/abcl-fix-build-xml.patch	\
   %D%/packages/patches/ableton-link-system-libraries-debian.patch	\
   %D%/packages/patches/abiword-explictly-cast-bools.patch	\
diff --git a/gnu/packages/music.scm b/gnu/packages/music.scm
index 5069e6f0df..9017966f2f 100644
--- a/gnu/packages/music.scm
+++ b/gnu/packages/music.scm
@@ -54,6 +54,7 @@
 ;;; Copyright © 2023 Antero Mejr <[email-masked]>
 ;;; Copyright © 2023 Sharlatan Hellseher <[email-masked]>
 ;;; Copyright © 2023 Yovan Naumovski <[email-masked]>
+;;; Copyright © 2023 Zheng Junjie <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -7014,20 +7015,20 @@ (define-public a2jmidid
                     (commit version)))
               (sha256
                (base32 "1x6rcl3f4nklnx4p5jln9a7fpj9y7agjxs9rw7cccmwnski7pnsq"))
-              (file-name (git-file-name name version))))
+              (file-name (git-file-name name version))
+              ;; https://github.com/jackaudio/a2jmidid/pull/18
+              (patches (search-patches "a2jmidid-enable-riscv-build.patch"))))
     (arguments
-     `(#:tests? #f      ; No tests.
-       #:phases
-       (modify-phases %standard-phases
-         (add-after 'install 'wrap-programs
-           (lambda* (#:key inputs outputs #:allow-other-keys)
-             (let* ((out (assoc-ref outputs "out"))
-                    (bin (string-append out "/bin/")))
-               (substitute* (string-append bin "a2j")
-                 (("a2j_control") (string-append bin "a2j_control")))
-               (wrap-program (string-append bin "a2j_control")
-                `("PYTHONPATH" prefix (,(getenv "GUIX_PYTHONPATH"))))
-               #t))))))
+     (list #:tests? #f      ; No tests.
+           #:phases
+           #~(modify-phases %standard-phases
+               (add-after 'install 'wrap-programs
+                 (lambda* (#:key inputs outputs #:allow-other-keys)
+                   (let ((bin (string-append #$output "/bin/")))
+                     (substitute* (string-append bin "a2j")
+                       (("a2j_control") (string-append bin "a2j_control")))
+                     (wrap-program (string-append bin "a2j_control")
+                       `("PYTHONPATH" prefix (,(getenv "GUIX_PYTHONPATH"))))))))))
     (build-system meson-build-system)
     (inputs
      (list alsa-lib
diff --git a/gnu/packages/patches/a2jmidid-enable-riscv-build.patch b/gnu/packages/patches/a2jmidid-enable-riscv-build.patch
new file mode 100644
index 0000000000..2b9e2ed1c5
--- /dev/null
+++ b/gnu/packages/patches/a2jmidid-enable-riscv-build.patch
@@ -0,0 +1,44 @@
+From 2c3fbef6854743416d95d85b1565dde51668488c Mon Sep 17 00:00:00 2001
+From: Heinrich Schuchardt <[email-masked]>
+Date: Fri, 1 Oct 2021 16:15:29 +0200
+Subject: [PATCH] sigsegv: enable RISC-V build
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Avoid build error
+
+../sigsegv.c:104:39: error: ‘mcontext_t’ has no member named ‘gregs’;
+did you mean ‘__gregs’?
+  104 |                 ucontext->uc_mcontext.gregs[i]
+      |                                       ^~~~~
+
+Signed-off-by: Heinrich Schuchardt <[email-masked]>
+---
+ sigsegv.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/sigsegv.c b/sigsegv.c
+index fb4456e..6930185 100644
+--- a/sigsegv.c
++++ b/sigsegv.c
+@@ -91,7 +91,9 @@ static void signal_segv(int signum, siginfo_t* info, void*ptr) {
+     a2j_error("info.si_errno = %d", info->si_errno);
+     a2j_error("info.si_code  = %d (%s)", info->si_code, si_codes[info->si_code]);
+     a2j_error("info.si_addr  = %p", info->si_addr);
+-#if !defined(__alpha__) && !defined(__ia64__) && !defined(__FreeBSD_kernel__) && !defined(__arm__) && !defined(__hppa__) && !defined(__sh__) && !defined(__aarch64__)
++#if !defined(__alpha__) && !defined(__ia64__) && \
++    !defined(__FreeBSD_kernel__) && !defined(__arm__) && !defined(__hppa__) && \
++    !defined(__sh__) && !defined(__aarch64__) && !defined(__riscv)
+     for(i = 0; i < NGREG; i++)
+         a2j_error("reg[%02d]       = 0x" REGFORMAT, i,
+ #if defined(__powerpc__) && !defined(__powerpc64__)
+@@ -108,7 +110,7 @@ static void signal_segv(int signum, siginfo_t* info, void*ptr) {
+                 ucontext->uc_mcontext.gregs[i]
+ #endif
+                 );
+-#endif /* alpha, ia64, kFreeBSD, arm, hppa, aarch64 */
++#endif /* alpha, ia64, kFreeBSD, arm, hppa, aarch64, riscv */
+ 
+ #if defined(SIGSEGV_STACK_X86) || defined(SIGSEGV_STACK_IA64)
+ # if defined(SIGSEGV_STACK_IA64)

base-commit: 269cfe341f242c2b5f37774cb9b1e17d9aa68e2c
-- 
2.40.1