net-wireless/hostapd: use #!/sbin/openrc-run instead of #!/sbin/runscript
[gentoo.git] / eclass / latex-package.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: latex-package.eclass
6 # @MAINTAINER:
7 # TeX team <tex@gentoo.org>
8 # @AUTHOR:
9 # Matthew Turk <satai@gentoo.org>
10 # Martin Ehmsen <ehmsen@gentoo.org>
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 case ${EAPI:-0} in
57         0|1|2|3|4|5) inherit base eutils ;;
58         6) ;;
59         *) die "Unknown EAPI ${EAPI} for ${ECLASS}" ;;
60 esac
61
62 RDEPEND="virtual/latex-base"
63 DEPEND="${RDEPEND}
64         >=sys-apps/texinfo-4.2-r5"
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 # Kept for backwards compatibility
82 latex-package_has_tetex_3() {
83         case ${EAPI:-0} in
84                 0|1|2|3|4|5) return 0 ;;
85                 *) die "${FUNCNAME} no longer supported in EAPI ${EAPI}" ;;
86         esac
87 }
88
89 # @FUNCTION: latex-package_src_doinstall
90 # @USAGE: [ module ]
91 # @DESCRIPTION:
92 # [module] can be one or more of: sh, sty, cls, fd, clo, def, cfg, dvi, ps, pdf,
93 # tex, dtx, tfm, vf, afm, pfb, ttf, bst, styles, doc, fonts, bin, or all.
94 # If [module] is not given, all is assumed.
95 # It installs the files found in the current directory to the standard locations
96 # for a TeX installation
97 latex-package_src_doinstall() {
98         debug-print function $FUNCNAME $*
99
100         # Avoid generating font cache outside of the sandbox
101         export VARTEXFONTS="${T}/fonts"
102
103         # This actually follows the directions for a "single-user" system
104         # at http://www.ctan.org/installationadvice/ modified for gentoo.
105         [ -z "$1" ] && latex-package_src_install all
106
107         while [ "$1" ]; do
108                 case $1 in
109                         "sh")
110                                 for i in `find . -maxdepth 1 -type f -name "*.${1}"`
111                                 do
112                                         dobin $i || die "dobin $i failed"
113                                 done
114                                 ;;
115                         "sty" | "cls" | "fd" | "clo" | "def" | "cfg")
116                                 for i in `find . -maxdepth 1 -type f -name "*.${1}"`
117                                 do
118                                         insinto ${TEXMF}/tex/latex/${PN}
119                                         doins $i || die "doins $i failed"
120                                 done
121                                 ;;
122                         "dvi" | "ps" | "pdf")
123                                 for i in `find . -maxdepth 1 -type f -name "*.${1}"`
124                                 do
125                                         insinto /usr/share/doc/${PF}
126                                         doins $i || die "doins $i failed"
127                                         dosym /usr/share/doc/${PF}/$(basename ${i}) ${TEXMF}/doc/latex/${PN}/${i}
128                                         case "${EAPI:-0}" in
129                                                 0|1|2|3) ;;
130                                                 *)
131                                                         # prevent compression of symlink target
132                                                         docompress -x /usr/share/doc/${PF}/$(basename ${i})
133                                                         ;;
134                                         esac
135                                 done
136                                 ;;
137                         "tex" | "dtx")
138                                 if ! in_iuse doc || use doc ; then
139                                         for i in `find . -maxdepth 1 -type f -name "*.${1}"`
140                                         do
141                                                 einfo "Making documentation: $i"
142                                                 if pdflatex ${LATEX_DOC_ARGUMENTS} --interaction=batchmode $i &> /dev/null ; then
143                                                         pdflatex ${LATEX_DOC_ARGUMENTS} --interaction=batchmode $i &> /dev/null || die
144                                                 else
145                                                         einfo "pdflatex failed, trying texi2dvi"
146                                                         texi2dvi -q -c --language=latex $i &> /dev/null || die
147                                                 fi
148                                         done
149                                 fi
150                                 ;;
151                         "tfm" | "vf" | "afm")
152                                 for i in `find . -maxdepth 1 -type f -name "*.${1}"`
153                                 do
154                                         insinto ${TEXMF}/fonts/${1}/${SUPPLIER}/${PN}
155                                         doins $i || die "doins $i failed"
156                                 done
157                                 ;;
158                         "pfb")
159                                 for i in `find . -maxdepth 1 -type f -name "*.pfb"`
160                                 do
161                                         insinto ${TEXMF}/fonts/type1/${SUPPLIER}/${PN}
162                                         doins $i || die "doins $i failed"
163                                 done
164                                 ;;
165                         "ttf")
166                                 for i in `find . -maxdepth 1 -type f -name "*.ttf"`
167                                 do
168                                         insinto ${TEXMF}/fonts/truetype/${SUPPLIER}/${PN}
169                                         doins $i || die "doins $i failed"
170                                 done
171                                 ;;
172                         "bst")
173                                 for i in `find . -maxdepth 1 -type f -name "*.bst"`
174                                 do
175                                         insinto ${TEXMF}/bibtex/bst/${PN}
176                                         doins $i || die "doins $i failed"
177                                 done
178                                 ;;
179                         "styles")
180                                 latex-package_src_doinstall sty cls fd clo def cfg bst
181                                 ;;
182                         "doc")
183                                 latex-package_src_doinstall tex dtx dvi ps pdf
184                                 ;;
185                         "fonts")
186                                 latex-package_src_doinstall tfm vf afm pfb ttf
187                                 ;;
188                         "bin")
189                                 latex-package_src_doinstall sh
190                                 ;;
191                         "all")
192                                 latex-package_src_doinstall styles fonts bin doc
193                                 ;;
194                 esac
195         shift
196         done
197 }
198
199 # @FUNCTION: latex-package_src_compile
200 # @DESCRIPTION:
201 # Calls latex for each *.ins in the current directory in order to generate the
202 # relevant files that will be installed
203 latex-package_src_compile() {
204         debug-print function $FUNCNAME $*
205         for i in `find \`pwd\` -maxdepth 1 -type f -name "*.ins"`
206         do
207                 einfo "Extracting from $i"
208                 latex --interaction=batchmode $i &> /dev/null || die
209         done
210 }
211
212 # @FUNCTION: latex-package_src_install
213 # @DESCRIPTION:
214 # Installs the package
215 latex-package_src_install() {
216         debug-print function $FUNCNAME $*
217         latex-package_src_doinstall all
218         if [ -n "${DOCS}" ] ; then
219                 dodoc ${DOCS}
220         fi
221 }
222
223 # @FUNCTION: latex-package_pkg_postinst
224 # @DESCRIPTION:
225 # Calls latex-package_rehash to ensure the TeX installation is consistent with
226 # the kpathsea database
227 latex-package_pkg_postinst() {
228         debug-print function $FUNCNAME $*
229         latex-package_rehash
230 }
231
232 # @FUNCTION: latex-package_pkg_postrm
233 # @DESCRIPTION:
234 # Calls latex-package_rehash to ensure the TeX installation is consistent with
235 # the kpathsea database
236 latex-package_pkg_postrm() {
237         debug-print function $FUNCNAME $*
238         latex-package_rehash
239 }
240
241 # @FUNCTION: latex-package_rehash
242 # @DESCRIPTION:
243 # Rehashes the kpathsea database, according to the current TeX installation
244 latex-package_rehash() {
245         debug-print function $FUNCNAME $*
246         texmf-update
247 }
248
249 EXPORT_FUNCTIONS src_compile src_install pkg_postinst pkg_postrm