1 # Copyright 1999-2014 Gentoo Foundation
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>
9 # @BLURB: Provide generic install functions so that modular texlive's texmf ebuild will only have to inherit this eclass
11 # Purpose: Provide generic install functions so that modular texlive's texmf ebuilds will
12 # only have to inherit this eclass.
13 # Ebuilds have to provide TEXLIVE_MODULE_CONTENTS variable that contains the list
14 # of packages that it will install. (See below)
16 # For TeX Live versions prior to 2009, the ebuild was supposed to unpack the
17 # texmf and texmf-dist directories to ${WORKDIR} (which is what the default
19 # Starting from TeX Live 2009, the eclass provides a src_unpack function taking
20 # care of unpacking and relocating the files that need it.
22 # It inherits texlive-common. Patching is supported via the PATCHES
25 # @ECLASS-VARIABLE: TEXLIVE_MODULE_CONTENTS
27 # The list of packages that will be installed. This variable will be expanded to
29 # foo -> texlive-module-foo-${PV}.tar.xz
31 # @ECLASS-VARIABLE: TEXLIVE_MODULE_DOC_CONTENTS
33 # The list of packages that will be installed if the doc useflag is enabled.
34 # Expansion to SRC_URI is the same as for TEXLIVE_MODULE_CONTENTS.
36 # @ECLASS-VARIABLE: TEXLIVE_MODULE_SRC_CONTENTS
38 # The list of packages that will be installed if the source useflag is enabled.
39 # Expansion to SRC_URI is the same as for TEXLIVE_MODULE_CONTENTS.
41 # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINSCRIPTS
43 # A space separated list of files that are in fact scripts installed in the
44 # texmf tree and that we want to be available directly. They will be installed in
47 # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINLINKS
49 # A space separated list of links to add for BINSCRIPTS.
50 # The systax is: foo:bar to create a symlink bar -> foo.
52 # @ECLASS-VARIABLE: TL_PV
54 # Normally the module's PV reflects the TeXLive release it belongs to.
55 # If this is not the case, TL_PV takes the version number for the
56 # needed app-text/texlive-core.
58 # @ECLASS-VARIABLE: TL_MODULE_INFORMATION
60 # Information to display about the package.
61 # e.g. for enabling/disabling a feature
63 # @ECLASS-VARIABLE: PATCHES
65 # Array variable specifying any patches to be applied.
67 inherit texlive-common eutils
71 die "EAPI='${EAPI}' is not supported anymore"
77 HOMEPAGE="http://www.tug.org/texlive/"
79 COMMON_DEPEND=">=app-text/texlive-core-${TL_PV:-${PV}}"
83 # Starting from TeX Live 2009, upstream provides .tar.xz modules.
85 DEPEND="${COMMON_DEPEND}
88 for i in ${TEXLIVE_MODULE_CONTENTS}; do
89 SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
93 [ -n "${PN##*documentation*}" ] && [ -n "${TEXLIVE_MODULE_DOC_CONTENTS}" ] && SRC_URI="${SRC_URI} doc? ("
94 for i in ${TEXLIVE_MODULE_DOC_CONTENTS}; do
95 SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
97 [ -n "${PN##*documentation*}" ] && [ -n "${TEXLIVE_MODULE_DOC_CONTENTS}" ] && SRC_URI="${SRC_URI} )"
99 # Forge source SRC_URI
100 if [ -n "${TEXLIVE_MODULE_SRC_CONTENTS}" ] ; then
101 SRC_URI="${SRC_URI} source? ("
102 for i in ${TEXLIVE_MODULE_SRC_CONTENTS}; do
103 SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
105 SRC_URI="${SRC_URI} )"
108 RDEPEND="${COMMON_DEPEND}"
110 [ -z "${PN##*documentation*}" ] || IUSE="${IUSE} doc"
112 # @ECLASS-VARIABLE: TEXLIVE_MODULE_OPTIONAL_ENGINE
114 # A space separated list of Tex engines that can be made optional.
115 # e.g. "luatex luajittex"
117 if [ -n "${TEXLIVE_MODULE_OPTIONAL_ENGINE}" ] ; then
118 for engine in ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ; do
119 IUSE="${IUSE} +${engine}"
125 # @FUNCTION: texlive-module_src_unpack
127 # Only for TeX Live 2009 and later.
128 # After unpacking, the files that need to be relocated are moved accordingly.
130 RELOC_TARGET=texmf-dist
132 texlive-module_src_unpack() {
135 grep RELOC tlpkg/tlpobj/* | awk '{print $2}' | sed 's#^RELOC/##' > "${T}/reloclist"
136 { for i in $(<"${T}/reloclist"); do dirname $i; done; } | uniq > "${T}/dirlist"
137 for i in $(<"${T}/dirlist"); do
138 [ -d "${RELOC_TARGET}/${i}" ] || mkdir -p "${RELOC_TARGET}/${i}"
140 for i in $(<"${T}/reloclist"); do
141 mv "${i}" "${RELOC_TARGET}"/$(dirname "${i}") || die "failed to relocate ${i} to ${RELOC_TARGET}/$(dirname ${i})"
145 # @FUNCTION: texlive-module_src_prepare
147 # Apply patches from the PATCHES array and user patches, if any.
149 texlive-module_src_prepare() {
150 [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
154 # @FUNCTION: texlive-module_add_format
156 # Creates/appends to a format.${PN}.cnf file for fmtutil.
157 # It parses the AddFormat directive of tlpobj files to create it.
158 # This will make fmtutil generate the formats when asked and allow the remaining
159 # src_compile phase to build the formats.
161 texlive-module_add_format() {
162 local name engine mode patterns options
164 einfo "Appending to format.${PN}.cnf for $@"
165 [ -d texmf-dist/fmtutil ] || mkdir -p texmf-dist/fmtutil
166 [ -f texmf-dist/fmtutil/format.${PN}.cnf ] || { echo "# Generated for ${PN} by texlive-module.eclass" > texmf-dist/fmtutil/format.${PN}.cnf; }
167 [ -n "${TEXLIVE_MODULE_OPTIONAL_ENGINE}" ] && has ${engine} ${TEXLIVE_MODULE_OPTIONAL_ENGINE} && use !${engine} && mode="disabled"
168 if [ "${mode}" = "disabled" ]; then
169 printf "#! " >> texmf-dist/fmtutil/format.${PN}.cnf
171 [ -z "${patterns}" ] && patterns="-"
172 printf "${name}\t${engine}\t${patterns}\t${options}\n" >> texmf-dist/fmtutil/format.${PN}.cnf
175 # @FUNCTION: texlive-module_make_language_def_lines
177 # Creates a language.${PN}.def entry to put in /etc/texmf/language.def.d.
178 # It parses the AddHyphen directive of tlpobj files to create it.
180 texlive-module_make_language_def_lines() {
181 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
183 einfo "Generating language.def entry for $@"
184 [ -z "$lefthyphenmin" ] && lefthyphenmin="2"
185 [ -z "$righthyphenmin" ] && righthyphenmin="3"
186 echo "\\addlanguage{$name}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def"
187 if [ -n "$synonyms" ] ; then
188 for i in $(echo $synonyms | tr ',' ' ') ; do
189 einfo "Generating language.def synonym $i for $@"
190 echo "\\addlanguage{$i}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def"
195 # @FUNCTION: texlive-module_make_language_dat_lines
197 # Creates a language.${PN}.dat entry to put in /etc/texmf/language.dat.d.
198 # It parses the AddHyphen directive of tlpobj files to create it.
200 texlive-module_make_language_dat_lines() {
201 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
203 einfo "Generating language.dat entry for $@"
204 echo "$name $file" >> "${S}/language.${PN}.dat"
205 if [ -n "$synonyms" ] ; then
206 for i in $(echo $synonyms | tr ',' ' ') ; do
207 einfo "Generating language.dat synonym $i for $@"
208 echo "=$i" >> "${S}/language.${PN}.dat"
213 # @FUNCTION: texlive-module_synonyms_to_language_lua_line
215 # Helper function for texlive-module_make_language_lua_lines to generate a
216 # correctly formatted synonyms entry for language.dat.lua.
218 texlive-module_synonyms_to_language_lua_line() {
220 for i in $(echo $@ | tr ',' ' ') ; do
221 printf "${prev} '%s'" $i
226 # @FUNCTION: texlive-module_make_language_lua_lines
228 # Only valid for TeXLive 2010 and later.
229 # Creates a language.${PN}.dat.lua entry to put in
230 # /etc/texmf/language.dat.lua.d.
231 # It parses the AddHyphen directive of tlpobj files to create it.
233 texlive-module_make_language_lua_lines() {
234 local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
235 local dest="${S}/language.${PN}.dat.lua"
237 [ -z "$lefthyphenmin" ] && lefthyphenmin="2"
238 [ -z "$righthyphenmin" ] && righthyphenmin="3"
239 einfo "Generating language.dat.lua entry for $@"
240 printf "\t['%s'] = {\n" "$name" >> "$dest"
241 printf "\t\tloader = '%s',\n" "$file" >> "$dest"
242 printf "\t\tlefthyphenmin = %s,\n\t\trighthyphenmin = %s,\n" "$lefthyphenmin" "$righthyphenmin" >> "$dest"
243 printf "\t\tsynonyms = {%s },\n" "$(texlive-module_synonyms_to_language_lua_line "$synonyms")" >> "$dest"
244 [ -n "$file_patterns" ] && printf "\t\tpatterns = '%s',\n" "$file_patterns" >> "$dest"
245 [ -n "$file_exceptions" ] && printf "\t\thyphenation = '%s',\n" "$file_exceptions" >> "$dest"
246 [ -n "$luaspecial" ] && printf "\t\tspecial = '%s',\n" "$luaspecial" >> "$dest"
247 printf "\t},\n" >> "$dest"
250 # @FUNCTION: texlive-module_src_compile
253 # Generates the config files that are to be installed in /etc/texmf;
254 # texmf-update script will take care of merging the different config files for
255 # different packages in a single one used by the whole tex installation.
257 # Once the config files are generated, we build the format files using fmtutil
258 # (provided by texlive-core). The compiled format files will be sent to
259 # texmf-var/web2c, like fmtutil defaults to but with some trick to stay in the
262 texlive-module_src_compile() {
263 # Generate config files from the tlpobj files provided by TeX Live 2008 and
265 for i in "${S}"/tlpkg/tlpobj/*;
267 grep '^execute ' "${i}" | sed -e 's/^execute //' | tr ' \t' '##' >> "${T}/jobs"
270 for i in $(<"${T}/jobs");
272 j="$(echo $i | tr '#' ' ')"
277 echo "Map ${parameter}" >> "${S}/${PN}.cfg";;
279 echo "MixedMap ${parameter}" >> "${S}/${PN}.cfg";;
281 echo "KanjiMap ${parameter}" >> "${S}/${PN}.cfg";;
283 echo "p +${parameter}" >> "${S}/${PN}-config.ps";;
285 echo "f ${parameter}" >> "${S}/${PN}-config";;
287 texlive-module_make_language_def_lines "$parameter"
288 texlive-module_make_language_dat_lines "$parameter"
289 texlive-module_make_language_lua_lines "$parameter"
292 texlive-module_add_format "$parameter";;
294 einfo "Format $parameter already built.";;
296 einfo "Language file $parameter already generated.";;
298 die "No rule to proccess ${command}. Please file a bug."
303 for i in texmf-dist/fmtutil/format*.cnf; do
304 if [ -f "${i}" ]; then
305 einfo "Building format ${i}"
306 [ -d texmf-var ] || mkdir texmf-var
307 [ -d texmf-var/web2c ] || mkdir texmf-var/web2c
308 VARTEXFONTS="${T}/fonts" TEXMFHOME="${S}/texmf:${S}/texmf-dist:${S}/texmf-var"\
309 env -u TEXINPUTS fmtutil --cnffile "${i}" --fmtdir "${S}/texmf-var/web2c" --all\
310 || die "failed to build format ${i}"
314 # Delete ls-R files, these should not be created but better be certain they
315 # do not end up being installed.
316 find . -name 'ls-R' -delete
319 # @FUNCTION: texlive-module_src_install
322 # Installs texmf and config files to the system.
324 texlive-module_src_install() {
325 for i in texmf-dist/fmtutil/format*.cnf; do
326 [ -f "${i}" ] && etexlinks "${i}"
330 if [ -z "${PN##*documentation*}" ] || use doc; then
331 [ -d texmf-doc ] && cp -pR texmf-doc "${ED}/usr/share/"
333 [ -d texmf/doc ] && rm -rf texmf/doc
334 [ -d texmf-dist/doc ] && rm -rf texmf-dist/doc
337 [ -d texmf ] && cp -pR texmf "${ED}/usr/share/"
338 [ -d texmf-dist ] && cp -pR texmf-dist "${ED}/usr/share/"
339 [ -d tlpkg ] && use source && cp -pR tlpkg "${ED}/usr/share/"
341 insinto /var/lib/texmf
342 [ -d texmf-var ] && doins -r texmf-var/*
344 insinto /etc/texmf/updmap.d
345 [ -f "${S}/${PN}.cfg" ] && doins "${S}/${PN}.cfg"
346 insinto /etc/texmf/dvips.d
347 [ -f "${S}/${PN}-config.ps" ] && doins "${S}/${PN}-config.ps"
348 insinto /etc/texmf/dvipdfm/config
349 [ -f "${S}/${PN}-config" ] && doins "${S}/${PN}-config"
351 if [ -f "${S}/language.${PN}.def" ] ; then
352 insinto /etc/texmf/language.def.d
353 doins "${S}/language.${PN}.def"
356 if [ -f "${S}/language.${PN}.dat" ] ; then
357 insinto /etc/texmf/language.dat.d
358 doins "${S}/language.${PN}.dat"
361 if [ -f "${S}/language.${PN}.dat.lua" ] ; then
362 insinto /etc/texmf/language.dat.lua.d
363 doins "${S}/language.${PN}.dat.lua"
366 [ -n "${TEXLIVE_MODULE_BINSCRIPTS}" ] && dobin_texmf_scripts ${TEXLIVE_MODULE_BINSCRIPTS}
367 if [ -n "${TEXLIVE_MODULE_BINLINKS}" ] ; then
368 for i in ${TEXLIVE_MODULE_BINLINKS} ; do
369 [ -f "${ED}/usr/bin/${i%:*}" ] || die "Trying to install an invalid BINLINK. This should not happen. Please file a bug."
370 dosym ${i%:*} /usr/bin/${i#*:}
374 texlive-common_handle_config_files
375 TEXMF_PATH=${TEXMF_DIST_PATH} texlive-common_handle_config_files
378 # @FUNCTION: texlive-module_pkg_postinst
381 # Run texmf-update to ensure the tex installation is consistent with the
382 # installed texmf trees.
384 texlive-module_pkg_postinst() {
386 [ -n "${TL_MODULE_INFORMATION}" ] && elog "${TL_MODULE_INFORMATION}"
389 # @FUNCTION: texlive-module_pkg_postrm
392 # Run texmf-update to ensure the tex installation is consistent with the
393 # installed texmf trees.
395 texlive-module_pkg_postrm() {
399 EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install \
400 pkg_postinst pkg_postrm