1 # Copyright 1999-2019 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
73 die "EAPI='${EAPI}' is not supported anymore"
76 inherit texlive-common
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"
144 { for i in $(<"${T}/reloclist"); do dirname $i; done; } | uniq > "${T}/dirlist"
145 for i in $(<"${T}/dirlist"); do
146 [ -d "${RELOC_TARGET}/${i}" ] || mkdir -p "${RELOC_TARGET}/${i}"
148 for i in $(<"${T}/reloclist"); do
149 mv "${i}" "${RELOC_TARGET}"/$(dirname "${i}") || die "failed to relocate ${i} to ${RELOC_TARGET}/$(dirname ${i})"
153 # @FUNCTION: texlive-module_add_format
155 # Creates/appends to a format.${PN}.cnf file for fmtutil.
156 # It parses the AddFormat directive of tlpobj files to create it.
157 # This will make fmtutil generate the formats when asked and allow the remaining
158 # src_compile phase to build the formats.
160 texlive-module_add_format() {
161 local name engine mode patterns options
163 einfo "Appending to format.${PN}.cnf for $@"
164 [ -d texmf-dist/fmtutil ] || mkdir -p texmf-dist/fmtutil
165 [ -f texmf-dist/fmtutil/format.${PN}.cnf ] || { echo "# Generated for ${PN} by texlive-module.eclass" > texmf-dist/fmtutil/format.${PN}.cnf; }
166 [ -n "${TEXLIVE_MODULE_OPTIONAL_ENGINE}" ] && has ${engine} ${TEXLIVE_MODULE_OPTIONAL_ENGINE} && use !${engine} && mode="disabled"
167 if [ "${mode}" = "disabled" ]; then
168 printf "#! " >> texmf-dist/fmtutil/format.${PN}.cnf
170 [ -z "${patterns}" ] && patterns="-"
171 printf "${name}\t${engine}\t${patterns}\t${options}\n" >> texmf-dist/fmtutil/format.${PN}.cnf
174 # @FUNCTION: texlive-module_make_language_def_lines
176 # Creates a language.${PN}.def entry to put in /etc/texmf/language.def.d.
177 # It parses the AddHyphen directive of tlpobj files to create it.
179 texlive-module_make_language_def_lines() {
180 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
182 einfo "Generating language.def entry for $@"
183 [ -z "$lefthyphenmin" ] && lefthyphenmin="2"
184 [ -z "$righthyphenmin" ] && righthyphenmin="3"
185 echo "\\addlanguage{$name}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def"
186 if [ -n "$synonyms" ] ; then
187 for i in $(echo $synonyms | tr ',' ' ') ; do
188 einfo "Generating language.def synonym $i for $@"
189 echo "\\addlanguage{$i}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def"
194 # @FUNCTION: texlive-module_make_language_dat_lines
196 # Creates a language.${PN}.dat entry to put in /etc/texmf/language.dat.d.
197 # It parses the AddHyphen directive of tlpobj files to create it.
199 texlive-module_make_language_dat_lines() {
200 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
202 einfo "Generating language.dat entry for $@"
203 echo "$name $file" >> "${S}/language.${PN}.dat"
204 if [ -n "$synonyms" ] ; then
205 for i in $(echo $synonyms | tr ',' ' ') ; do
206 einfo "Generating language.dat synonym $i for $@"
207 echo "=$i" >> "${S}/language.${PN}.dat"
212 # @FUNCTION: texlive-module_synonyms_to_language_lua_line
214 # Helper function for texlive-module_make_language_lua_lines to generate a
215 # correctly formatted synonyms entry for language.dat.lua.
217 texlive-module_synonyms_to_language_lua_line() {
219 for i in $(echo $@ | tr ',' ' ') ; do
220 printf "${prev} '%s'" $i
225 # @FUNCTION: texlive-module_make_language_lua_lines
227 # Only valid for TeXLive 2010 and later.
228 # Creates a language.${PN}.dat.lua entry to put in
229 # /etc/texmf/language.dat.lua.d.
230 # It parses the AddHyphen directive of tlpobj files to create it.
232 texlive-module_make_language_lua_lines() {
233 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
234 local dest="${S}/language.${PN}.dat.lua"
236 [ -z "$lefthyphenmin" ] && lefthyphenmin="2"
237 [ -z "$righthyphenmin" ] && righthyphenmin="3"
238 einfo "Generating language.dat.lua entry for $@"
239 printf "\t['%s'] = {\n" "$name" >> "$dest"
240 printf "\t\tloader = '%s',\n" "$file" >> "$dest"
241 printf "\t\tlefthyphenmin = %s,\n\t\trighthyphenmin = %s,\n" "$lefthyphenmin" "$righthyphenmin" >> "$dest"
242 printf "\t\tsynonyms = {%s },\n" "$(texlive-module_synonyms_to_language_lua_line "$synonyms")" >> "$dest"
243 [ -n "$file_patterns" ] && printf "\t\tpatterns = '%s',\n" "$file_patterns" >> "$dest"
244 [ -n "$file_exceptions" ] && printf "\t\thyphenation = '%s',\n" "$file_exceptions" >> "$dest"
245 [ -n "$luaspecial" ] && printf "\t\tspecial = '%s',\n" "$luaspecial" >> "$dest"
246 printf "\t},\n" >> "$dest"
249 # @FUNCTION: texlive-module_src_compile
252 # Generates the config files that are to be installed in /etc/texmf;
253 # texmf-update script will take care of merging the different config files for
254 # different packages in a single one used by the whole tex installation.
256 # Once the config files are generated, we build the format files using fmtutil
257 # (provided by texlive-core). The compiled format files will be sent to
258 # texmf-var/web2c, like fmtutil defaults to but with some trick to stay in the
261 texlive-module_src_compile() {
262 # Generate config files from the tlpobj files provided by TeX Live 2008 and
264 for i in "${S}"/tlpkg/tlpobj/*;
266 grep '^execute ' "${i}" | sed -e 's/^execute //' | tr ' \t' '##' >> "${T}/jobs"
269 for i in $(<"${T}/jobs");
271 j="$(echo $i | tr '#' ' ')"
276 echo "Map ${parameter}" >> "${S}/${PN}.cfg";;
278 echo "MixedMap ${parameter}" >> "${S}/${PN}.cfg";;
280 echo "KanjiMap ${parameter}" >> "${S}/${PN}.cfg";;
282 echo "p +${parameter}" >> "${S}/${PN}-config.ps";;
284 echo "f ${parameter}" >> "${S}/${PN}-config";;
286 texlive-module_make_language_def_lines "$parameter"
287 texlive-module_make_language_dat_lines "$parameter"
288 texlive-module_make_language_lua_lines "$parameter"
291 texlive-module_add_format "$parameter";;
293 einfo "Format $parameter already built.";;
295 einfo "Language file $parameter already generated.";;
297 die "No rule to proccess ${command}. Please file a bug."
301 # Determine texlive-core version for fmtutil call
302 fmt_call="$(has_version '>=app-text/texlive-core-2019' \
303 && echo "fmtutil-user" || echo "fmtutil")"
306 for i in texmf-dist/fmtutil/format*.cnf; do
307 if [ -f "${i}" ]; then
308 einfo "Building format ${i}"
309 [ -d texmf-var ] || mkdir texmf-var
310 [ -d texmf-var/web2c ] || mkdir texmf-var/web2c
311 VARTEXFONTS="${T}/fonts" TEXMFHOME="${S}/texmf:${S}/texmf-dist:${S}/texmf-var"\
312 env -u TEXINPUTS $fmt_call --cnffile "${i}" --fmtdir "${S}/texmf-var/web2c" --all\
313 || die "failed to build format ${i}"
317 # Delete ls-R files, these should not be created but better be certain they
318 # do not end up being installed.
319 find . -name 'ls-R' -delete || die
322 # @FUNCTION: texlive-module_src_install
325 # Installs texmf and config files to the system.
327 texlive-module_src_install() {
328 for i in texmf-dist/fmtutil/format*.cnf; do
329 [ -f "${i}" ] && etexlinks "${i}"
334 [ -d texmf-doc ] && cp -pR texmf-doc "${ED}/usr/share/"
336 [ -d texmf/doc ] && rm -rf texmf/doc
337 [ -d texmf-dist/doc ] && rm -rf texmf-dist/doc
340 [ -d texmf ] && cp -pR texmf "${ED}/usr/share/"
341 [ -d texmf-dist ] && cp -pR texmf-dist "${ED}/usr/share/"
342 [ -d tlpkg ] && use source && cp -pR tlpkg "${ED}/usr/share/"
344 insinto /var/lib/texmf
345 [ -d texmf-var ] && doins -r texmf-var/*
347 insinto /etc/texmf/updmap.d
348 [ -f "${S}/${PN}.cfg" ] && doins "${S}/${PN}.cfg"
349 insinto /etc/texmf/dvips.d
350 [ -f "${S}/${PN}-config.ps" ] && doins "${S}/${PN}-config.ps"
351 insinto /etc/texmf/dvipdfm/config
352 [ -f "${S}/${PN}-config" ] && doins "${S}/${PN}-config"
354 if [ -f "${S}/language.${PN}.def" ] ; then
355 insinto /etc/texmf/language.def.d
356 doins "${S}/language.${PN}.def"
359 if [ -f "${S}/language.${PN}.dat" ] ; then
360 insinto /etc/texmf/language.dat.d
361 doins "${S}/language.${PN}.dat"
364 if [ -f "${S}/language.${PN}.dat.lua" ] ; then
365 insinto /etc/texmf/language.dat.lua.d
366 doins "${S}/language.${PN}.dat.lua"
369 [ -n "${TEXLIVE_MODULE_BINSCRIPTS}" ] && dobin_texmf_scripts ${TEXLIVE_MODULE_BINSCRIPTS}
370 if [ -n "${TEXLIVE_MODULE_BINLINKS}" ] ; then
371 for i in ${TEXLIVE_MODULE_BINLINKS} ; do
372 [ -f "${ED}/usr/bin/${i%:*}" ] || die "Trying to install an invalid BINLINK. This should not happen. Please file a bug."
373 dosym ${i%:*} /usr/bin/${i#*:}
377 texlive-common_handle_config_files
378 TEXMF_PATH=${TEXMF_DIST_PATH} texlive-common_handle_config_files
381 # @FUNCTION: texlive-module_pkg_postinst
384 # Run texmf-update to ensure the tex installation is consistent with the
385 # installed texmf trees.
387 texlive-module_pkg_postinst() {
389 [ -n "${TL_MODULE_INFORMATION}" ] && elog "${TL_MODULE_INFORMATION}"
392 # @FUNCTION: texlive-module_pkg_postrm
395 # Run texmf-update to ensure the tex installation is consistent with the
396 # installed texmf trees.
398 texlive-module_pkg_postrm() {
402 EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm