doc: Mention value /var to localstatedir option.
[jackhill/guix/guix.git] / doc / build.scm
CommitLineData
ccadafdc
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
19
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:
22;;
23;; guix build -f build.scm
24;;
25;; The result is a directory hierarchy that can be used as the manual/
26;; sub-directory of the web site.
27
28(use-modules (guix)
29 (guix gexp)
30 (guix git)
31 (guix git-download)
7854bbeb 32 (guix utils)
ccadafdc
LC
33 (git)
34 (gnu packages base)
35 (gnu packages gawk)
36 (gnu packages gettext)
37 (gnu packages guile)
f8c143a7 38 (gnu packages guile-xyz)
e591541d 39 (gnu packages iso-codes)
ccadafdc
LC
40 (gnu packages texinfo)
41 (gnu packages tex)
42 (srfi srfi-19)
43 (srfi srfi-71))
44
45(define file-append*
46 (@@ (guix self) file-append*))
47
48(define translated-texi-manuals
49 (@@ (guix self) translate-texi-manuals))
50
51(define info-manual
52 (@@ (guix self) info-manual))
53
cacb5576
LC
54(define %manual
55 ;; The manual to build--i.e., the base name of a .texi file, such as "guix"
56 ;; or "guix-cookbook".
57 (or (getenv "GUIX_MANUAL")
58 "guix"))
59
ccadafdc
LC
60(define %languages
61 '("de" "en" "es" "fr" "ru" "zh_CN"))
62
63(define (texinfo-manual-images source)
64 "Return a directory containing all the images used by the user manual, taken
65from SOURCE, the root of the source tree."
66 (define graphviz
67 (module-ref (resolve-interface '(gnu packages graphviz))
68 'graphviz))
69
70 (define images
71 (file-append* source "doc/images"))
72
73 (define build
74 (with-imported-modules '((guix build utils))
75 #~(begin
76 (use-modules (guix build utils)
77 (srfi srfi-26))
78
79 (define (dot->image dot-file format)
80 (invoke #+(file-append graphviz "/bin/dot")
81 "-T" format "-Gratio=.9" "-Gnodesep=.005"
82 "-Granksep=.00005" "-Nfontsize=9"
83 "-Nheight=.1" "-Nwidth=.1"
84 "-o" (string-append #$output "/"
85 (basename dot-file ".dot")
86 "." format)
87 dot-file))
88
89 ;; Build graphs.
90 (mkdir-p #$output)
91 (for-each (lambda (dot-file)
92 (for-each (cut dot->image dot-file <>)
93 '("png" "pdf")))
94 (find-files #$images "\\.dot$"))
95
96 ;; Copy other PNGs.
97 (for-each (lambda (png-file)
98 (install-file png-file #$output))
99 (find-files #$images "\\.png$")))))
100
101 (computed-file "texinfo-manual-images" build))
102
103(define* (texinfo-manual-source source #:key
104 (version "0.0")
105 (languages %languages)
106 (date 1))
107 "Gather all the source files of the Texinfo manuals from SOURCE--.texi file
108as well as images, OS examples, and translations."
109 (define documentation
110 (file-append* source "doc"))
111
112 (define examples
113 (file-append* source "gnu/system/examples"))
114
115 (define build
116 (with-imported-modules '((guix build utils))
117 #~(begin
118 (use-modules (guix build utils)
119 (srfi srfi-19))
120
121 (define (make-version-texi language)
122 ;; Create the 'version.texi' file for LANGUAGE.
123 (let ((file (if (string=? language "en")
124 "version.texi"
125 (string-append "version-" language ".texi"))))
126 (call-with-output-file (string-append #$output "/" file)
127 (lambda (port)
128 (let* ((version #$version)
129 (time (make-time time-utc 0 #$date))
130 (date (time-utc->date time)))
131 (format port "
132@set UPDATED ~a
133@set UPDATED-MONTH ~a
134@set EDITION ~a
135@set VERSION ~a\n"
136 (date->string date "~e ~B ~Y")
137 (date->string date "~B ~Y")
138 version version))))))
139
140 (install-file #$(file-append* documentation "/htmlxref.cnf")
141 #$output)
142
143 (for-each (lambda (texi)
144 (install-file texi #$output))
145 (append (find-files #$documentation "\\.(texi|scm)$")
146 (find-files #$(translated-texi-manuals source)
147 "\\.texi$")))
148
149 ;; Create 'version.texi'.
150 (for-each make-version-texi '#$languages)
151
152 ;; Copy configuration templates that the manual includes.
153 (for-each (lambda (template)
154 (copy-file template
155 (string-append
156 #$output "/os-config-"
157 (basename template ".tmpl")
158 ".texi")))
159 (find-files #$examples "\\.tmpl$"))
160
161 (symlink #$(texinfo-manual-images source)
162 (string-append #$output "/images")))))
163
164 (computed-file "texinfo-manual-source" build))
165
166(define %web-site-url
167 ;; URL of the web site home page.
168 (or (getenv "GUIX_WEB_SITE_URL")
169 "/software/guix/"))
170
171(define %makeinfo-html-options
172 ;; Options passed to 'makeinfo --html'.
2f000f2e
JL
173 '("--css-ref=https://www.gnu.org/software/gnulib/manual.css"
174 "-c" "EXTRA_HEAD=<meta name=\"viewport\" \
175content=\"width=device-width, initial-scale=1\" />"))
ccadafdc 176
7854bbeb
LC
177(define guile-lib/htmlprag-fixed
178 ;; Guile-Lib with a hotfix for (htmlprag).
179 (package
180 (inherit guile-lib)
181 (source (origin
182 (inherit (package-source guile-lib))
183 (modules '(( guix build utils)))
184 (snippet
185 '(begin
186 ;; When parsing
187 ;; "<body><blockquote><p>foo</p>\n</blockquote></body>",
188 ;; 'html->shtml' would mistakenly close 'blockquote' right
189 ;; before <p>. This patch removes 'p' from the
190 ;; 'parent-constraints' alist to fix that.
191 (substitute* "src/htmlprag.scm"
192 (("^[[:blank:]]*\\(p[[:blank:]]+\\. \\(body td th\\)\\).*")
193 ""))
194 #t))))
195 (arguments
196 (substitute-keyword-arguments (package-arguments guile-lib)
197 ((#:phases phases '%standard-phases)
198 `(modify-phases ,phases
199 (add-before 'check 'skip-known-failure
200 (lambda _
201 ;; XXX: The above change causes one test failure among
202 ;; the htmlprag tests.
203 (setenv "XFAIL_TESTS" "htmlprag.scm")
204 #t))))))))
205
f8c143a7
LC
206(define* (syntax-highlighted-html input
207 #:key
208 (name "highlighted-syntax")
209 (syntax-css-url
210 "/static/base/css/code.css"))
211 "Return a derivation called NAME that processes all the HTML files in INPUT
212to (1) add them a link to SYNTAX-CSS-URL, and (2) highlight the syntax of all
213its <pre class=\"lisp\"> blocks (as produced by 'makeinfo --html')."
214 (define build
7854bbeb 215 (with-extensions (list guile-lib/htmlprag-fixed guile-syntax-highlight)
f8c143a7
LC
216 (with-imported-modules '((guix build utils))
217 #~(begin
218 (use-modules (htmlprag)
219 (syntax-highlight)
220 (syntax-highlight scheme)
221 (syntax-highlight lexers)
222 (guix build utils)
223 (ice-9 match)
224 (ice-9 threads))
225
012c93e9
LC
226 (define (pair-open/close lst)
227 ;; Pair 'open' and 'close' tags produced by 'highlights' and
228 ;; produce nested 'paren' tags instead.
229 (let loop ((lst lst)
230 (level 0)
231 (result '()))
232 (match lst
233 ((('open open) rest ...)
234 (call-with-values
235 (lambda ()
236 (loop rest (+ 1 level) '()))
237 (lambda (inner close rest)
238 (loop rest level
239 (cons `(paren ,level ,open ,inner ,close)
240 result)))))
241 ((('close str) rest ...)
242 (if (> level 0)
243 (values (reverse result) str rest)
244 (begin
245 (format (current-error-port)
246 "warning: extra closing paren; context:~% ~y~%"
247 (reverse result))
248 (loop rest 0 (cons `(close ,str) result)))))
249 ((item rest ...)
250 (loop rest level (cons item result)))
251 (()
252 (when (> level 0)
253 (format (current-error-port)
254 "warning: missing ~a closing parens; context:~% ~y%"
255 level (reverse result)))
256 (values (reverse result) "" '())))))
257
258 (define (highlights->sxml* highlights)
259 ;; Like 'highlights->sxml', but handle nested 'paren tags. This
260 ;; allows for paren matching highlights via appropriate CSS
261 ;; "hover" properties.
262 (define (tag->class tag)
263 (string-append "syntax-" (symbol->string tag)))
264
265 (map (match-lambda
266 ((? string? str) str)
267 (('paren level open (body ...) close)
268 `(span (@ (class ,(string-append "syntax-paren"
269 (number->string level))))
270 ,open
271 (span (@ (class "syntax-symbol"))
272 ,@(highlights->sxml* body))
273 ,close))
274 ((tag text)
275 `(span (@ (class ,(tag->class tag))) ,text)))
276 highlights))
277
f8c143a7
LC
278 (define entity->string
279 (match-lambda
280 ("rArr" "⇒")
281 ("hellip" "…")
282 ("rsquo" "’")
283 (e (pk 'unknown-entity e) (primitive-exit 2))))
284
285 (define (concatenate-snippets pieces)
286 ;; Concatenate PIECES, which contains strings and entities,
287 ;; replacing entities with their corresponding string.
288 (let loop ((pieces pieces)
289 (strings '()))
290 (match pieces
291 (()
292 (string-concatenate-reverse strings))
293 (((? string? str) . rest)
294 (loop rest (cons str strings)))
295 ((('*ENTITY* "additional" entity) . rest)
296 (loop rest (cons (entity->string entity) strings)))
297 ((('span _ lst ...) . rest) ;for <span class="roman">
298 (loop (append lst rest) strings))
299 (something
300 (pk 'unsupported-code-snippet something)
301 (primitive-exit 1)))))
302
303 (define (syntax-highlight sxml)
304 ;; Recurse over SXML and syntax-highlight code snippets.
305 (match sxml
306 (('*TOP* decl body ...)
307 `(*TOP* ,decl ,@(map syntax-highlight body)))
308 (('head things ...)
309 `(head ,@things
310 (link (@ (rel "stylesheet")
311 (type "text/css")
312 (href #$syntax-css-url)))))
313 (('pre ('@ ('class "lisp")) code-snippet ...)
314 `(pre (@ (class "lisp"))
012c93e9
LC
315 ,@(highlights->sxml*
316 (pair-open/close
317 (highlight lex-scheme
318 (concatenate-snippets code-snippet))))))
f8c143a7
LC
319 ((tag ('@ attributes ...) body ...)
320 `(,tag (@ ,@attributes) ,@(map syntax-highlight body)))
321 ((tag body ...)
322 `(,tag ,@(map syntax-highlight body)))
323 ((? string? str)
324 str)))
325
326 (define (process-html file)
327 ;; Parse FILE and perform syntax highlighting for its Scheme
328 ;; snippets. Install the result to #$output.
329 (format (current-error-port) "processing ~a...~%" file)
330 (let* ((shtml (call-with-input-file file html->shtml))
331 (highlighted (syntax-highlight shtml))
332 (base (string-drop file (string-length #$input)))
333 (target (string-append #$output base)))
334 (mkdir-p (dirname target))
335 (call-with-output-file target
336 (lambda (port)
337 (write-shtml-as-html highlighted port)))))
338
339 (define (copy-as-is file)
340 ;; Copy FILE as is to #$output.
341 (let* ((base (string-drop file (string-length #$input)))
342 (target (string-append #$output base)))
343 (mkdir-p (dirname target))
344 (catch 'system-error
345 (lambda ()
346 (if (eq? 'symlink (stat:type (lstat file)))
347 (symlink (readlink file) target)
348 (link file target)))
349 (lambda args
350 (let ((errno (system-error-errno args)))
351 (pk 'error-link file target (strerror errno))
352 (primitive-exit 3))))))
353
354 ;; Install a UTF-8 locale so we can process UTF-8 files.
355 (setenv "GUIX_LOCPATH"
356 #+(file-append glibc-utf8-locales "/lib/locale"))
357 (setlocale LC_ALL "en_US.utf8")
358
359 (n-par-for-each (parallel-job-count)
360 (lambda (file)
361 (if (string-suffix? ".html" file)
362 (process-html file)
363 (copy-as-is file)))
364 (find-files #$input))))))
365
366 (computed-file name build))
367
ccadafdc
LC
368(define* (html-manual source #:key (languages %languages)
369 (version "0.0")
cacb5576 370 (manual %manual)
ccadafdc
LC
371 (date 1)
372 (options %makeinfo-html-options))
373 "Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
374makeinfo OPTIONS."
375 (define manual-source
376 (texinfo-manual-source source
377 #:version version
378 #:languages languages
379 #:date date))
380
e3e9c191
LC
381 (define images
382 (texinfo-manual-images source))
383
ccadafdc
LC
384 (define build
385 (with-imported-modules '((guix build utils))
386 #~(begin
387 (use-modules (guix build utils)
388 (ice-9 match))
389
390 (define (normalize language)
e591541d 391 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
ccadafdc
LC
392 (string-map (match-lambda
393 (#\_ #\-)
394 (chr chr))
395 (string-downcase language)))
396
cacb5576
LC
397 (define (language->texi-file-name language)
398 (if (string=? language "en")
399 (string-append #$manual-source "/"
400 #$manual ".texi")
401 (string-append #$manual-source "/"
402 #$manual "." language ".texi")))
403
ccadafdc
LC
404 ;; Install a UTF-8 locale so that 'makeinfo' is at ease.
405 (setenv "GUIX_LOCPATH"
406 #+(file-append glibc-utf8-locales "/lib/locale"))
407 (setenv "LC_ALL" "en_US.utf8")
408
409 (setvbuf (current-output-port) 'line)
410 (setvbuf (current-error-port) 'line)
411
412 (for-each (lambda (language)
cacb5576
LC
413 (let* ((texi (language->texi-file-name language))
414 (opts `("--html"
415 "-c" ,(string-append "TOP_NODE_UP_URL=/manual/"
ccadafdc 416 language)
cacb5576
LC
417 #$@options
418 ,texi)))
ccadafdc
LC
419 (format #t "building HTML manual for language '~a'...~%"
420 language)
421 (mkdir-p (string-append #$output "/"
422 (normalize language)))
423 (setenv "LANGUAGE" language)
424 (apply invoke #$(file-append texinfo "/bin/makeinfo")
425 "-o" (string-append #$output "/"
426 (normalize language)
427 "/html_node")
428 opts)
429 (apply invoke #$(file-append texinfo "/bin/makeinfo")
430 "--no-split"
431 "-o"
432 (string-append #$output "/"
433 (normalize language)
434 "/" #$manual
435 (if (string=? language "en")
436 ""
437 (string-append "." language))
438 ".html")
e3e9c191
LC
439 opts)
440
441 ;; Make sure images are available.
442 (symlink #$images
443 (string-append #$output "/" (normalize language)
444 "/images"))
445 (symlink #$images
446 (string-append #$output "/" (normalize language)
447 "/html_node/images"))))
cacb5576
LC
448 (filter (compose file-exists? language->texi-file-name)
449 '#$languages)))))
ccadafdc 450
f8c143a7
LC
451 (let* ((name (string-append manual "-html-manual"))
452 (manual (computed-file name build)))
453 (syntax-highlighted-html manual
454 #:name (string-append name "-highlighted"))))
ccadafdc
LC
455
456(define* (pdf-manual source #:key (languages %languages)
457 (version "0.0")
cacb5576 458 (manual %manual)
ccadafdc
LC
459 (date 1)
460 (options '()))
461 "Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
462makeinfo OPTIONS."
463 (define manual-source
464 (texinfo-manual-source source
465 #:version version
466 #:languages languages
467 #:date date))
468
469 ;; FIXME: This union works, except for the table of contents of non-English
470 ;; manuals, which contains escape sequences like "^^ca^^fe" instead of
471 ;; accented letters.
472 ;;
473 ;; (define texlive
474 ;; (texlive-union (list texlive-tex-texinfo
475 ;; texlive-generic-epsf
476 ;; texlive-fonts-ec)))
477
478 (define build
479 (with-imported-modules '((guix build utils))
480 #~(begin
481 (use-modules (guix build utils)
482 (srfi srfi-34)
483 (ice-9 match))
484
485 (define (normalize language) ;XXX: deduplicate
486 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
487 (string-map (match-lambda
488 (#\_ #\-)
489 (chr chr))
490 (string-downcase language)))
491
492 ;; Install a UTF-8 locale so that 'makeinfo' is at ease.
493 (setenv "GUIX_LOCPATH"
494 #+(file-append glibc-utf8-locales "/lib/locale"))
495 (setenv "LC_ALL" "en_US.utf8")
496 (setenv "PATH"
497 (string-append #+(file-append texlive "/bin") ":"
498 #+(file-append texinfo "/bin") ":"
499
500 ;; Below are command-line tools needed by
501 ;; 'texi2dvi' and friends.
502 #+(file-append sed "/bin") ":"
503 #+(file-append grep "/bin") ":"
504 #+(file-append coreutils "/bin") ":"
505 #+(file-append gawk "/bin") ":"
506 #+(file-append tar "/bin") ":"
507 #+(file-append diffutils "/bin")))
508
509 (setvbuf (current-output-port) 'line)
510 (setvbuf (current-error-port) 'line)
511
512 (setenv "HOME" (getcwd)) ;for kpathsea/mktextfm
513
514 ;; 'SOURCE_DATE_EPOCH' is honored by pdftex.
515 (setenv "SOURCE_DATE_EPOCH" "1")
516
517 (for-each (lambda (language)
518 (let ((opts `("--pdf"
519 "-I" "."
520 #$@options
521 ,(if (string=? language "en")
522 (string-append #$manual-source "/"
523 #$manual ".texi")
524 (string-append #$manual-source "/"
525 #$manual "." language ".texi")))))
526 (format #t "building PDF manual for language '~a'...~%"
527 language)
528 (mkdir-p (string-append #$output "/"
529 (normalize language)))
530 (setenv "LANGUAGE" language)
531
532
533 ;; FIXME: Unfortunately building PDFs for non-Latin
534 ;; alphabets doesn't work:
535 ;; <https://lists.gnu.org/archive/html/help-texinfo/2012-01/msg00014.html>.
536 (guard (c ((invoke-error? c)
537 (format (current-error-port)
538 "~%~%Failed to produce \
539PDF for language '~a'!~%~%"
540 language)))
541 (apply invoke #$(file-append texinfo "/bin/makeinfo")
542 "--pdf" "-o"
543 (string-append #$output "/"
544 (normalize language)
545 "/" #$manual
546 (if (string=? language "en")
547 ""
548 (string-append "."
549 language))
550 ".pdf")
551 opts))))
552 '#$languages))))
553
554 (computed-file (string-append manual "-pdf-manual") build))
555
556(define (guix-manual-text-domain source languages)
557 "Return the PO files for LANGUAGES of the 'guix-manual' text domain taken
558from SOURCE."
559 (define po-directory
560 (file-append* source "/po/doc"))
561
562 (define build
563 (with-imported-modules '((guix build utils))
564 #~(begin
565 (use-modules (guix build utils))
566
567 (mkdir-p #$output)
568 (for-each (lambda (language)
569 (define directory
570 (string-append #$output "/" language
571 "/LC_MESSAGES"))
572
573 (mkdir-p directory)
574 (invoke #+(file-append gnu-gettext "/bin/msgfmt")
575 "-c" "-o"
576 (string-append directory "/guix-manual.mo")
577 (string-append #$po-directory "/guix-manual."
578 language ".po")))
579 '#$(delete "en" languages)))))
580
581 (computed-file "guix-manual-po" build))
582
583(define* (html-manual-indexes source
584 #:key (languages %languages)
585 (version "0.0")
cacb5576 586 (manual %manual)
208cc522
LC
587 (title (if (string=? "guix" manual)
588 "GNU Guix Reference Manual"
589 "GNU Guix Cookbook"))
ccadafdc
LC
590 (date 1))
591 (define build
e591541d
LC
592 (with-extensions (list guile-json-3)
593 (with-imported-modules '((guix build utils))
594 #~(begin
595 (use-modules (guix build utils)
596 (json)
597 (ice-9 match)
598 (ice-9 popen)
599 (sxml simple)
600 (srfi srfi-1)
601 (srfi srfi-19))
602
603 (define (normalize language) ;XXX: deduplicate
604 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
605 (string-map (match-lambda
606 (#\_ #\-)
607 (chr chr))
608 (string-downcase language)))
609
610 (define-syntax-rule (with-language language exp ...)
611 (let ((lang (getenv "LANGUAGE")))
612 (dynamic-wind
613 (lambda ()
614 (setenv "LANGUAGE" language)
615 (setlocale LC_MESSAGES))
616 (lambda () exp ...)
617 (lambda ()
618 (if lang
619 (setenv "LANGUAGE" lang)
620 (unsetenv "LANGUAGE"))
621 (setlocale LC_MESSAGES)))))
622
623 ;; (put 'with-language 'scheme-indent-function 1)
624 (define* (translate str language
625 #:key (domain "guix-manual"))
626 (define exp
627 `(begin
628 (bindtextdomain "guix-manual"
629 #+(guix-manual-text-domain
630 source
631 languages))
632 (bindtextdomain "iso_639-3" ;language names
633 #+(file-append iso-codes
634 "/share/locale"))
635 (write (gettext ,str ,domain))))
636
637 (with-language language
638 ;; Since the 'gettext' function caches msgid translations,
639 ;; regardless of $LANGUAGE, we have to spawn a new process each
640 ;; time we want to translate to a different language. Bah!
641 (let* ((pipe (open-pipe* OPEN_READ
642 #+(file-append guile-2.2
643 "/bin/guile")
644 "-c" (object->string exp)))
645 (str (read pipe)))
646 (close-pipe pipe)
647 str)))
648
649 (define (seconds->string seconds language)
650 (let* ((time (make-time time-utc 0 seconds))
651 (date (time-utc->date time)))
652 (with-language language (date->string date "~e ~B ~Y"))))
653
654 (define (guix-url path)
655 (string-append #$%web-site-url path))
656
657 (define (sxml-index language title body)
658 ;; FIXME: Avoid duplicating styling info from guix-artwork.git.
659 `(html (@ (lang ,language))
660 (head
661 (title ,(string-append title " — GNU Guix"))
662 (meta (@ (charset "UTF-8")))
663 (meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0")))
664 ;; Menu prefetch.
665 (link (@ (rel "prefetch") (href ,(guix-url "menu/index.html"))))
666 ;; Base CSS.
667 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/elements.css"))))
668 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/common.css"))))
669 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/messages.css"))))
670 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/navbar.css"))))
671 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/breadcrumbs.css"))))
672 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/buttons.css"))))
673 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/footer.css"))))
674
675 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/page.css"))))
676 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/post.css")))))
677 (body
678 (header (@ (class "navbar"))
679 (h1 (a (@ (class "branding")
680 (href #$%web-site-url)))
681 (span (@ (class "a11y-offset"))
682 "Guix"))
683 (nav (@ (class "menu"))))
684 (nav (@ (class "breadcrumbs"))
685 (a (@ (class "crumb")
686 (href #$%web-site-url))
687 "Home"))
688 ,body
689 (footer))))
690
691 (define (language-index language)
692 (define title
208cc522 693 (translate #$title language))
e591541d
LC
694
695 (sxml-index
696 language title
697 `(main
698 (article
699 (@ (class "page centered-block limit-width"))
700 (h2 ,title)
701 (p (@ (class "post-metadata centered-text"))
702 #$version " — "
703 ,(seconds->string #$date language))
704
705 (div
706 (ul
707 (li (a (@ (href "html_node"))
708 "HTML, with one page per node"))
709 (li (a (@ (href
710 ,(string-append
711 #$manual
712 (if (string=? language
713 "en")
714 ""
715 (string-append "."
716 language))
717 ".html")))
718 "HTML, entirely on one page"))
719 ,@(if (member language '("ru" "zh_CN"))
720 '()
721 `((li (a (@ (href ,(string-append
722 #$manual
723 (if (string=? language "en")
724 ""
725 (string-append "."
726 language))
727 ".pdf"))))
728 "PDF")))))))))
729
730 (define %iso639-languages
731 (vector->list
732 (assoc-ref (call-with-input-file
733 #+(file-append iso-codes
734 "/share/iso-codes/json/iso_639-3.json")
735 json->scm)
736 "639-3")))
737
738 (define (language-code->name code)
739 "Return the full name of a language from its ISO-639-3 code."
740 (let ((code (match (string-index code #\_)
741 (#f code)
742 (index (string-take code index)))))
743 (any (lambda (language)
744 (and (string=? (or (assoc-ref language "alpha_2")
745 (assoc-ref language "alpha_3"))
746 code)
747 (assoc-ref language "name")))
748 %iso639-languages)))
749
750 (define (top-level-index languages)
208cc522 751 (define title #$title)
e591541d
LC
752 (sxml-index
753 "en" title
754 `(main
755 (article
756 (@ (class "page centered-block limit-width"))
757 (h2 ,title)
758 (div
208cc522 759 "This document is available in the following
e591541d
LC
760languages:\n"
761 (ul
762 ,@(map (lambda (language)
763 `(li (a (@ (href ,(normalize language)))
764 ,(translate
765 (language-code->name language)
766 language
767 #:domain "iso_639-3"))))
768 languages)))))))
769
770 (define (write-html file sxml)
771 (call-with-output-file file
772 (lambda (port)
773 (display "<!DOCTYPE html>\n" port)
774 (sxml->xml sxml port))))
775
776 (setenv "GUIX_LOCPATH"
777 #+(file-append glibc-utf8-locales "/lib/locale"))
778 (setenv "LC_ALL" "en_US.utf8")
779 (setlocale LC_ALL "en_US.utf8")
780
781 (for-each (lambda (language)
782 (define directory
783 (string-append #$output "/"
784 (normalize language)))
785
786 (mkdir-p directory)
787 (write-html (string-append directory "/index.html")
788 (language-index language)))
789 '#$languages)
790
791 (write-html (string-append #$output "/index.html")
792 (top-level-index '#$languages))))))
ccadafdc
LC
793
794 (computed-file "html-indexes" build))
795
796(define* (pdf+html-manual source
797 #:key (languages %languages)
798 (version "0.0")
799 (date (time-second (current-time time-utc)))
cacb5576 800 (manual %manual))
ccadafdc
LC
801 "Return the union of the HTML and PDF manuals, as well as the indexes."
802 (directory-union (string-append manual "-manual")
803 (map (lambda (proc)
804 (proc source
805 #:date date
806 #:languages languages
807 #:version version
808 #:manual manual))
809 (list html-manual-indexes
810 html-manual pdf-manual))
811 #:copy? #t))
812
813(define (latest-commit+date directory)
814 "Return two values: the last commit ID (a hex string) for DIRECTORY, and its
815commit date (an integer)."
816 (let* ((repository (repository-open directory))
817 (head (repository-head repository))
818 (oid (reference-target head))
819 (commit (commit-lookup repository oid)))
820 ;; TODO: Use (git describe) when it's widely available.
821 (values (oid->string oid) (commit-time commit))))
822
823\f
824(let* ((root (canonicalize-path
825 (string-append (current-source-directory) "/..")))
826 (commit date (latest-commit+date root)))
827 (format (current-error-port)
828 "building manual from work tree around commit ~a, ~a~%"
829 commit
830 (let* ((time (make-time time-utc 0 date))
831 (date (time-utc->date time)))
832 (date->string date "~e ~B ~Y")))
833 (pdf+html-manual (local-file root "guix" #:recursive? #t
834 #:select? (git-predicate root))
835 #:version (or (getenv "GUIX_MANUAL_VERSION")
836 (string-take commit 7))
837 #:date date))