Revert "texlive-module: kill POSIXism"
[gentoo.git] / eclass / latex-package.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: latex-package.eclass
5 # @MAINTAINER:
6 # TeX team <tex@gentoo.org>
7 # @AUTHOR:
8 # Matthew Turk <satai@gentoo.org>
9 # Martin Ehmsen <ehmsen@gentoo.org>
10 # @SUPPORTED_EAPIS: 7
11 # @BLURB: An eclass for easy installation of LaTeX packages
12 # @DESCRIPTION:
13 # This eClass is designed to be easy to use and implement.  The vast majority of
14 # LaTeX packages will only need to define SRC_URI (and sometimes S) for a
15 # successful installation.  If fonts need to be installed, then the variable
16 # SUPPLIER must also be defined.
17 #
18 # However, those packages that contain subdirectories must process each
19 # subdirectory individually.  For example, a package that contains directories
20 # DIR1 and DIR2 must call latex-package_src_compile() and
21 # latex-package_src_install() in each directory, as shown here:
22 #
23 # src_compile() {
24 #    cd ${S}
25 #    cd DIR1
26 #    latex-package_src_compile
27 #    cd ..
28 #    cd DIR2
29 #    latex-package_src_compile
30 # }
31 #
32 # src_install() {
33 #    cd ${S}
34 #    cd DIR1
35 #    latex-package_src_install
36 #    cd ..
37 #    cd DIR2
38 #    latex-package_src_install
39 # }
40 #
41 # The eClass automatically takes care of rehashing TeX's cache (ls-lR) after
42 # installation and after removal, as well as creating final documentation from
43 # TeX files that come with the source.  Note that we break TeX layout standards
44 # by placing documentation in /usr/share/doc/${PN}
45 #
46 # For examples of basic installations, check out dev-tex/aastex and
47 # dev-tex/leaflet .
48 #
49 # NOTE: The CTAN "directory grab" function creates files with different MD5
50 # signatures EVERY TIME.  For this reason, if you are grabbing from the CTAN,
51 # you must either grab each file individually, or find a place to mirror an
52 # archive of them.  (iBiblio)
53 #
54 # It inherits base and eutils in EAPI 5 and earlier.
55
56 RDEPEND="virtual/latex-base"
57 DEPEND="${RDEPEND}
58         >=sys-apps/texinfo-4.2-r5"
59
60 case ${EAPI:-0} in
61         0|1|2|3|4|5|6) ;;
62         *) die "${EAPI} is not supported" ;;
63 esac
64
65 HOMEPAGE="http://www.tug.org/"
66 TEXMF="/usr/share/texmf-site"
67
68 # @ECLASS-VARIABLE: SUPPLIER
69 # @DESCRIPTION:
70 # This refers to the font supplier; it should be overridden (see eclass
71 # DESCRIPTION above)
72 SUPPLIER="misc"
73
74 # @ECLASS-VARIABLE: LATEX_DOC_ARGUMENTS
75 # @DESCRIPTION:
76 # When compiling documentation (.tex/.dtx), this variable will be passed
77 # to pdflatex as additional argument (e.g. -shell-escape). This variable
78 # must be set after inherit, as it gets automatically cleared otherwise.
79 LATEX_DOC_ARGUMENTS=""
80
81 # @FUNCTION: latex-package_src_doinstall
82 # @USAGE: [ module ]
83 # @DESCRIPTION:
84 # [module] can be one or more of: sh, sty, cls, fd, clo, def, cfg, dvi, ps, pdf,
85 # tex, dtx, tfm, vf, afm, pfb, ttf, bst, styles, doc, fonts, bin, or all.
86 # If [module] is not given, all is assumed.
87 # It installs the files found in the current directory to the standard locations
88 # for a TeX installation
89 latex-package_src_doinstall() {
90         debug-print function $FUNCNAME $*
91
92         # Avoid generating font cache outside of the sandbox
93         export VARTEXFONTS="${T}/fonts"
94
95         # This actually follows the directions for a "single-user" system
96         # at http://www.ctan.org/installationadvice/ modified for gentoo.
97         [[ -z $1 ]] && latex-package_src_install all
98
99         while [[ $1 ]]; do
100                 case $1 in
101                         "sh")
102                                 for i in `find . -maxdepth 1 -type f -name "*.${1}"`
103                                 do
104                                         dobin ${i} || die "dobin $i failed"
105                                 done
106                                 ;;
107                         "sty" | "cls" | "fd" | "clo" | "def" | "cfg")
108                                 for i in `find . -maxdepth 1 -type f -name "*.${1}"`
109                                 do
110                                         insinto ${TEXMF}/tex/latex/${PN}
111                                         doins ${i}
112                                 done
113                                 ;;
114                         "dvi" | "ps" | "pdf")
115                                 for i in `find . -maxdepth 1 -type f -name "*.${1}"`
116                                 do
117                                         insinto /usr/share/doc/${PF}
118                                         doins ${i}
119                                         dosym /usr/share/doc/${PF}/$(basename ${i}) ${TEXMF}/doc/latex/${PN}/${i}
120                                                         # prevent compression of symlink target
121                                         docompress -x /usr/share/doc/${PF}/$(basename ${i})
122                                                         ;;
123                                         esac
124                                 done
125                                 ;;
126                         "tex" | "dtx")
127                                 if ! in_iuse doc || use doc ; then
128                                         for i in `find . -maxdepth 1 -type f -name "*.${1}"`
129                                         do
130                                                 [[-n ${LATEX_PACKAGE_SKIP} ]] && has ${i##*/} ${LATEX_PACKAGE_SKIP} && continue
131                                                 einfo "Making documentation: ${i}"
132                                                 if pdflatex ${LATEX_DOC_ARGUMENTS} --halt-on-error --interaction=nonstopmode $i ; then
133                                                         pdflatex ${LATEX_DOC_ARGUMENTS} --halt-on-error --interaction=nonstopmode $i || die
134                                                 else
135                                                         einfo "pdflatex failed, trying texi2dvi"
136                                                         texi2dvi -q -c --language=latex ${i} || die
137                                                 fi
138                                         done
139                                 fi
140                                 ;;
141                         "tfm" | "vf" | "afm")
142                                 for i in `find . -maxdepth 1 -type f -name "*.${1}"`
143                                 do
144                                         insinto ${TEXMF}/fonts/${1}/${SUPPLIER}/${PN}
145                                         doins ${i}
146                                 done
147                                 ;;
148                         "pfb")
149                                 for i in `find . -maxdepth 1 -type f -name "*.pfb"`
150                                 do
151                                         insinto ${TEXMF}/fonts/type1/${SUPPLIER}/${PN}
152                                         doins ${i}
153                                 ;;
154                         "ttf")
155                                 for i in `find . -maxdepth 1 -type f -name "*.ttf"`
156                                 do
157                                         insinto ${TEXMF}/fonts/truetype/${SUPPLIER}/${PN}
158                                         doins ${i}
159                                 done
160                                 ;;
161                         "bst")
162                                 for i in `find . -maxdepth 1 -type f -name "*.bst"`
163                                 do
164                                         insinto ${TEXMF}/bibtex/bst/${PN}
165                                         doins ${i}
166                                 done
167                                 ;;
168                         "styles")
169                                 latex-package_src_doinstall sty cls fd clo def cfg bst
170                                 ;;
171                         "doc")
172                                 latex-package_src_doinstall tex dtx dvi ps pdf
173                                 ;;
174                         "fonts")
175                                 latex-package_src_doinstall tfm vf afm pfb ttf
176                                 ;;
177                         "bin")
178                                 latex-package_src_doinstall sh
179                                 ;;
180                         "all")
181                                 latex-package_src_doinstall styles fonts bin doc
182                                 ;;
183                 esac
184         shift
185         done
186 }
187
188 # @FUNCTION: latex-package_src_compile
189 # @DESCRIPTION:
190 # Calls latex for each *.ins in the current directory in order to generate the
191 # relevant files that will be installed
192 latex-package_src_compile() {
193         debug-print function $FUNCNAME $*
194         for i in `find \`pwd\` -maxdepth 1 -type f -name "*.ins"`
195         do
196                 einfo "Extracting from ${i}"
197                 latex --halt-on-error --interaction=nonstopmode ${i} || die
198         done
199 }
200
201 # @FUNCTION: latex-package_src_install
202 # @DESCRIPTION:
203 # Installs the package
204 latex-package_src_install() {
205         debug-print function $FUNCNAME $*
206         latex-package_src_doinstall all
207         if [[ -n ${DOCS} ]] ; then
208                 dodoc ${DOCS}
209         fi
210 }
211
212 # @FUNCTION: latex-package_pkg_postinst
213 # @DESCRIPTION:
214 # Calls latex-package_rehash to ensure the TeX installation is consistent with
215 # the kpathsea database
216 latex-package_pkg_postinst() {
217         debug-print function $FUNCNAME $*
218         latex-package_rehash
219 }
220
221 # @FUNCTION: latex-package_pkg_postrm
222 # @DESCRIPTION:
223 # Calls latex-package_rehash to ensure the TeX installation is consistent with
224 # the kpathsea database
225 latex-package_pkg_postrm() {
226         debug-print function $FUNCNAME $*
227         latex-package_rehash
228 }
229
230 # @FUNCTION: latex-package_rehash
231 # @DESCRIPTION:
232 # Rehashes the kpathsea database, according to the current TeX installation
233 latex-package_rehash() {
234         debug-print function $FUNCNAME $*
235         texmf-update
236 }
237
238 EXPORT_FUNCTIONS src_compile src_install pkg_postinst pkg_postrm