llvm.eclass: Add initial tests
[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 # Now where should we get these files?
90 TEXLIVE_DEVS=${TEXLIVE_DEVS:- zlogene dilfridge }
91
92 # We do not need anything from SYSROOT:
93 #   Everything is built from the texlive install in /
94 #   Generated files are noarch
95 BDEPEND="${COMMON_DEPEND}
96         app-arch/xz-utils"
97
98 for i in ${TEXLIVE_MODULE_CONTENTS}; do
99         for tldev in ${TEXLIVE_DEVS}; do
100                 SRC_URI="${SRC_URI} https://dev.gentoo.org/~${tldev}/distfiles/texlive/tl-${i}-${PV}.${PKGEXT}"
101         done
102 done
103
104 # Forge doc SRC_URI
105 [[ -n ${TEXLIVE_MODULE_DOC_CONTENTS} ]] && SRC_URI="${SRC_URI} doc? ("
106 for i in ${TEXLIVE_MODULE_DOC_CONTENTS}; do
107         for tldev in ${TEXLIVE_DEVS}; do
108                 SRC_URI="${SRC_URI} https://dev.gentoo.org/~${tldev}/distfiles/texlive/tl-${i}-${PV}.${PKGEXT}"
109         done
110 done
111 [[ -n ${TEXLIVE_MODULE_DOC_CONTENTS} ]] && SRC_URI="${SRC_URI} )"
112
113 # Forge source SRC_URI
114 if [[ -n ${TEXLIVE_MODULE_SRC_CONTENTS} ]] ; then
115         SRC_URI="${SRC_URI} source? ("
116         for i in ${TEXLIVE_MODULE_SRC_CONTENTS}; do
117                 for tldev in ${TEXLIVE_DEVS}; do
118                         SRC_URI="${SRC_URI} https://dev.gentoo.org/~${tldev}/distfiles/texlive/tl-${i}-${PV}.${PKGEXT}"
119                 done
120         done
121         SRC_URI="${SRC_URI} )"
122 fi
123
124 RDEPEND="${COMMON_DEPEND}"
125
126 IUSE="${IUSE} doc"
127
128 # @ECLASS-VARIABLE: TEXLIVE_MODULE_OPTIONAL_ENGINE
129 # @DEFAULT_UNSET
130 # @DESCRIPTION:
131 # A space separated list of Tex engines that can be made optional.
132 # e.g. "luatex luajittex"
133
134 if [[ -n ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ]] ; then
135         for engine in ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ; do
136                 IUSE="${IUSE} +${engine}"
137         done
138 fi
139
140 S="${WORKDIR}"
141
142 # @FUNCTION: texlive-module_src_unpack
143 # @DESCRIPTION:
144 # Only for TeX Live 2009 and later.
145 # After unpacking, the files that need to be relocated are moved accordingly.
146
147 RELOC_TARGET=texmf-dist
148
149 texlive-module_src_unpack() {
150         unpack ${A}
151
152         sed -n -e 's:\s*RELOC/::p' tlpkg/tlpobj/* > "${T}/reloclist" || die
153         sed -e 's/\/[^/]*$//' -e "s:^:${RELOC_TARGET}/:" "${T}/reloclist" |
154                 sort -u |
155                 xargs mkdir -p || die
156         local i
157         while read i; do
158                 mv "${i}" "${RELOC_TARGET}/${i%/*}" || die
159         done < "${T}/reloclist"
160 }
161
162 # @FUNCTION: texlive-module_add_format
163 # @DESCRIPTION:
164 # Creates/appends to a format.${PN}.cnf file for fmtutil.
165 # It parses the AddFormat directive of tlpobj files to create it.
166 # This will make fmtutil generate the formats when asked and allow the remaining
167 # src_compile phase to build the formats.
168
169 texlive-module_add_format() {
170         local name engine mode patterns options
171         eval $@
172         einfo "Appending to format.${PN}.cnf for $@"
173
174         if [[ ! -d texmf-dist/fmtutil ]]; then
175                 mkdir -p texmf-dist/fmtutil || die
176         fi
177
178         [[ -f texmf-dist/fmtutil/format.${PN}.cnf ]] || { echo "# Generated for ${PN}   by texlive-module.eclass" > texmf-dist/fmtutil/format.${PN}.cnf; }
179         [[ -n ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ]] && has ${engine} ${TEXLIVE_MODULE_OPTIONAL_ENGINE} && use !${engine} && mode="disabled"
180         if [[ ${mode} = disabled ]]; then
181                 printf "#! " >> texmf-dist/fmtutil/format.${PN}.cnf || die
182         fi
183         [[ -z ${patterns} ]] && patterns="-"
184         printf "${name}\t${engine}\t${patterns}\t${options}\n" >> texmf-dist/fmtutil/format.${PN}.cnf || die
185 }
186
187 # @FUNCTION: texlive-module_make_language_def_lines
188 # @DESCRIPTION:
189 # Creates a language.${PN}.def entry to put in /etc/texmf/language.def.d.
190 # It parses the AddHyphen directive of tlpobj files to create it.
191
192 texlive-module_make_language_def_lines() {
193         local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
194         eval $@
195         einfo "Generating language.def entry for $@"
196         [[ -z ${lefthyphenmin} ]] && lefthyphenmin="2"
197         [[ -z ${righthyphenmin} ]] && righthyphenmin="3"
198         echo "\\addlanguage{$name}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def" || die
199         if [[ -n ${synonyms} ]]; then
200                 for i in $(echo $synonyms | tr ',' ' ') ; do
201                         einfo "Generating language.def synonym $i for $@"
202                         echo "\\addlanguage{$i}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def" || die
203                 done
204         fi
205 }
206
207 # @FUNCTION: texlive-module_make_language_dat_lines
208 # @DESCRIPTION:
209 # Creates a language.${PN}.dat entry to put in /etc/texmf/language.dat.d.
210 # It parses the AddHyphen directive of tlpobj files to create it.
211
212 texlive-module_make_language_dat_lines() {
213         local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
214         eval $@
215         einfo "Generating language.dat entry for $@"
216         echo "$name $file" >> "${S}/language.${PN}.dat" || die
217         if [[ -n ${synonyms} ]]; then
218                 for i in $(echo ${synonyms} | tr ',' ' ') ; do
219                         einfo "Generating language.dat synonym ${i} for $@"
220                         echo "=${i}" >> "${S}/language.${PN}.dat" || die
221                 done
222         fi
223 }
224
225 # @FUNCTION: texlive-module_synonyms_to_language_lua_line
226 # @DESCRIPTION:
227 # Helper function for texlive-module_make_language_lua_lines to generate a
228 # correctly formatted synonyms entry for language.dat.lua.
229
230 texlive-module_synonyms_to_language_lua_line() {
231         local prev=""
232         for i in $(echo $@ | tr ',' ' ') ; do
233                 printf "${prev} '%s'" ${i}
234                 prev=","
235         done
236 }
237
238 # @FUNCTION: texlive-module_make_language_lua_lines
239 # @DESCRIPTION:
240 # Only valid for TeXLive 2010 and later.
241 # Creates a language.${PN}.dat.lua entry to put in
242 # /etc/texmf/language.dat.lua.d.
243 # It parses the AddHyphen directive of tlpobj files to create it.
244
245 texlive-module_make_language_lua_lines() {
246         local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
247         local dest="${S}/language.${PN}.dat.lua"
248         eval $@
249         [[ -z ${lefthyphenmin}  ]] && lefthyphenmin="2"
250         [[ -z ${righthyphenmin} ]] && righthyphenmin="3"
251         einfo "Generating language.dat.lua entry for $@"
252         printf "\t['%s'] = {\n" "${name}"                                                                   >> "${dest}" || die
253         printf "\t\tloader = '%s',\n" "${file}"                                                             >> "${dest}" || die
254         printf "\t\tlefthyphenmin = %s,\n\t\trighthyphenmin = %s,\n" "${lefthyphenmin}" "${righthyphenmin}" >> "${dest}" || die
255         printf "\t\tsynonyms = {%s },\n" "$(texlive-module_synonyms_to_language_lua_line "${synonyms}")"    >> "${dest}" || die
256
257         if [[ -n ${file_patterns} ]]; then
258                 printf "\t\tpatterns = '%s',\n" "${file_patterns}"                   >> "${dest}" || die
259         fi
260
261         if [[ -n ${file_exceptions} ]]; then
262                 printf "\t\thyphenation = '%s',\n"      "${file_exceptions}"          >> "${dest}" || die
263         fi
264
265         if [[ -n ${luaspecial} ]]; then
266                 printf "\t\tspecial = '%s',\n" "$luaspecial"                          >> "${dest}" || die
267         fi
268
269         printf "\t},\n"                                                                >> "${dest}" || die
270 }
271
272 # @FUNCTION: texlive-module_src_compile
273 # @DESCRIPTION:
274 # exported function:
275 # Generates the config files that are to be installed in /etc/texmf;
276 # texmf-update script will take care of merging the different config files for
277 # different packages in a single one used by the whole tex installation.
278 #
279 # Once the config files are generated, we build the format files using fmtutil
280 # (provided by texlive-core). The compiled format files will be sent to
281 # texmf-var/web2c, like fmtutil defaults to but with some trick to stay in the
282 # sandbox.
283
284 texlive-module_src_compile() {
285         # Generate config files from the tlpobj files provided by TeX Live 2008 and
286         # later
287         for i in "${S}"/tlpkg/tlpobj/*;
288         do
289                 grep '^execute ' "${i}" | sed -e 's/^execute //' | tr ' \t' '##' >> "${T}/jobs" || die
290         done
291
292         for i in $(<"${T}/jobs");
293         do
294                 j="$(echo $i | tr '#' ' ')"
295                 command=${j%% *}
296                 parameter=${j#* }
297                 case ${command} in
298                         addMap)
299                                 echo "Map ${parameter}" >> "${S}/${PN}.cfg";;
300                         addMixedMap)
301                                 echo "MixedMap ${parameter}" >> "${S}/${PN}.cfg";;
302                         addKanjiMap)
303                                 echo "KanjiMap ${parameter}" >> "${S}/${PN}.cfg";;
304                         addDvipsMap)
305                                 echo "p +${parameter}" >> "${S}/${PN}-config.ps";;
306                         addDvipdfmMap)
307                                 echo "f ${parameter}" >> "${S}/${PN}-config";;
308                         AddHyphen)
309                                 texlive-module_make_language_def_lines ${parameter}
310                                 texlive-module_make_language_dat_lines ${parameter}
311                                 texlive-module_make_language_lua_lines ${parameter}
312                                 ;;
313                         AddFormat)
314                                 texlive-module_add_format ${parameter};;
315                         BuildFormat)
316                                 einfo "Format ${parameter} already built.";;
317                         BuildLanguageDat)
318                                 einfo "Language file $parameter already generated.";;
319                         *)
320                                 die "No rule to proccess ${command}. Please file a bug."
321                 esac
322         done
323
324         # Determine texlive-core version for fmtutil call
325         fmt_call="$(has_version '>=app-text/texlive-core-2019' \
326          && echo "fmtutil-user" || echo "fmtutil")"
327
328         # Build format files
329         for i in texmf-dist/fmtutil/format*.cnf; do
330                 if [[ -f ${i} ]]; then
331                         einfo "Building format ${i}"
332                         if [[ ! -d texmf-var ]]; then
333                                 mkdir texmf-var || die
334                         fi
335                         if [[ ! -d texmf-var/web2c ]]; then
336                                 mkdir texmf-var/web2c || die
337                         fi
338                         VARTEXFONTS="${T}/fonts" TEXMFHOME="${S}/texmf:${S}/texmf-dist:${S}/texmf-var"\
339                                 env -u TEXINPUTS $fmt_call --cnffile "${i}" --fmtdir "${S}/texmf-var/web2c" --all\
340                                 || die "failed to build format ${i}"
341                 fi
342         done
343
344         # Delete ls-R files, these should not be created but better be certain they
345         # do not end up being installed.
346         find . -name 'ls-R' -delete || die
347 }
348
349 # @FUNCTION: texlive-module_src_install
350 # @DESCRIPTION:
351 # exported function:
352 # Installs texmf and config files to the system.
353
354 texlive-module_src_install() {
355         for i in texmf-dist/fmtutil/format*.cnf; do
356                 [[ -f ${i} ]] && etexlinks "${i}"
357         done
358
359         dodir /usr/share
360         if use doc; then
361                 if [[ -d texmf-doc ]]; then
362                         cp -pR texmf-doc "${ED}/usr/share/" || die
363                 fi
364         else
365                 if [[ -d texmf-dist/doc ]]; then
366                         rm -rf texmf-dist/doc || die
367                 fi
368
369                 if [[ -d texmf/doc ]]; then
370                         rm -rf texmf/doc || die
371                 fi
372         fi
373
374         if [[ -d texmf ]]; then
375                 cp -pR texmf "${ED}/usr/share/" || die
376         fi
377
378         if [[ -d texmf-dist ]]; then
379                 cp -pR texmf-dist "${ED}/usr/share/" || die
380         fi
381
382         if [[ -d tlpkg ]] && use source; then
383                 cp -pR tlpkg "${ED}/usr/share/" || die
384         fi
385
386         insinto /var/lib/texmf
387
388         [[ -d texmf-var ]] && doins -r texmf-var/.
389
390         insinto /etc/texmf/updmap.d
391         [[ -f ${S}/${PN}.cfg ]] && doins "${S}/${PN}.cfg"
392         insinto /etc/texmf/dvips.d
393         [[ -f ${S}/${PN}-config.ps ]] && doins "${S}/${PN}-config.ps"
394         insinto /etc/texmf/dvipdfm/config
395         [[ -f ${S}/${PN}-config ]] && doins "${S}/${PN}-config"
396
397         if [[ -f ${S}/language.${PN}.def ]] ; then
398                 insinto /etc/texmf/language.def.d
399                 doins "${S}/language.${PN}.def"
400         fi
401
402         if [[ -f ${S}/language.${PN}.dat ]] ; then
403                 insinto /etc/texmf/language.dat.d
404                 doins "${S}/language.${PN}.dat"
405         fi
406
407         if [[ -f ${S}/language.${PN}.dat.lua ]] ; then
408                 insinto /etc/texmf/language.dat.lua.d
409                 doins "${S}/language.${PN}.dat.lua"
410         fi
411
412         [[ -n ${TEXLIVE_MODULE_BINSCRIPTS} ]] && dobin_texmf_scripts ${TEXLIVE_MODULE_BINSCRIPTS}
413         if [[ -n ${TEXLIVE_MODULE_BINLINKS} ]] ; then
414                 for i in ${TEXLIVE_MODULE_BINLINKS} ; do
415                         [[ -f ${ED}/usr/bin/${i%:*} ]] || die "Trying to install an invalid     BINLINK. This should not happen. Please file a bug."
416                         dosym ${i%:*} /usr/bin/${i#*:}
417                 done
418         fi
419
420         texlive-common_handle_config_files
421         TEXMF_PATH=${TEXMF_DIST_PATH} texlive-common_handle_config_files
422 }
423
424 # @FUNCTION: texlive-module_pkg_postinst
425 # @DESCRIPTION:
426 # exported function:
427 # Run texmf-update to ensure the tex installation is consistent with the
428 # installed texmf trees.
429
430 texlive-module_pkg_postinst() {
431         etexmf-update
432         [[ -n ${TL_MODULE_INFORMATION} ]] && elog "${TL_MODULE_INFORMATION}"
433 }
434
435 # @FUNCTION: texlive-module_pkg_postrm
436 # @DESCRIPTION:
437 # exported function:
438 # Run texmf-update to ensure the tex installation is consistent with the
439 # installed texmf trees.
440
441 texlive-module_pkg_postrm() {
442         etexmf-update
443 }
444
445 EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm
446
447 fi