Subject: [PATCH 2/2] WIP failing attempt to get the man page while cross-compiling

From: Attila Lendvai <[email-masked]>
Date: Fri, 24 Feb 2023 15:07:42 +0100

---
 gnu/packages/admin.scm | 48 +++++++++++++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index 91f98bf48e..6e5082e612 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -343,7 +343,7 @@ (define-public shepherd-0.9
               (sha256
                (base32 "1pvdpx2mfki8wvhcac54p8fn5idqszicww60ikswszz2cv5d0s11"))))
     (arguments
-     (list #:configure-flags #~'("--localstatedir=/var")
+     (list #:configure-flags #~'("HELP2MAN=true --localstatedir=/var")
            #:make-flags #~'("GUILE_AUTO_COMPILE=0")
            #:phases (if (%current-target-system)
                         #~(modify-phases %standard-phases
@@ -359,17 +359,45 @@ (define-public shepherd-0.9
                                   (("%FIBERS_OBJECT_DIRECTORY%")
                                    #$(file-append
                                       (this-package-input "guile-fibers")
-                                      "/lib/guile/3.0/site-ccache"))))))
+                                      "/lib/guile/3.0/site-ccache")))))
+                            (add-after 'configure 'copy-man-pages
+                              (lambda* (#:key outputs native-inputs #:allow-other-keys)
+                                ;; Cannot run help2man when cross-compiling,
+                                ;; so let's copy the man pages from the native
+                                ;; build.
+                                (let ((gzip (search-input-file native-inputs
+                                                               "bin/gzip")))
+                                  ;; TODO
+                                  (pk #$(file-append
+                                         (this-package-input this-package)
+                                         "/man/shepherd.1.gz"))
+                                  (invoke gzip "--decompress" "--stdout"
+                                          #$(file-append
+                                             (this-package-input this-package)
+                                             "/man/shepherd.1.gz")
+                                          ">doc/shepherd.1"))
+                                #;(copy-file #$(file-append
+                                              (this-package-input this-package)
+                                              "/man/shepherd.1")
+                                           (string-append
+                                            (assoc-ref outputs "out")
+                                            "/man/shepherd.1"))
+                                #f)))
                         #~%standard-phases)))
     (native-inputs
-     (list autoconf
-           automake
-           gettext-minimal
-           guile-3.0
-           guile-fibers-1.1             ; for cross-compilation
-           help2man
-           pkg-config
-           texinfo))
+     (cons* autoconf
+            automake
+            gettext-minimal
+            guile-3.0
+            guile-fibers-1.1            ; for cross-compilation
+            help2man
+            pkg-config
+            texinfo
+            ;; for the help2man man page when cross-compiling
+            (if (%current-target-system)
+                (list gzip
+                      this-package)
+                '())))
     (inputs (list guile-3.0
                   guile-fibers-1.1))))
 
-- 
2.38.1