texlive-build-system.scm 3.7 KB

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