1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: texlive-module.eclass
8 # 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
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)
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
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.
23 # It inherits texlive-common. Patching is supported via the PATCHES
26 # @ECLASS-VARIABLE: TEXLIVE_MODULE_CONTENTS
29 # The list of packages that will be installed. This variable will be expanded to
31 # foo -> texlive-module-foo-${PV}.tar.xz
33 # @ECLASS-VARIABLE: TEXLIVE_MODULE_DOC_CONTENTS
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.
39 # @ECLASS-VARIABLE: TEXLIVE_MODULE_SRC_CONTENTS
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.
45 # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINSCRIPTS
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
52 # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINLINKS
55 # A space separated list of links to add for BINSCRIPTS.
56 # The systax is: foo:bar to create a symlink bar -> foo.
58 # @ECLASS-VARIABLE: TL_PV
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.
65 # @ECLASS-VARIABLE: TL_MODULE_INFORMATION
68 # Information to display about the package.
69 # e.g. for enabling/disabling a feature
71 if [[ -z ${_TEXLIVE_MODULE_ECLASS} ]]; then
72 _TEXLIVE_MODULE_ECLASS=1
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}" ;;
80 HOMEPAGE="http://www.tug.org/texlive/"
82 COMMON_DEPEND=">=app-text/texlive-core-${TL_PV:-${PV}}"
86 # Starting from TeX Live 2009, upstream provides .tar.xz modules.
89 # Now where should we get these files?
90 TEXLIVE_DEVS=${TEXLIVE_DEVS:- zlogene dilfridge }
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}
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}"
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}"
111 [[ -n ${TEXLIVE_MODULE_DOC_CONTENTS} ]] && SRC_URI="${SRC_URI} )"
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}"
121 SRC_URI="${SRC_URI} )"
124 RDEPEND="${COMMON_DEPEND}"
128 # @ECLASS-VARIABLE: TEXLIVE_MODULE_OPTIONAL_ENGINE
131 # A space separated list of Tex engines that can be made optional.
132 # e.g. "luatex luajittex"
134 if [[ -n ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ]] ; then
135 for engine in ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ; do
136 IUSE="${IUSE} +${engine}"
142 # @FUNCTION: texlive-module_src_unpack
144 # Only for TeX Live 2009 and later.
145 # After unpacking, the files that need to be relocated are moved accordingly.
147 RELOC_TARGET=texmf-dist
149 texlive-module_src_unpack() {
152 sed -n -e 's:\s*RELOC/::p' tlpkg/tlpobj/* > "${T}/reloclist" || die
153 sed -e 's/\/[^/]*$//' -e "s:^:${RELOC_TARGET}/:" "${T}/reloclist" |
155 xargs mkdir -p || die
158 mv "${i}" "${RELOC_TARGET}/${i%/*}" || die
159 done < "${T}/reloclist"
162 # @FUNCTION: texlive-module_add_format
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.
169 texlive-module_add_format() {
170 local name engine mode patterns options
172 einfo "Appending to format.${PN}.cnf for $@"
174 if [[ ! -d texmf-dist/fmtutil ]]; then
175 mkdir -p texmf-dist/fmtutil || die
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
183 [[ -z ${patterns} ]] && patterns="-"
184 printf "${name}\t${engine}\t${patterns}\t${options}\n" >> texmf-dist/fmtutil/format.${PN}.cnf || die
187 # @FUNCTION: texlive-module_make_language_def_lines
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.
192 texlive-module_make_language_def_lines() {
193 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
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
207 # @FUNCTION: texlive-module_make_language_dat_lines
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.
212 texlive-module_make_language_dat_lines() {
213 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
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
225 # @FUNCTION: texlive-module_synonyms_to_language_lua_line
227 # Helper function for texlive-module_make_language_lua_lines to generate a
228 # correctly formatted synonyms entry for language.dat.lua.
230 texlive-module_synonyms_to_language_lua_line() {
232 for i in $(echo $@ | tr ',' ' ') ; do
233 printf "${prev} '%s'" ${i}
238 # @FUNCTION: texlive-module_make_language_lua_lines
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.
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"
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
257 if [[ -n ${file_patterns} ]]; then
258 printf "\t\tpatterns = '%s',\n" "${file_patterns}" >> "${dest}" || die
261 if [[ -n ${file_exceptions} ]]; then
262 printf "\t\thyphenation = '%s',\n" "${file_exceptions}" >> "${dest}" || die
265 if [[ -n ${luaspecial} ]]; then
266 printf "\t\tspecial = '%s',\n" "$luaspecial" >> "${dest}" || die
269 printf "\t},\n" >> "${dest}" || die
272 # @FUNCTION: texlive-module_src_compile
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.
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
284 texlive-module_src_compile() {
285 # Generate config files from the tlpobj files provided by TeX Live 2008 and
287 for i in "${S}"/tlpkg/tlpobj/*;
289 grep '^execute ' "${i}" | sed -e 's/^execute //' | tr ' \t' '##' >> "${T}/jobs" || die
292 for i in $(<"${T}/jobs");
294 j="$(echo $i | tr '#' ' ')"
299 echo "Map ${parameter}" >> "${S}/${PN}.cfg";;
301 echo "MixedMap ${parameter}" >> "${S}/${PN}.cfg";;
303 echo "KanjiMap ${parameter}" >> "${S}/${PN}.cfg";;
305 echo "p +${parameter}" >> "${S}/${PN}-config.ps";;
307 echo "f ${parameter}" >> "${S}/${PN}-config";;
309 texlive-module_make_language_def_lines ${parameter}
310 texlive-module_make_language_dat_lines ${parameter}
311 texlive-module_make_language_lua_lines ${parameter}
314 texlive-module_add_format ${parameter};;
316 einfo "Format ${parameter} already built.";;
318 einfo "Language file $parameter already generated.";;
320 die "No rule to proccess ${command}. Please file a bug."
324 # Determine texlive-core version for fmtutil call
325 fmt_call="$(has_version '>=app-text/texlive-core-2019' \
326 && echo "fmtutil-user" || echo "fmtutil")"
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
335 if [[ ! -d texmf-var/web2c ]]; then
336 mkdir texmf-var/web2c || die
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}"
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
349 # @FUNCTION: texlive-module_src_install
352 # Installs texmf and config files to the system.
354 texlive-module_src_install() {
355 for i in texmf-dist/fmtutil/format*.cnf; do
356 [[ -f ${i} ]] && etexlinks "${i}"
361 if [[ -d texmf-doc ]]; then
362 cp -pR texmf-doc "${ED}/usr/share/" || die
365 if [[ -d texmf-dist/doc ]]; then
366 rm -rf texmf-dist/doc || die
369 if [[ -d texmf/doc ]]; then
370 rm -rf texmf/doc || die
374 if [[ -d texmf ]]; then
375 cp -pR texmf "${ED}/usr/share/" || die
378 if [[ -d texmf-dist ]]; then
379 cp -pR texmf-dist "${ED}/usr/share/" || die
382 if [[ -d tlpkg ]] && use source; then
383 cp -pR tlpkg "${ED}/usr/share/" || die
386 insinto /var/lib/texmf
388 [[ -d texmf-var ]] && doins -r texmf-var/.
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"
397 if [[ -f ${S}/language.${PN}.def ]] ; then
398 insinto /etc/texmf/language.def.d
399 doins "${S}/language.${PN}.def"
402 if [[ -f ${S}/language.${PN}.dat ]] ; then
403 insinto /etc/texmf/language.dat.d
404 doins "${S}/language.${PN}.dat"
407 if [[ -f ${S}/language.${PN}.dat.lua ]] ; then
408 insinto /etc/texmf/language.dat.lua.d
409 doins "${S}/language.${PN}.dat.lua"
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#*:}
420 texlive-common_handle_config_files
421 TEXMF_PATH=${TEXMF_DIST_PATH} texlive-common_handle_config_files
424 # @FUNCTION: texlive-module_pkg_postinst
427 # Run texmf-update to ensure the tex installation is consistent with the
428 # installed texmf trees.
430 texlive-module_pkg_postinst() {
432 [[ -n ${TL_MODULE_INFORMATION} ]] && elog "${TL_MODULE_INFORMATION}"
435 # @FUNCTION: texlive-module_pkg_postrm
438 # Run texmf-update to ensure the tex installation is consistent with the
439 # installed texmf trees.
441 texlive-module_pkg_postrm() {
445 EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm