x11-terms/mlterm: Fix typo in metadata.xml
[gentoo.git] / eclass / texlive-module.eclass
1 # Copyright 1999-2014 Gentoo Foundation
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 # @BLURB: Provide generic install functions so that modular texlive's texmf ebuild will only have to inherit this eclass
10 # @DESCRIPTION:
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)
15 #
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
18 # src_unpack does).
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.
21 #
22 # It inherits texlive-common.  Patching is supported via the PATCHES
23 # bash array.
24
25 # @ECLASS-VARIABLE: TEXLIVE_MODULE_CONTENTS
26 # @DESCRIPTION:
27 # The list of packages that will be installed. This variable will be expanded to
28 # SRC_URI:
29 # foo -> texlive-module-foo-${PV}.tar.xz
30
31 # @ECLASS-VARIABLE: TEXLIVE_MODULE_DOC_CONTENTS
32 # @DESCRIPTION:
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.
35
36 # @ECLASS-VARIABLE: TEXLIVE_MODULE_SRC_CONTENTS
37 # @DESCRIPTION:
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.
40
41 # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINSCRIPTS
42 # @DESCRIPTION:
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
45 # /usr/bin.
46
47 # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINLINKS
48 # @DESCRIPTION:
49 # A space separated list of links to add for BINSCRIPTS.
50 # The systax is: foo:bar to create a symlink bar -> foo.
51
52 # @ECLASS-VARIABLE: TL_PV
53 # @DESCRIPTION:
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.
57
58 # @ECLASS-VARIABLE: TL_MODULE_INFORMATION
59 # @DESCRIPTION:
60 # Information to display about the package.
61 # e.g. for enabling/disabling a feature
62
63 # @ECLASS-VARIABLE: PATCHES
64 # @DESCRIPTION:
65 # Array variable specifying any patches to be applied.
66
67 inherit texlive-common eutils
68
69 case "${EAPI:-0}" in
70         0|1|2)
71                 die "EAPI='${EAPI}' is not supported anymore"
72                 ;;
73         *)
74                 ;;
75 esac
76
77 HOMEPAGE="http://www.tug.org/texlive/"
78
79 COMMON_DEPEND=">=app-text/texlive-core-${TL_PV:-${PV}}"
80
81 IUSE="source"
82
83 # Starting from TeX Live 2009, upstream provides .tar.xz modules.
84 PKGEXT=tar.xz
85 DEPEND="${COMMON_DEPEND}
86         app-arch/xz-utils"
87
88 for i in ${TEXLIVE_MODULE_CONTENTS}; do
89         SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
90 done
91
92 # Forge doc SRC_URI
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}"
96 done
97 [ -n "${PN##*documentation*}" ] && [ -n "${TEXLIVE_MODULE_DOC_CONTENTS}" ] && SRC_URI="${SRC_URI} )"
98
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}"
104         done
105         SRC_URI="${SRC_URI} )"
106 fi
107
108 RDEPEND="${COMMON_DEPEND}"
109
110 [ -z "${PN##*documentation*}" ] || IUSE="${IUSE} doc"
111
112 # @ECLASS-VARIABLE: TEXLIVE_MODULE_OPTIONAL_ENGINE
113 # @DESCRIPTION:
114 # A space separated list of Tex engines that can be made optional.
115 # e.g. "luatex luajittex"
116
117 if [ -n "${TEXLIVE_MODULE_OPTIONAL_ENGINE}" ] ; then
118         for engine in ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ; do
119                 IUSE="${IUSE} +${engine}"
120         done
121 fi
122
123 S="${WORKDIR}"
124
125 # @FUNCTION: texlive-module_src_unpack
126 # @DESCRIPTION:
127 # Only for TeX Live 2009 and later.
128 # After unpacking, the files that need to be relocated are moved accordingly.
129
130 RELOC_TARGET=texmf-dist
131
132 texlive-module_src_unpack() {
133         unpack ${A}
134
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}"
139         done
140         for i in $(<"${T}/reloclist"); do
141                 mv "${i}" "${RELOC_TARGET}"/$(dirname "${i}") || die "failed to relocate ${i} to ${RELOC_TARGET}/$(dirname ${i})"
142         done
143 }
144
145 # @FUNCTION: texlive-module_src_prepare
146 # @DESCRIPTION:
147 # Apply patches from the PATCHES array and user patches, if any.
148
149 texlive-module_src_prepare() {
150         [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
151         epatch_user
152 }
153
154 # @FUNCTION: texlive-module_add_format
155 # @DESCRIPTION:
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.
160
161 texlive-module_add_format() {
162         local name engine mode patterns options
163         eval $@
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
170         fi
171         [ -z "${patterns}" ] && patterns="-"
172         printf "${name}\t${engine}\t${patterns}\t${options}\n" >> texmf-dist/fmtutil/format.${PN}.cnf
173 }
174
175 # @FUNCTION: texlive-module_make_language_def_lines
176 # @DESCRIPTION:
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.
179
180 texlive-module_make_language_def_lines() {
181         local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
182         eval $@
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"
191                 done
192         fi
193 }
194
195 # @FUNCTION: texlive-module_make_language_dat_lines
196 # @DESCRIPTION:
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.
199
200 texlive-module_make_language_dat_lines() {
201         local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
202         eval $@
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"
209                 done
210         fi
211 }
212
213 # @FUNCTION: texlive-module_synonyms_to_language_lua_line
214 # @DESCRIPTION:
215 # Helper function for texlive-module_make_language_lua_lines to generate a
216 # correctly formatted synonyms entry for language.dat.lua.
217
218 texlive-module_synonyms_to_language_lua_line() {
219         local prev=""
220         for i in $(echo $@ | tr ',' ' ') ; do
221                 printf "${prev} '%s'" $i
222                 prev=","
223         done
224 }
225
226 # @FUNCTION: texlive-module_make_language_lua_lines
227 # @DESCRIPTION:
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.
232
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"
236         eval $@
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"
248 }
249
250 # @FUNCTION: texlive-module_src_compile
251 # @DESCRIPTION:
252 # exported function:
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.
256 #
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
260 # sandbox.
261
262 texlive-module_src_compile() {
263         # Generate config files from the tlpobj files provided by TeX Live 2008 and
264         # later
265         for i in "${S}"/tlpkg/tlpobj/*;
266         do
267                 grep '^execute ' "${i}" | sed -e 's/^execute //' | tr ' \t' '##' >> "${T}/jobs"
268         done
269
270         for i in $(<"${T}/jobs");
271         do
272                 j="$(echo $i | tr '#' ' ')"
273                 command=${j%% *}
274                 parameter=${j#* }
275                 case "${command}" in
276                         addMap)
277                                 echo "Map ${parameter}" >> "${S}/${PN}.cfg";;
278                         addMixedMap)
279                                 echo "MixedMap ${parameter}" >> "${S}/${PN}.cfg";;
280                         addKanjiMap)
281                                 echo "KanjiMap ${parameter}" >> "${S}/${PN}.cfg";;
282                         addDvipsMap)
283                                 echo "p +${parameter}" >> "${S}/${PN}-config.ps";;
284                         addDvipdfmMap)
285                                 echo "f ${parameter}" >> "${S}/${PN}-config";;
286                         AddHyphen)
287                                 texlive-module_make_language_def_lines "$parameter"
288                                 texlive-module_make_language_dat_lines "$parameter"
289                                 texlive-module_make_language_lua_lines "$parameter"
290                                 ;;
291                         AddFormat)
292                                 texlive-module_add_format "$parameter";;
293                         BuildFormat)
294                                 einfo "Format $parameter already built.";;
295                         BuildLanguageDat)
296                                 einfo "Language file $parameter already generated.";;
297                         *)
298                                 die "No rule to proccess ${command}. Please file a bug."
299                 esac
300         done
301
302         # Build format files
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}"
311                 fi
312         done
313
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
317 }
318
319 # @FUNCTION: texlive-module_src_install
320 # @DESCRIPTION:
321 # exported function:
322 # Installs texmf and config files to the system.
323
324 texlive-module_src_install() {
325         for i in texmf-dist/fmtutil/format*.cnf; do
326                 [ -f "${i}" ] && etexlinks "${i}"
327         done
328
329         dodir /usr/share
330         if [ -z "${PN##*documentation*}" ] || use doc; then
331                 [ -d texmf-doc ] && cp -pR texmf-doc "${ED}/usr/share/"
332         else
333                 [ -d texmf/doc ] && rm -rf texmf/doc
334                 [ -d texmf-dist/doc ] && rm -rf texmf-dist/doc
335         fi
336
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/"
340
341         insinto /var/lib/texmf
342         [ -d texmf-var ] && doins -r texmf-var/*
343
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"
350
351         if [ -f "${S}/language.${PN}.def" ] ; then
352                 insinto /etc/texmf/language.def.d
353                 doins "${S}/language.${PN}.def"
354         fi
355
356         if [ -f "${S}/language.${PN}.dat" ] ; then
357                 insinto /etc/texmf/language.dat.d
358                 doins "${S}/language.${PN}.dat"
359         fi
360
361         if [ -f "${S}/language.${PN}.dat.lua" ] ; then
362                 insinto /etc/texmf/language.dat.lua.d
363                 doins "${S}/language.${PN}.dat.lua"
364         fi
365
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#*:}
371                 done
372         fi
373
374         texlive-common_handle_config_files
375         TEXMF_PATH=${TEXMF_DIST_PATH} texlive-common_handle_config_files
376 }
377
378 # @FUNCTION: texlive-module_pkg_postinst
379 # @DESCRIPTION:
380 # exported function:
381 # Run texmf-update to ensure the tex installation is consistent with the
382 # installed texmf trees.
383
384 texlive-module_pkg_postinst() {
385         etexmf-update
386         [ -n "${TL_MODULE_INFORMATION}" ] && elog "${TL_MODULE_INFORMATION}"
387 }
388
389 # @FUNCTION: texlive-module_pkg_postrm
390 # @DESCRIPTION:
391 # exported function:
392 # Run texmf-update to ensure the tex installation is consistent with the
393 # installed texmf trees.
394
395 texlive-module_pkg_postrm() {
396         etexmf-update
397 }
398
399 EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install \
400         pkg_postinst pkg_postrm