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 # 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}
95 for i in ${TEXLIVE_MODULE_CONTENTS}; do
96 SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
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}"
104 [[ -n ${TEXLIVE_MODULE_DOC_CONTENTS} ]] && SRC_URI="${SRC_URI} )"
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}"
112 SRC_URI="${SRC_URI} )"
115 RDEPEND="${COMMON_DEPEND}"
119 # @ECLASS-VARIABLE: TEXLIVE_MODULE_OPTIONAL_ENGINE
122 # A space separated list of Tex engines that can be made optional.
123 # e.g. "luatex luajittex"
125 if [[ -n ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ]] ; then
126 for engine in ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ; do
127 IUSE="${IUSE} +${engine}"
133 # @FUNCTION: texlive-module_src_unpack
135 # Only for TeX Live 2009 and later.
136 # After unpacking, the files that need to be relocated are moved accordingly.
138 RELOC_TARGET=texmf-dist
140 texlive-module_src_unpack() {
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
150 for i in $(<"${T}/reloclist"); do
151 mv "${i}" "${RELOC_TARGET}"/$(dirname "${i}") || die "failed to relocate ${i} to ${RELOC_TARGET}/$(dirname ${i})"
155 # @FUNCTION: texlive-module_add_format
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.
162 texlive-module_add_format() {
163 local name engine mode patterns options
165 einfo "Appending to format.${PN}.cnf for $@"
167 if [[ ! -d texmf-dist/fmtutil ]]; then
168 mkdir -p texmf-dist/fmtutil || die
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
176 [[ -z ${patterns} ]] && patterns="-"
177 printf "${name}\t${engine}\t${patterns}\t${options}\n" >> texmf-dist/fmtutil/format.${PN}.cnf || die
180 # @FUNCTION: texlive-module_make_language_def_lines
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.
185 texlive-module_make_language_def_lines() {
186 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
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
200 # @FUNCTION: texlive-module_make_language_dat_lines
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.
205 texlive-module_make_language_dat_lines() {
206 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
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
218 # @FUNCTION: texlive-module_synonyms_to_language_lua_line
220 # Helper function for texlive-module_make_language_lua_lines to generate a
221 # correctly formatted synonyms entry for language.dat.lua.
223 texlive-module_synonyms_to_language_lua_line() {
225 for i in $(echo $@ | tr ',' ' ') ; do
226 printf "${prev} '%s'" ${i}
231 # @FUNCTION: texlive-module_make_language_lua_lines
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.
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"
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
250 if [[ -n ${file_patterns} ]]; then
251 printf "\t\tpatterns = '%s',\n" "${file_patterns}" >> "${dest}" || die
254 if [[ -n ${file_exceptions} ]]; then
255 printf "\t\thyphenation = '%s',\n" "${file_exceptions}" >> "${dest}" || die
258 if [[ -n ${luaspecial} ]]; then
259 printf "\t\tspecial = '%s',\n" "$luaspecial" >> "${dest}" || die
262 printf "\t},\n" >> "${dest}" || die
265 # @FUNCTION: texlive-module_src_compile
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.
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
277 texlive-module_src_compile() {
278 # Generate config files from the tlpobj files provided by TeX Live 2008 and
280 for i in "${S}"/tlpkg/tlpobj/*;
282 grep '^execute ' "${i}" | sed -e 's/^execute //' | tr ' \t' '##' >> "${T}/jobs" || die
285 for i in $(<"${T}/jobs");
287 j="$(echo $i | tr '#' ' ')"
292 echo "Map ${parameter}" >> "${S}/${PN}.cfg";;
294 echo "MixedMap ${parameter}" >> "${S}/${PN}.cfg";;
296 echo "KanjiMap ${parameter}" >> "${S}/${PN}.cfg";;
298 echo "p +${parameter}" >> "${S}/${PN}-config.ps";;
300 echo "f ${parameter}" >> "${S}/${PN}-config";;
302 texlive-module_make_language_def_lines ${parameter}
303 texlive-module_make_language_dat_lines ${parameter}
304 texlive-module_make_language_lua_lines ${parameter}
307 texlive-module_add_format ${parameter};;
309 einfo "Format ${parameter} already built.";;
311 einfo "Language file $parameter already generated.";;
313 die "No rule to proccess ${command}. Please file a bug."
317 # Determine texlive-core version for fmtutil call
318 fmt_call="$(has_version '>=app-text/texlive-core-2019' \
319 && echo "fmtutil-user" || echo "fmtutil")"
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
328 if [[ ! -d texmf-var/web2c ]]; then
329 mkdir texmf-var/web2c || die
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}"
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
342 # @FUNCTION: texlive-module_src_install
345 # Installs texmf and config files to the system.
347 texlive-module_src_install() {
348 for i in texmf-dist/fmtutil/format*.cnf; do
349 [[ -f ${i} ]] && etexlinks "${i}"
354 if [[ -d texmf-doc ]]; then
355 cp -pR texmf-doc "${ED}/usr/share/" || die
358 if [[ -d texmf-dist/doc ]]; then
359 rm -rf texmf-dist/doc || die
362 if [[ -d texmf/doc ]]; then
363 rm -rf texmf/doc || die
367 if [[ -d texmf ]]; then
368 cp -pR texmf "${ED}/usr/share/" || die
371 if [[ -d texmf-dist ]]; then
372 cp -pR texmf-dist "${ED}/usr/share/" || die
375 if [[ -d tlpkg ]] && use source; then
376 cp -pR tlpkg "${ED}/usr/share/" || die
379 insinto /var/lib/texmf
381 [[ -d texmf-var ]] && doins -r texmf-var/.
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"
390 if [[ -f ${S}/language.${PN}.def ]] ; then
391 insinto /etc/texmf/language.def.d
392 doins "${S}/language.${PN}.def"
395 if [[ -f ${S}/language.${PN}.dat ]] ; then
396 insinto /etc/texmf/language.dat.d
397 doins "${S}/language.${PN}.dat"
400 if [[ -f ${S}/language.${PN}.dat.lua ]] ; then
401 insinto /etc/texmf/language.dat.lua.d
402 doins "${S}/language.${PN}.dat.lua"
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#*:}
413 texlive-common_handle_config_files
414 TEXMF_PATH=${TEXMF_DIST_PATH} texlive-common_handle_config_files
417 # @FUNCTION: texlive-module_pkg_postinst
420 # Run texmf-update to ensure the tex installation is consistent with the
421 # installed texmf trees.
423 texlive-module_pkg_postinst() {
425 [[ -n ${TL_MODULE_INFORMATION} ]] && elog "${TL_MODULE_INFORMATION}"
428 # @FUNCTION: texlive-module_pkg_postrm
431 # Run texmf-update to ensure the tex installation is consistent with the
432 # installed texmf trees.
434 texlive-module_pkg_postrm() {
438 EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm