Subject: [bug#50445] [PATCHES wip-gnome v1 3/4] gnu: gtksourceview: Enable documentation.

From: Raghav Gururajan <[email-masked]>
Date: Mon, 6 Sep 2021 21:02:16 -0400

* gnu/packages/gtk.scm (gtksourceview)[outputs]: New output "doc".
[configure-flags](gtk-doc): New flag.
[phases](patch-docbook-xml,move-doc): New phases.
[native-inputs]: Add docbook-xml-4.3, docbook-xsl, gtk-doc and libxslt.
---
 gnu/packages/gtk.scm | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/gtk.scm b/gnu/packages/gtk.scm
index fa3a69d46d..0a80671629 100644
--- a/gnu/packages/gtk.scm
+++ b/gnu/packages/gtk.scm
@@ -548,9 +548,24 @@ printing and other features typical of a source code editor.")
               (base32
                "1hcswszqnsyqzzf5zk8iflxdvkfvvcg89pf6xsqwbyyabwdxfqyi"))))
    (build-system meson-build-system)
+   (outputs '("out" "doc"))
    (arguments
-    '(#:phases
+    `(#:configure-flags
+      (list
+       ,@(if (%current-target-system)
+       ;; If true, gtkdoc-scangobj will try to execute a
+       ;; cross-compiled binary.
+       '("-Dgtk_doc=false")
+       '("-Dgtk_doc=true")))
+      #:phases
       (modify-phases %standard-phases
+        (add-after 'unpack 'patch-docbook-xml
+          (lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
+            (substitute* (find-files "docs" "\\.xml\\.in$")
+              (("http://www.oasis-open.org/docbook/xml/4.3/")
+               (string-append
+                (assoc-ref (or native-inputs inputs) "docbook-xml-4.3")
+                "/xml/dtd/docbook/")))))
         (add-before
          'check 'pre-check
          (lambda* (#:key inputs #:allow-other-keys)
@@ -560,12 +575,24 @@ printing and other features typical of a source code editor.")
              (setenv "DISPLAY" ":1")
              ;; For the missing /etc/machine-id.
              (setenv "DBUS_FATAL_WARNINGS" "0")
-             #t))))))
+             #t)))
+        (add-after 'install 'move-doc
+          (lambda* (#:key outputs #:allow-other-keys)
+            (let* ((out (assoc-ref outputs "out"))
+                   (doc (assoc-ref outputs "doc")))
+              (mkdir-p (string-append doc "/share/gtk-doc"))
+              (rename-file
+               (string-append out "/share/gtk-doc")
+               (string-append doc "/share/gtk-doc"))))))))
    (native-inputs
-    `(("glib:bin" ,glib "bin") ; for glib-genmarshal, etc.
+    `(("docbook-xml-4.3" ,docbook-xml-4.3)
+      ("docbook-xsl" ,docbook-xsl)
+      ("glib:bin" ,glib "bin") ; for glib-genmarshal, etc.
+      ("gtk-doc" ,gtk-doc)
       ("intltool" ,intltool)
       ("itstool" ,itstool)
       ("gobject-introspection" ,gobject-introspection)
+      ("libxslt" ,libxslt)
       ("pkg-config" ,pkg-config)
       ("vala" ,vala)
       ;; For testing.
-- 
2.33.0