;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 Andreas Enge
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see .
(define-module (gnu packages texlive)
;; #:use-module (guix licenses)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix build-system gnu)
#:use-module (gnu packages)
#:use-module (gnu packages compression)
#:use-module (gnu packages freetype)
#:use-module (gnu packages ghostscript)
#:use-module (gnu packages icu4c)
#:use-module (gnu packages libpng)
#:use-module (gnu packages pdf)
#:use-module (gnu packages perl)
#:use-module (gnu packages pkg-config)
#:use-module (gnu packages python)
#:use-module (gnu packages zip))
(define texlive-extra-src
(origin
(method url-fetch)
(uri "ftp://tug.org/historic/systems/texlive/2012/texlive-20120701-extra.tar.xz")
(sha256 (base32
"0cb8fnv4x281gy5ka779f00ssdmdpjj4x3pkh9j9vq45hrwg3522"))))
(define texlive-texmf-src
(origin
(method url-fetch)
(uri "ftp://tug.org/historic/systems/texlive/2012/texlive-20120701-texmf.tar.xz")
(sha256 (base32
"1fn1dg9k7pnh8a80j23zfkbrfnqyc4c2w4ss30dpkqj490nxsywq"))))
(define-public texlive
(package
(name "texlive")
(version "2012")
(source (origin
(method url-fetch)
(uri "ftp://tug.org/historic/systems/texlive/2012/texlive-20120701-source.tar.xz")
(sha256 (base32
"10bcrdfsqnc6y3gqcb8ndnjy07i5kz63as39irbq4gmcbmyn2rln"))))
(build-system gnu-build-system)
(inputs `(("texlive-extra-src" ,texlive-extra-src)
("texlive-texmf-src" ,texlive-texmf-src)
("fontconfig" ,fontconfig)
("freetype" ,freetype)
("icu4c" ,icu4c)
("ghostscript" ,ghostscript)
("libpng" ,libpng)
("perl" ,perl)
("poppler" ,poppler)
("pkg-config" ,pkg-config)
;; FIXME: Add interpreters csh, fontforge and ruby,
;; once they are available.
("python" ,python)
("teckit" ,teckit)
("t1lib" ,t1lib)
("zlib" ,zlib)
("zziplib" ,zziplib)))
(outputs '("share" "out"))
(arguments
`(#:out-of-source? #t
#:configure-flags
'("--disable-native-texlive-build"
"--without-x" ; FIXME: Drop as soon as X is available.
"--with-system-freetype2"
;; "--with-system-gd"
;; "--with-system-graphite"
"--with-system-icu"
"--with-system-libgs"
"--with-system-libpng"
"--with-system-poppler"
"--with-system-t1lib"
"--with-system-teckit"
"--with-system-xpdf"
"--with-system-zlib"
"--with-system-zziplib")
#:phases
(alist-replace
'configure
(lambda* (#:key outputs #:allow-other-keys #:rest args)
(let ((configure (assoc-ref %standard-phases 'configure))
(share (assoc-ref outputs "share")))
(substitute* "utils/psutils/Makefile.in"
(("/usr/bin/env perl") (which "perl")))
;; Correct targets for symbolic links of binaries.
(substitute* '("texk/texlive/linked_scripts/Makefile.in"
"texk/texlive/linked_scripts/Makefile.in"
"texk/tetex/Makefile.in"
"texk/tex4htk/Makefile.in"
"utils/psutils/Makefile.in"
"utils/chktex/Makefile.in"
"utils/mtx/Makefile.in"
"utils/pmx/Makefile.in"
"utils/ps2eps/Makefile.in")
(("\\$\\$REL/") (string-append share "/")))
(apply configure args)))
(alist-cons-after 'install 'postinst
(lambda* (#:key inputs outputs #:allow-other-keys #:rest args)
(let ((texlive-extra (assoc-ref inputs "texlive-extra-src"))
(texlive-texmf (assoc-ref inputs "texlive-texmf-src"))
(out (assoc-ref outputs "out"))
(share (assoc-ref outputs "share"))
(unpack (assoc-ref %standard-phases 'unpack))
(patch-source-shebangs
(assoc-ref %standard-phases 'patch-source-shebangs)))
;; Create symbolic links for the latex variants and their
;; man pages.
(let ((bin (string-append out "/bin/"))
(man (string-append out "/share/man/man1/")))
(symlink (string-append bin "pdftex")
(string-append bin "latex"))
(symlink (string-append bin "pdftex")
(string-append bin "pdflatex"))
(symlink (string-append bin "xetex")
(string-append bin "xelatex"))
(symlink (string-append bin "luatex")
(string-append bin "lualatex"))
(symlink (string-append man "luatex.1")
(string-append man "lualatex.1")))
;; Create the output directory for the shared data
;; tlpkg, texmf and texmf-dist.
(mkdir share)
;; Unpack texlive-extra and install tlpkg.
(mkdir "texlive-extra")
(chdir "texlive-extra")
(apply unpack (list #:source texlive-extra))
(apply patch-source-shebangs (list #:source texlive-extra))
(system* "mv" "tlpkg" share)
(chdir "../..")
;; Unpack and install texlive-texmf.
(mkdir "texlive-texmf")
(chdir "texlive-texmf")
(apply unpack (list #:source texlive-texmf))
(apply patch-source-shebangs (list #:source texlive-texmf))
;; Register "share" for kpathsea in texmf.cnf.
(substitute* "texmf/web2c/texmf.cnf"
(("TEXMFROOT = \\$SELFAUTOPARENT")
(string-append "TEXMFROOT = " share)))
(system* "mv" "texmf" share)
(system* "mv" "texmf-dist" share)
(chdir "../..")
;; Delete (most of) texmf and texmf-dist for "out", since they
;; are now in "share" from texlive-texmf; the purpose of this
;; procedure is to avoid installing them in the user profile.
;; But texmf.cnf must be placed in "out", since kpsewhich does
;; not know about "share" until it has found this file.
(system* "rm" "-r" (string-append out "/share/texmf"))
(system* "rm" "-r" (string-append out "/share/texmf-dist"))
(mkdir (string-append out "/share/texmf"))
(mkdir (string-append out "/share/texmf/web2c"))
(copy-file (string-append share "/texmf/web2c/texmf.cnf")
(string-append out "/share/texmf/web2c/texmf.cnf"))))
(alist-cons-after 'patch-shebangs 'texconfig
(lambda* (#:key outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out")))
;; Configure the texlive system; inspired from
;; http://slackbuilds.org/repository/13.37/office/texlive/
(display (string-append (getcwd) "\n"))
(display (string-append out "\n"))
(setenv "PATH" (string-append (getenv "PATH") ":" out "/bin"))
(display (string-append (getenv "PATH") "\n"))
(system* "updmap-sys" "--nohash" "--syncwithtrees")
(system* "mktexlsr")
(system* "fmtutil-sys" "--all")))
%standard-phases)))))
(synopsis "Tex Live, a package of the TeX typesetting system")
(description
"TeX Live provides a comprehensive TeX document production system.
It includes all the major TeX-related programs, macro packages, and fonts
that are free software, including support for many languages around the
world.")
(license "other")
(home-page "http://www.tug.org/texlive/")))