Commit | Line | Data |
---|---|---|
205794c8 RW |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net> | |
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 | (define-module (guix build texlive-build-system) | |
20 | #:use-module ((guix build gnu-build-system) #:prefix gnu:) | |
21 | #:use-module (guix build utils) | |
bb3b3597 | 22 | #:use-module (guix build union) |
205794c8 | 23 | #:use-module (ice-9 match) |
1678be09 | 24 | #:use-module (ice-9 ftw) |
205794c8 RW |
25 | #:use-module (srfi srfi-1) |
26 | #:use-module (srfi srfi-26) | |
27 | #:export (%standard-phases | |
28 | texlive-build)) | |
29 | ||
30 | ;; Commentary: | |
31 | ;; | |
32 | ;; Builder-side code of the standard build procedure for TeX Live packages. | |
33 | ;; | |
34 | ;; Code: | |
35 | ||
36 | (define (compile-with-latex format file) | |
37 | (zero? (system* format | |
38 | "-interaction=batchmode" | |
39 | "-output-directory=build" | |
40 | (string-append "&" format) | |
41 | file))) | |
42 | ||
bb3b3597 RW |
43 | (define* (configure #:key inputs #:allow-other-keys) |
44 | (let* ((out (string-append (getcwd) "/.texlive-union")) | |
45 | (texmf.cnf (string-append out "/share/texmf-dist/web2c/texmf.cnf"))) | |
46 | ;; Build a modifiable union of all inputs (but exclude bash) | |
47 | (match inputs | |
48 | (((names . directories) ...) | |
82af2c2f | 49 | (union-build out (filter directory-exists? directories) |
bb3b3597 RW |
50 | #:create-all-directories? #t |
51 | #:log-port (%make-void-port "w")))) | |
52 | ||
53 | ;; The configuration file "texmf.cnf" is provided by the | |
54 | ;; "texlive-bin" package. We take it and override only the | |
55 | ;; setting for TEXMFROOT and TEXMF. This file won't be consulted | |
56 | ;; by default, though, so we still need to set TEXMFCNF. | |
57 | (substitute* texmf.cnf | |
58 | (("^TEXMFROOT = .*") | |
59 | (string-append "TEXMFROOT = " out "/share\n")) | |
60 | (("^TEXMF = .*") | |
61 | "TEXMF = $TEXMFROOT/share/texmf-dist\n")) | |
62 | (setenv "TEXMFCNF" (dirname texmf.cnf)) | |
63 | (setenv "TEXMF" (string-append out "/share/texmf-dist"))) | |
205794c8 | 64 | (mkdir "build") |
bb3b3597 RW |
65 | #t) |
66 | ||
67 | (define* (build #:key inputs build-targets tex-format #:allow-other-keys) | |
205794c8 RW |
68 | (every (cut compile-with-latex tex-format <>) |
69 | (if build-targets build-targets | |
1678be09 | 70 | (scandir "." (cut string-suffix? ".ins" <>))))) |
205794c8 RW |
71 | |
72 | (define* (install #:key outputs tex-directory #:allow-other-keys) | |
73 | (let* ((out (assoc-ref outputs "out")) | |
74 | (target (string-append | |
75 | out "/share/texmf-dist/tex/" tex-directory))) | |
76 | (mkdir-p target) | |
77 | (for-each delete-file (find-files "." "\\.(log|aux)$")) | |
78 | (for-each (cut install-file <> target) | |
79 | (find-files "build" ".*")) | |
80 | #t)) | |
81 | ||
82 | (define %standard-phases | |
83 | (modify-phases gnu:%standard-phases | |
189be331 | 84 | (delete 'bootstrap) |
bb3b3597 | 85 | (replace 'configure configure) |
205794c8 RW |
86 | (replace 'build build) |
87 | (delete 'check) | |
88 | (replace 'install install))) | |
89 | ||
90 | (define* (texlive-build #:key inputs (phases %standard-phases) | |
91 | #:allow-other-keys #:rest args) | |
92 | "Build the given TeX Live package, applying all of PHASES in order." | |
93 | (apply gnu:gnu-build #:inputs inputs #:phases phases args)) | |
94 | ||
95 | ;;; texlive-build-system.scm ends here |