net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / texlive-module.eclass
1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: texlive-module.eclass
6 # @MAINTAINER:
7 # tex@gentoo.org
8 # @AUTHOR:
9 # Original Author: Alexis Ballier <aballier@gentoo.org>
10 # @BLURB: Provide generic install functions so that modular texlive's texmf ebuild will only have to inherit this eclass
11 # @DESCRIPTION:
12 # Purpose: Provide generic install functions so that modular texlive's texmf ebuilds will
13 # only have to inherit this eclass.
14 # Ebuilds have to provide TEXLIVE_MODULE_CONTENTS variable that contains the list
15 # of packages that it will install. (See below)
16 #
17 # For TeX Live versions prior to 2009, the ebuild was supposed to unpack the
18 # texmf and texmf-dist directories to ${WORKDIR} (which is what the default
19 # src_unpack does).
20 # Starting from TeX Live 2009, the eclass provides a src_unpack function taking
21 # care of unpacking and relocating the files that need it.
22 #
23 # It inherits texlive-common.  Patching is supported via the PATCHES
24 # bash array.
25
26 # @ECLASS-VARIABLE: TEXLIVE_MODULE_CONTENTS
27 # @DESCRIPTION:
28 # The list of packages that will be installed. This variable will be expanded to
29 # SRC_URI:
30 # foo -> texlive-module-foo-${PV}.tar.xz
31
32 # @ECLASS-VARIABLE: TEXLIVE_MODULE_DOC_CONTENTS
33 # @DESCRIPTION:
34 # The list of packages that will be installed if the doc useflag is enabled.
35 # Expansion to SRC_URI is the same as for TEXLIVE_MODULE_CONTENTS.
36
37 # @ECLASS-VARIABLE: TEXLIVE_MODULE_SRC_CONTENTS
38 # @DESCRIPTION:
39 # The list of packages that will be installed if the source useflag is enabled.
40 # Expansion to SRC_URI is the same as for TEXLIVE_MODULE_CONTENTS.
41
42 # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINSCRIPTS
43 # @DESCRIPTION:
44 # A space separated list of files that are in fact scripts installed in the
45 # texmf tree and that we want to be available directly. They will be installed in
46 # /usr/bin.
47
48 # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINLINKS
49 # @DESCRIPTION:
50 # A space separated list of links to add for BINSCRIPTS.
51 # The systax is: foo:bar to create a symlink bar -> foo.
52
53 # @ECLASS-VARIABLE: TL_PV
54 # @DESCRIPTION:
55 # Normally the module's PV reflects the TeXLive release it belongs to.
56 # If this is not the case, TL_PV takes the version number for the
57 # needed app-text/texlive-core.
58
59 # @ECLASS-VARIABLE: TL_MODULE_INFORMATION
60 # @DESCRIPTION:
61 # Information to display about the package.
62 # e.g. for enabling/disabling a feature
63
64 # @ECLASS-VARIABLE: PATCHES
65 # @DESCRIPTION:
66 # Array variable specifying any patches to be applied.
67
68 inherit texlive-common eutils
69
70 case "${EAPI:-0}" in
71         0|1|2)
72                 die "EAPI='${EAPI}' is not supported anymore"
73                 ;;
74         *)
75                 ;;
76 esac
77
78 HOMEPAGE="http://www.tug.org/texlive/"
79
80 COMMON_DEPEND=">=app-text/texlive-core-${TL_PV:-${PV}}"
81
82 IUSE="source"
83
84 # Starting from TeX Live 2009, upstream provides .tar.xz modules.
85 PKGEXT=tar.xz
86 DEPEND="${COMMON_DEPEND}
87         app-arch/xz-utils"
88
89 for i in ${TEXLIVE_MODULE_CONTENTS}; do
90         SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
91 done
92
93 # Forge doc SRC_URI
94 [ -n "${PN##*documentation*}" ] && [ -n "${TEXLIVE_MODULE_DOC_CONTENTS}" ] && SRC_URI="${SRC_URI} doc? ("
95 for i in ${TEXLIVE_MODULE_DOC_CONTENTS}; do
96         SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
97 done
98 [ -n "${PN##*documentation*}" ] && [ -n "${TEXLIVE_MODULE_DOC_CONTENTS}" ] && SRC_URI="${SRC_URI} )"
99
100 # Forge source SRC_URI
101 if [ -n "${TEXLIVE_MODULE_SRC_CONTENTS}" ] ; then
102         SRC_URI="${SRC_URI} source? ("
103         for i in ${TEXLIVE_MODULE_SRC_CONTENTS}; do
104                 SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
105         done
106         SRC_URI="${SRC_URI} )"
107 fi
108
109 RDEPEND="${COMMON_DEPEND}"
110
111 [ -z "${PN##*documentation*}" ] || IUSE="${IUSE} doc"
112
113 # @ECLASS-VARIABLE: TEXLIVE_MODULE_OPTIONAL_ENGINE
114 # @DESCRIPTION:
115 # A space separated list of Tex engines that can be made optional.
116 # e.g. "luatex luajittex"
117
118 if [ -n "${TEXLIVE_MODULE_OPTIONAL_ENGINE}" ] ; then
119         for engine in ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ; do
120                 IUSE="${IUSE} +${engine}"
121         done
122 fi
123
124 S="${WORKDIR}"
125
126 # @FUNCTION: texlive-module_src_unpack
127 # @DESCRIPTION:
128 # Only for TeX Live 2009 and later.
129 # After unpacking, the files that need to be relocated are moved accordingly.
130
131 RELOC_TARGET=texmf-dist
132
133 texlive-module_src_unpack() {
134         unpack ${A}
135
136         grep RELOC tlpkg/tlpobj/* | awk '{print $2}' | sed 's#^RELOC/##' > "${T}/reloclist"
137         { for i in $(<"${T}/reloclist"); do  dirname $i; done; } | uniq > "${T}/dirlist"
138         for i in $(<"${T}/dirlist"); do
139                 [ -d "${RELOC_TARGET}/${i}" ] || mkdir -p "${RELOC_TARGET}/${i}"
140         done
141         for i in $(<"${T}/reloclist"); do
142                 mv "${i}" "${RELOC_TARGET}"/$(dirname "${i}") || die "failed to relocate ${i} to ${RELOC_TARGET}/$(dirname ${i})"
143         done
144 }
145
146 # @FUNCTION: texlive-module_src_prepare
147 # @DESCRIPTION:
148 # Apply patches from the PATCHES array and user patches, if any.
149
150 texlive-module_src_prepare() {
151         [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
152         epatch_user
153 }
154
155 # @FUNCTION: texlive-module_add_format
156 # @DESCRIPTION:
157 # Creates/appends to a format.${PN}.cnf file for fmtutil.
158 # It parses the AddFormat directive of tlpobj files to create it.
159 # This will make fmtutil generate the formats when asked and allow the remaining
160 # src_compile phase to build the formats.
161
162 texlive-module_add_format() {
163         local name engine mode patterns options
164         eval $@
165         einfo "Appending to format.${PN}.cnf for $@"
166         [ -d texmf-dist/fmtutil ] || mkdir -p texmf-dist/fmtutil
167         [ -f texmf-dist/fmtutil/format.${PN}.cnf ] || { echo "# Generated for ${PN}     by texlive-module.eclass" > texmf-dist/fmtutil/format.${PN}.cnf; }
168         [ -n "${TEXLIVE_MODULE_OPTIONAL_ENGINE}" ] && has ${engine} ${TEXLIVE_MODULE_OPTIONAL_ENGINE} && use !${engine} && mode="disabled"
169         if [ "${mode}" = "disabled" ]; then
170                 printf "#! " >> texmf-dist/fmtutil/format.${PN}.cnf
171         fi
172         [ -z "${patterns}" ] && patterns="-"
173         printf "${name}\t${engine}\t${patterns}\t${options}\n" >> texmf-dist/fmtutil/format.${PN}.cnf
174 }
175
176 # @FUNCTION: texlive-module_make_language_def_lines
177 # @DESCRIPTION:
178 # Creates a language.${PN}.def entry to put in /etc/texmf/language.def.d.
179 # It parses the AddHyphen directive of tlpobj files to create it.
180
181 texlive-module_make_language_def_lines() {
182         local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
183         eval $@
184         einfo "Generating language.def entry for $@"
185         [ -z "$lefthyphenmin" ] && lefthyphenmin="2"
186         [ -z "$righthyphenmin" ] && righthyphenmin="3"
187         echo "\\addlanguage{$name}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def"
188         if [ -n "$synonyms" ] ; then
189                 for i in $(echo $synonyms | tr ',' ' ') ; do
190                         einfo "Generating language.def synonym $i for $@"
191                         echo "\\addlanguage{$i}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def"
192                 done
193         fi
194 }
195
196 # @FUNCTION: texlive-module_make_language_dat_lines
197 # @DESCRIPTION:
198 # Creates a language.${PN}.dat entry to put in /etc/texmf/language.dat.d.
199 # It parses the AddHyphen directive of tlpobj files to create it.
200
201 texlive-module_make_language_dat_lines() {
202         local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
203         eval $@
204         einfo "Generating language.dat entry for $@"
205         echo "$name $file" >> "${S}/language.${PN}.dat"
206         if [ -n "$synonyms" ] ; then
207                 for i in $(echo $synonyms | tr ',' ' ') ; do
208                         einfo "Generating language.dat synonym $i for $@"
209                         echo "=$i" >> "${S}/language.${PN}.dat"
210                 done
211         fi
212 }
213
214 # @FUNCTION: texlive-module_synonyms_to_language_lua_line
215 # @DESCRIPTION:
216 # Helper function for texlive-module_make_language_lua_lines to generate a
217 # correctly formatted synonyms entry for language.dat.lua.
218
219 texlive-module_synonyms_to_language_lua_line() {
220         local prev=""
221         for i in $(echo $@ | tr ',' ' ') ; do
222                 printf "${prev} '%s'" $i
223                 prev=","
224         done
225 }
226
227 # @FUNCTION: texlive-module_make_language_lua_lines
228 # @DESCRIPTION:
229 # Only valid for TeXLive 2010 and later.
230 # Creates a language.${PN}.dat.lua entry to put in
231 # /etc/texmf/language.dat.lua.d.
232 # It parses the AddHyphen directive of tlpobj files to create it.
233
234 texlive-module_make_language_lua_lines() {
235         local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
236         local dest="${S}/language.${PN}.dat.lua"
237         eval $@
238         [ -z "$lefthyphenmin"  ] && lefthyphenmin="2"
239         [ -z "$righthyphenmin" ] && righthyphenmin="3"
240         einfo "Generating language.dat.lua entry for $@"
241         printf "\t['%s'] = {\n" "$name"                                                                 >> "$dest"
242         printf "\t\tloader = '%s',\n" "$file"                                                           >> "$dest"
243         printf "\t\tlefthyphenmin = %s,\n\t\trighthyphenmin = %s,\n" "$lefthyphenmin" "$righthyphenmin" >> "$dest"
244         printf "\t\tsynonyms = {%s },\n" "$(texlive-module_synonyms_to_language_lua_line "$synonyms")"  >> "$dest"
245         [ -n "$file_patterns"   ] && printf "\t\tpatterns = '%s',\n" "$file_patterns"                   >> "$dest"
246         [ -n "$file_exceptions" ] && printf "\t\thyphenation = '%s',\n" "$file_exceptions"              >> "$dest"
247         [ -n "$luaspecial"      ] && printf "\t\tspecial = '%s',\n" "$luaspecial"                       >> "$dest"
248         printf "\t},\n"                                                                                 >> "$dest"
249 }
250
251 # @FUNCTION: texlive-module_src_compile
252 # @DESCRIPTION:
253 # exported function:
254 # Generates the config files that are to be installed in /etc/texmf;
255 # texmf-update script will take care of merging the different config files for
256 # different packages in a single one used by the whole tex installation.
257 #
258 # Once the config files are generated, we build the format files using fmtutil
259 # (provided by texlive-core). The compiled format files will be sent to
260 # texmf-var/web2c, like fmtutil defaults to but with some trick to stay in the
261 # sandbox.
262
263 texlive-module_src_compile() {
264         # Generate config files from the tlpobj files provided by TeX Live 2008 and
265         # later
266         for i in "${S}"/tlpkg/tlpobj/*;
267         do
268                 grep '^execute ' "${i}" | sed -e 's/^execute //' | tr ' \t' '##' >> "${T}/jobs"
269         done
270
271         for i in $(<"${T}/jobs");
272         do
273                 j="$(echo $i | tr '#' ' ')"
274                 command=${j%% *}
275                 parameter=${j#* }
276                 case "${command}" in
277                         addMap)
278                                 echo "Map ${parameter}" >> "${S}/${PN}.cfg";;
279                         addMixedMap)
280                                 echo "MixedMap ${parameter}" >> "${S}/${PN}.cfg";;
281                         addKanjiMap)
282                                 echo "KanjiMap ${parameter}" >> "${S}/${PN}.cfg";;
283                         addDvipsMap)
284                                 echo "p +${parameter}" >> "${S}/${PN}-config.ps";;
285                         addDvipdfmMap)
286                                 echo "f ${parameter}" >> "${S}/${PN}-config";;
287                         AddHyphen)
288                                 texlive-module_make_language_def_lines "$parameter"
289                                 texlive-module_make_language_dat_lines "$parameter"
290                                 texlive-module_make_language_lua_lines "$parameter"
291                                 ;;
292                         AddFormat)
293                                 texlive-module_add_format "$parameter";;
294                         BuildFormat)
295                                 einfo "Format $parameter already built.";;
296                         BuildLanguageDat)
297                                 einfo "Language file $parameter already generated.";;
298                         *)
299                                 die "No rule to proccess ${command}. Please file a bug."
300                 esac
301         done
302
303         # Build format files
304         for i in texmf-dist/fmtutil/format*.cnf; do
305                 if [ -f "${i}" ]; then
306                         einfo "Building format ${i}"
307                         [ -d texmf-var ] || mkdir texmf-var
308                         [ -d texmf-var/web2c ] || mkdir texmf-var/web2c
309                         VARTEXFONTS="${T}/fonts" TEXMFHOME="${S}/texmf:${S}/texmf-dist:${S}/texmf-var"\
310                                 env -u TEXINPUTS fmtutil --cnffile "${i}" --fmtdir "${S}/texmf-var/web2c" --all\
311                                 || die "failed to build format ${i}"
312                 fi
313         done
314
315         # Delete ls-R files, these should not be created but better be certain they
316         # do not end up being installed.
317         find . -name 'ls-R' -delete
318 }
319
320 # @FUNCTION: texlive-module_src_install
321 # @DESCRIPTION:
322 # exported function:
323 # Installs texmf and config files to the system.
324
325 texlive-module_src_install() {
326         for i in texmf-dist/fmtutil/format*.cnf; do
327                 [ -f "${i}" ] && etexlinks "${i}"
328         done
329
330         dodir /usr/share
331         if [ -z "${PN##*documentation*}" ] || use doc; then
332                 [ -d texmf-doc ] && cp -pR texmf-doc "${ED}/usr/share/"
333         else
334                 [ -d texmf/doc ] && rm -rf texmf/doc
335                 [ -d texmf-dist/doc ] && rm -rf texmf-dist/doc
336         fi
337
338         [ -d texmf ] && cp -pR texmf "${ED}/usr/share/"
339         [ -d texmf-dist ] && cp -pR texmf-dist "${ED}/usr/share/"
340         [ -d tlpkg ] && use source && cp -pR tlpkg "${ED}/usr/share/"
341
342         insinto /var/lib/texmf
343         [ -d texmf-var ] && doins -r texmf-var/*
344
345         insinto /etc/texmf/updmap.d
346         [ -f "${S}/${PN}.cfg" ] && doins "${S}/${PN}.cfg"
347         insinto /etc/texmf/dvips.d
348         [ -f "${S}/${PN}-config.ps" ] && doins "${S}/${PN}-config.ps"
349         insinto /etc/texmf/dvipdfm/config
350         [ -f "${S}/${PN}-config" ] && doins "${S}/${PN}-config"
351
352         if [ -f "${S}/language.${PN}.def" ] ; then
353                 insinto /etc/texmf/language.def.d
354                 doins "${S}/language.${PN}.def"
355         fi
356
357         if [ -f "${S}/language.${PN}.dat" ] ; then
358                 insinto /etc/texmf/language.dat.d
359                 doins "${S}/language.${PN}.dat"
360         fi
361
362         if [ -f "${S}/language.${PN}.dat.lua" ] ; then
363                 insinto /etc/texmf/language.dat.lua.d
364                 doins "${S}/language.${PN}.dat.lua"
365         fi
366
367         [ -n "${TEXLIVE_MODULE_BINSCRIPTS}" ] && dobin_texmf_scripts ${TEXLIVE_MODULE_BINSCRIPTS}
368         if [ -n "${TEXLIVE_MODULE_BINLINKS}" ] ; then
369                 for i in ${TEXLIVE_MODULE_BINLINKS} ; do
370                         [ -f "${ED}/usr/bin/${i%:*}" ] || die "Trying to install an invalid     BINLINK. This should not happen. Please file a bug."
371                         dosym ${i%:*} /usr/bin/${i#*:}
372                 done
373         fi
374
375         texlive-common_handle_config_files
376         TEXMF_PATH=${TEXMF_DIST_PATH} texlive-common_handle_config_files
377 }
378
379 # @FUNCTION: texlive-module_pkg_postinst
380 # @DESCRIPTION:
381 # exported function:
382 # Run texmf-update to ensure the tex installation is consistent with the
383 # installed texmf trees.
384
385 texlive-module_pkg_postinst() {
386         etexmf-update
387         [ -n "${TL_MODULE_INFORMATION}" ] && elog "${TL_MODULE_INFORMATION}"
388 }
389
390 # @FUNCTION: texlive-module_pkg_postrm
391 # @DESCRIPTION:
392 # exported function:
393 # Run texmf-update to ensure the tex installation is consistent with the
394 # installed texmf trees.
395
396 texlive-module_pkg_postrm() {
397         etexmf-update
398 }
399
400 EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install \
401         pkg_postinst pkg_postrm