Subject: [PATCH core-updates v2 2/2] gnu: texlive-psnfss: Fix build; add "doc" output.

From: Simon South <[email-masked]>
Date: Sat, 22 Jan 2022 18:19:24 -0500

* gnu/packages/tex.scm (texlive-psnfss)[outputs]: Add "doc".
[arguments]<#:phases>: Add "chdir-back", "clean-installed-files" and
"move-doc-files" phases to ensure files are correctly arranged in package's
outputs, matching installation instructions in README.
---
 gnu/packages/tex.scm | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/tex.scm b/gnu/packages/tex.scm
index 9649b1361b..5ac4012e36 100644
--- a/gnu/packages/tex.scm
+++ b/gnu/packages/tex.scm
@@ -20,6 +20,7 @@
 ;;; Copyright © 2021 Ivan Gankevich <[email-masked]>
 ;;; Copyright © 2021 Julien Lepiller <[email-masked]>
 ;;; Copyright © 2021 Thiago Jung Bauermann <[email-masked]>
+;;; Copyright © 2022 Simon South <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -4089,6 +4090,7 @@ (define-public texlive-psnfss
                     "11f14dzhwsy4pli21acccip43d36nf3pac33ihjffnps1i2mhqkd"))))
     (package
       (inherit template)
+      (outputs '("out" "doc"))
       (arguments
        (substitute-keyword-arguments (package-arguments template)
          ((#:tex-directory _ #t)
@@ -4097,7 +4099,35 @@ (define-public texlive-psnfss
           `(modify-phases ,phases
              (add-after 'unpack 'chdir
                (lambda _
-                 (chdir "source/latex/psnfss")))))))
+                 (chdir "source/latex/psnfss")))
+             (add-after 'install 'chdir-back
+               (lambda _
+                 (chdir "../../..")))
+             (add-after 'chdir-back 'clean-installed-files
+               (lambda _
+                 ;; Remove the generated .sty files from the build area as
+                 ;; these were already copied to the default output in the
+                 ;; "install" phase.
+                 (delete-file-recursively "source/latex/psnfss/build")))
+             (add-after 'clean-installed-files 'move-doc-files
+               (lambda* (#:key outputs #:allow-other-keys)
+                 (let* ((doc (assoc-ref outputs "doc"))
+                        (doc-root (string-append doc "/share/texmf-dist"))
+                        (doc-path "doc/latex/psnfss")
+                        (source-path "source/latex/psnfss"))
+                   ;; Move the PDF documentation to the "doc" output.
+                   (let* ((file-name "psnfss2e.pdf")
+                          (source (string-append doc-path "/" file-name))
+                          (target-dir (string-append doc-root "/" doc-path)))
+                     (mkdir-p target-dir)
+                     (copy-file source
+                                (string-append target-dir "/" file-name))
+                     (delete-file source))
+
+                   ;; Keep the remaining files together with the package's
+                   ;; source, as per the installation instructions.
+                   (copy-recursively doc-path source-path)
+                   (delete-file-recursively "doc"))))))))
       (native-inputs
        (list texlive-cm))
       (home-page "https://www.ctan.org/pkg/psnfss")
-- 
2.34.0