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