1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 ;; This file contains machinery to build HTML and PDF copies of the manual
21 ;; that can be readily published on the web site. To do that, run:
23 ;; guix build -f build.scm
25 ;; The result is a directory hierarchy that can be used as the manual/
26 ;; sub-directory of the web site.
35 (gnu packages gettext)
37 (gnu packages texinfo)
43 (@@ (guix self) file-append*))
45 (define translated-texi-manuals
46 (@@ (guix self) translate-texi-manuals))
49 (@@ (guix self) info-manual))
52 '("de" "en" "es" "fr" "ru" "zh_CN"))
54 (define (texinfo-manual-images source)
55 "Return a directory containing all the images used by the user manual, taken
56 from SOURCE, the root of the source tree."
58 (module-ref (resolve-interface '(gnu packages graphviz))
62 (file-append* source "doc/images"))
65 (with-imported-modules '((guix build utils))
67 (use-modules (guix build utils)
70 (define (dot->image dot-file format)
71 (invoke #+(file-append graphviz "/bin/dot")
72 "-T" format "-Gratio=.9" "-Gnodesep=.005"
73 "-Granksep=.00005" "-Nfontsize=9"
74 "-Nheight=.1" "-Nwidth=.1"
75 "-o" (string-append #$output "/"
76 (basename dot-file ".dot")
82 (for-each (lambda (dot-file)
83 (for-each (cut dot->image dot-file <>)
85 (find-files #$images "\\.dot$"))
88 (for-each (lambda (png-file)
89 (install-file png-file #$output))
90 (find-files #$images "\\.png$")))))
92 (computed-file "texinfo-manual-images" build))
94 (define* (texinfo-manual-source source #:key
96 (languages %languages)
98 "Gather all the source files of the Texinfo manuals from SOURCE--.texi file
99 as well as images, OS examples, and translations."
100 (define documentation
101 (file-append* source "doc"))
104 (file-append* source "gnu/system/examples"))
107 (with-imported-modules '((guix build utils))
109 (use-modules (guix build utils)
112 (define (make-version-texi language)
113 ;; Create the 'version.texi' file for LANGUAGE.
114 (let ((file (if (string=? language "en")
116 (string-append "version-" language ".texi"))))
117 (call-with-output-file (string-append #$output "/" file)
119 (let* ((version #$version)
120 (time (make-time time-utc 0 #$date))
121 (date (time-utc->date time)))
124 @set UPDATED-MONTH ~a
127 (date->string date "~e ~B ~Y")
128 (date->string date "~B ~Y")
129 version version))))))
131 (install-file #$(file-append* documentation "/htmlxref.cnf")
134 (for-each (lambda (texi)
135 (install-file texi #$output))
136 (append (find-files #$documentation "\\.(texi|scm)$")
137 (find-files #$(translated-texi-manuals source)
140 ;; Create 'version.texi'.
141 (for-each make-version-texi '#$languages)
143 ;; Copy configuration templates that the manual includes.
144 (for-each (lambda (template)
147 #$output "/os-config-"
148 (basename template ".tmpl")
150 (find-files #$examples "\\.tmpl$"))
152 (symlink #$(texinfo-manual-images source)
153 (string-append #$output "/images")))))
155 (computed-file "texinfo-manual-source" build))
157 (define %web-site-url
158 ;; URL of the web site home page.
159 (or (getenv "GUIX_WEB_SITE_URL")
162 (define %makeinfo-html-options
163 ;; Options passed to 'makeinfo --html'.
164 '("--css-ref=https://www.gnu.org/software/gnulib/manual.css"))
166 (define* (html-manual source #:key (languages %languages)
170 (options %makeinfo-html-options))
171 "Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
173 (define manual-source
174 (texinfo-manual-source source
176 #:languages languages
180 (with-imported-modules '((guix build utils))
182 (use-modules (guix build utils)
185 (define (normalize language)
186 ;; Normalize LANGUAGE. For instance, "zh_CN" become "zh-cn".
187 (string-map (match-lambda
190 (string-downcase language)))
192 ;; Install a UTF-8 locale so that 'makeinfo' is at ease.
193 (setenv "GUIX_LOCPATH"
194 #+(file-append glibc-utf8-locales "/lib/locale"))
195 (setenv "LC_ALL" "en_US.utf8")
197 (setvbuf (current-output-port) 'line)
198 (setvbuf (current-error-port) 'line)
200 (for-each (lambda (language)
201 (let ((opts `("--html"
202 "-c" ,(string-append "TOP_NODE_UP_URL=/manual/"
205 ,(if (string=? language "en")
206 (string-append #$manual-source "/"
208 (string-append #$manual-source "/"
209 #$manual "." language ".texi")))))
210 (format #t "building HTML manual for language '~a'...~%"
212 (mkdir-p (string-append #$output "/"
213 (normalize language)))
214 (setenv "LANGUAGE" language)
215 (apply invoke #$(file-append texinfo "/bin/makeinfo")
216 "-o" (string-append #$output "/"
220 (apply invoke #$(file-append texinfo "/bin/makeinfo")
223 (string-append #$output "/"
226 (if (string=? language "en")
228 (string-append "." language))
233 (computed-file (string-append manual "-html-manual") build))
235 (define* (pdf-manual source #:key (languages %languages)
240 "Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
242 (define manual-source
243 (texinfo-manual-source source
245 #:languages languages
248 ;; FIXME: This union works, except for the table of contents of non-English
249 ;; manuals, which contains escape sequences like "^^ca^^fe" instead of
253 ;; (texlive-union (list texlive-tex-texinfo
254 ;; texlive-generic-epsf
255 ;; texlive-fonts-ec)))
258 (with-imported-modules '((guix build utils))
260 (use-modules (guix build utils)
264 (define (normalize language) ;XXX: deduplicate
265 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
266 (string-map (match-lambda
269 (string-downcase language)))
271 ;; Install a UTF-8 locale so that 'makeinfo' is at ease.
272 (setenv "GUIX_LOCPATH"
273 #+(file-append glibc-utf8-locales "/lib/locale"))
274 (setenv "LC_ALL" "en_US.utf8")
276 (string-append #+(file-append texlive "/bin") ":"
277 #+(file-append texinfo "/bin") ":"
279 ;; Below are command-line tools needed by
280 ;; 'texi2dvi' and friends.
281 #+(file-append sed "/bin") ":"
282 #+(file-append grep "/bin") ":"
283 #+(file-append coreutils "/bin") ":"
284 #+(file-append gawk "/bin") ":"
285 #+(file-append tar "/bin") ":"
286 #+(file-append diffutils "/bin")))
288 (setvbuf (current-output-port) 'line)
289 (setvbuf (current-error-port) 'line)
291 (setenv "HOME" (getcwd)) ;for kpathsea/mktextfm
293 ;; 'SOURCE_DATE_EPOCH' is honored by pdftex.
294 (setenv "SOURCE_DATE_EPOCH" "1")
296 (for-each (lambda (language)
297 (let ((opts `("--pdf"
300 ,(if (string=? language "en")
301 (string-append #$manual-source "/"
303 (string-append #$manual-source "/"
304 #$manual "." language ".texi")))))
305 (format #t "building PDF manual for language '~a'...~%"
307 (mkdir-p (string-append #$output "/"
308 (normalize language)))
309 (setenv "LANGUAGE" language)
312 ;; FIXME: Unfortunately building PDFs for non-Latin
313 ;; alphabets doesn't work:
314 ;; <https://lists.gnu.org/archive/html/help-texinfo/2012-01/msg00014.html>.
315 (guard (c ((invoke-error? c)
316 (format (current-error-port)
317 "~%~%Failed to produce \
318 PDF for language '~a'!~%~%"
320 (apply invoke #$(file-append texinfo "/bin/makeinfo")
322 (string-append #$output "/"
325 (if (string=? language "en")
333 (computed-file (string-append manual "-pdf-manual") build))
335 (define (guix-manual-text-domain source languages)
336 "Return the PO files for LANGUAGES of the 'guix-manual' text domain taken
339 (file-append* source "/po/doc"))
342 (with-imported-modules '((guix build utils))
344 (use-modules (guix build utils))
347 (for-each (lambda (language)
349 (string-append #$output "/" language
353 (invoke #+(file-append gnu-gettext "/bin/msgfmt")
355 (string-append directory "/guix-manual.mo")
356 (string-append #$po-directory "/guix-manual."
358 '#$(delete "en" languages)))))
360 (computed-file "guix-manual-po" build))
362 (define* (html-manual-indexes source
363 #:key (languages %languages)
368 (with-imported-modules '((guix build utils))
370 (use-modules (guix build utils)
376 (define (normalize language) ;XXX: deduplicate
377 ;; Normalize LANGUAGE. For instance, "zh_CN" become "zh-cn".
378 (string-map (match-lambda
381 (string-downcase language)))
383 (define-syntax-rule (with-language language exp ...)
384 (let ((lang (getenv "LANGUAGE")))
387 (setenv "LANGUAGE" language)
388 (setlocale LC_MESSAGES))
392 (setenv "LANGUAGE" lang)
393 (unsetenv "LANGUAGE"))
394 (setlocale LC_MESSAGES)))))
396 ;; (put 'with-language 'scheme-indent-function 1)
397 (define* (translate str language
398 #:key (domain "guix-manual"))
401 (bindtextdomain "guix-manual"
402 #+(guix-manual-text-domain
405 (write (gettext ,str "guix-manual"))))
407 (with-language language
408 ;; Since the 'gettext' function caches msgid translations,
409 ;; regardless of $LANGUAGE, we have to spawn a new process each
410 ;; time we want to translate to a different language. Bah!
411 (let* ((pipe (open-pipe* OPEN_READ
412 #+(file-append guile-2.2
414 "-c" (object->string exp)))
419 (define (seconds->string seconds language)
420 (let* ((time (make-time time-utc 0 seconds))
421 (date (time-utc->date time)))
422 (with-language language (date->string date "~e ~B ~Y"))))
424 (define (guix-url path)
425 (string-append #$%web-site-url path))
427 (define (sxml-index language title body)
428 ;; FIXME: Avoid duplicating styling info from guix-artwork.git.
429 `(html (@ (lang ,language))
431 (title ,(string-append title " — GNU Guix"))
432 (meta (@ (charset "UTF-8")))
433 (meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0")))
435 (link (@ (rel "prefetch") (href ,(guix-url "menu/index.html"))))
437 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/elements.css"))))
438 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/common.css"))))
439 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/messages.css"))))
440 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/navbar.css"))))
441 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/breadcrumbs.css"))))
442 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/buttons.css"))))
443 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/footer.css"))))
445 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/page.css"))))
446 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/post.css")))))
448 (header (@ (class "navbar"))
449 (h1 (a (@ (class "branding")
450 (href #$%web-site-url)))
451 (span (@ (class "a11y-offset"))
453 (nav (@ (class "menu"))))
454 (nav (@ (class "breadcrumbs"))
455 (a (@ (class "crumb")
456 (href #$%web-site-url))
461 (define (language-index language)
463 (translate "GNU Guix Reference Manual" language))
469 (@ (class "page centered-block limit-width"))
471 (p (@ (class "post-metadata centered-text"))
473 ,(seconds->string #$date language))
477 (li (a (@ (href "html_node"))
478 "HTML, with one page per node"))
482 (if (string=? language
488 "HTML, entirely on one page"))
489 ,@(if (member language '("ru" "zh_CN"))
491 `((li (a (@ (href ,(string-append
493 (if (string=? language "en")
500 (define (write-html file sxml)
501 (call-with-output-file file
503 (display "<!DOCTYPE html>\n" port)
504 (sxml->xml sxml port))))
506 (setenv "GUIX_LOCPATH"
507 #+(file-append glibc-utf8-locales "/lib/locale"))
508 (setenv "LC_ALL" "en_US.utf8")
509 (setlocale LC_ALL "en_US.utf8")
511 (bindtextdomain "guix-manual"
512 #+(guix-manual-text-domain source languages))
514 (for-each (lambda (language)
516 (string-append #$output "/"
517 (normalize language)))
520 (write-html (string-append directory "/index.html")
521 (language-index language)))
524 (computed-file "html-indexes" build))
526 (define* (pdf+html-manual source
527 #:key (languages %languages)
529 (date (time-second (current-time time-utc)))
531 "Return the union of the HTML and PDF manuals, as well as the indexes."
532 (directory-union (string-append manual "-manual")
536 #:languages languages
539 (list html-manual-indexes
540 html-manual pdf-manual))
543 (define (latest-commit+date directory)
544 "Return two values: the last commit ID (a hex string) for DIRECTORY, and its
545 commit date (an integer)."
546 (let* ((repository (repository-open directory))
547 (head (repository-head repository))
548 (oid (reference-target head))
549 (commit (commit-lookup repository oid)))
550 ;; TODO: Use (git describe) when it's widely available.
551 (values (oid->string oid) (commit-time commit))))
554 (let* ((root (canonicalize-path
555 (string-append (current-source-directory) "/..")))
556 (commit date (latest-commit+date root)))
557 (format (current-error-port)
558 "building manual from work tree around commit ~a, ~a~%"
560 (let* ((time (make-time time-utc 0 date))
561 (date (time-utc->date time)))
562 (date->string date "~e ~B ~Y")))
563 (pdf+html-manual (local-file root "guix" #:recursive? #t
564 #:select? (git-predicate root))
565 #:version (or (getenv "GUIX_MANUAL_VERSION")
566 (string-take commit 7))