Subject: bug#50299: [PATCH v5 10/24] gnu: swi-prolog: Correct reference to 'bin/swi-prolog'.

From: Maxime Devos <[email-masked]>
Date: Fri, 4 Mar 2022 13:01:05 +0000

* gnu/packages/prolog.scm
  (swi-prolog)[arguments]<#:phases>{fix-cross-references}: New phase.
---
 gnu/packages/prolog.scm | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/gnu/packages/prolog.scm b/gnu/packages/prolog.scm
index 00f09b49cc..86ac2c2bb1 100644
--- a/gnu/packages/prolog.scm
+++ b/gnu/packages/prolog.scm
@@ -120,19 +120,30 @@ manner.  It also features an interactive interpreter.")
            "-DINSTALL_DOCUMENTATION=ON"
            "-DSWIPL_INSTALL_IN_LIB=OFF") ; FIXME: Breaks RUNPATH validation.
        #:phases
-       (modify-phases %standard-phases
-         ;; XXX: Delete the test phase that attempts to write to the
-         ;; immutable store.
-         (add-after 'unpack 'delete-failing-tests
-           (lambda _
-             (substitute* "src/CMakeLists.txt"
-               ((" save") ""))
-             (substitute* "src/test.pl"
-               (("testdir\\('Tests/save'\\).") ""))
-             (with-directory-excursion "src/Tests"
-               (for-each delete-file-recursively
-                         '("save")))
-             #t)))))
+       ,#~(modify-phases %standard-phases
+            ;; XXX: Delete the test phase that attempts to write to the
+            ;; immutable store.
+            (add-after 'unpack 'delete-failing-tests
+              (lambda _
+                (substitute* "src/CMakeLists.txt"
+                  ((" save") ""))
+                (substitute* "src/test.pl"
+                  (("testdir\\('Tests/save'\\).") ""))
+                (with-directory-excursion "src/Tests"
+                  (for-each delete-file-recursively
+                            '("save")))
+                #t))
+            #$@(if (%current-target-system)
+                   ;; Prevent man_server.pl and swipl-lfr.pl from keeping a
+                   ;; reference to the native swi-prolog.
+                   ;; FIXME: libswipl.so and swipl-ld keep a reference to the
+                   ;; cross-compiler.
+                   #~((add-after 'install 'fix-cross-references
+                        (lambda _
+                          (define bin `(,(string-append #$output "/bin")))
+                          (for-each (lambda (file) (patch-shebang file bin))
+                                    (find-files #$output ".pl$")))))
+                   #~()))))
     (native-inputs
      `(,@(if (%current-target-system)
              (begin
-- 
2.30.2