sys-process/glances: revbump 3.1.4.1, add missing doc dep
[gentoo.git] / eclass / texlive-common.eclass
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: texlive-common.eclass
5 # @MAINTAINER:
6 # tex@gentoo.org
7 # @AUTHOR:
8 # Original Author: Alexis Ballier <aballier@gentoo.org>
9 # @SUPPORTED_EAPIS: 7
10 # @BLURB: Provide various functions used by both texlive-core and texlive modules
11 # @DESCRIPTION:
12 # Purpose: Provide various functions used by both texlive-core and texlive
13 # modules.
14 #
15 # Note that this eclass *must* not assume the presence of any standard tex too
16
17 if [[ -z ${_TEXLIVE_COMMON_ECLASS} ]]; then
18 _TEXLIVE_COMMON_ECLASS=1
19
20 case ${EAPI:-0} in
21         [0-6]) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
22         7)     ;;
23         *)     die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
24 esac
25
26 TEXMF_PATH=/usr/share/texmf
27 TEXMF_DIST_PATH=/usr/share/texmf-dist
28 TEXMF_VAR_PATH=/var/lib/texmf
29
30 # @FUNCTION: texlive-common_handle_config_files
31 # @DESCRIPTION:
32 # Has to be called in src_install after having installed the files in ${D}
33 # This function will move the relevant files to /etc/texmf and symling them
34 # from their original location. This is to allow easy update of texlive's
35 # configuration
36
37 texlive-common_handle_config_files() {
38         # Handle config files properly
39         [[ -d ${ED}${TEXMF_PATH} ]] || return
40         cd "${ED}${TEXMF_PATH}" || die
41
42         while read -r -d '' i; do
43                 if [[ ${f#*config} != ${f} || ${f#doc} != ${f} || ${f#source} != ${f} || ${f#tex} != ${f} ]] ; then
44                         continue
45                 fi
46                 dodir /etc/texmf/$(dirname ${f}).d
47                 einfo "Moving (and symlinking) ${EPREFIX}${TEXMF_PATH}/${f} to ${EPREFIX}/etc/texmf/$(dirname ${f}).d"
48                 mv "${ED}/${TEXMF_PATH}/${f}" "${ED}/etc/texmf/$(dirname ${f}).d" || die "mv ${f} failed."
49                 dosym /etc/texmf/$(dirname ${f}).d/$(basename ${f}) ${TEXMF_PATH}/${f}
50         done < <(find  -name '*.cnf' -type f -o -name '*.cfg' -type f | sed -e "s:\./::g")
51 }
52
53 # @FUNCTION: texlive-common_is_file_present_in_texmf
54 # @DESCRIPTION:
55 # Return if a file is present in the texmf tree
56 # Call it from the directory containing texmf and texmf-dist
57
58 texlive-common_is_file_present_in_texmf() {
59         local mark="${T}/${1}.found"
60         if [[ -d texmf ]]; then
61                 find texmf -name ${1} -exec touch ${mark} {} + || die
62         fi
63
64         if [[ -d texmf-dist ]]; then
65                 find texmf-dist -name ${1} -exec touch ${mark} {} + || die
66         fi
67 }
68
69 # @FUNCTION: texlive-common_do_symlinks
70 # @USAGE: <src> <dest>
71 # @DESCRIPTION:
72 # Mimic the install_link function of texlinks
73 #
74 # Should have the same behavior as the one in /usr/bin/texlinks
75 # except that it is under the control of the package manager
76 # Note that $1 corresponds to $src and $2 to $dest in this function
77 # ( Arguments are switched because texlinks main function sends them switched )
78 # This function should not be called from an ebuild, prefer etexlinks that will
79 # also do the fmtutil file parsing.
80
81 texlive-common_do_symlinks() {
82         while [[ ${#} != 0 ]]; do
83                 case ${1} in
84                         cont-??|metafun|mptopdf)
85                                 einfo "Symlink ${1} skipped (special case)"
86                                 ;;
87                         mf)
88                                 einfo "Symlink ${1} -> ${2} skipped (texlive-core takes care of it)"
89                                 ;;
90                         *)
91                                 if [[ ${1} == ${2} ]]; then
92                                         einfo "Symlink ${1} -> ${2} skipped"
93                                 elif [[ -e ${ED}/usr/bin/${1} || -L ${ED}/usr/bin/${1} ]]; then
94                                         einfo "Symlink ${1} skipped (file exists)"
95                                 else
96                                         einfo "Making symlink from ${1} to ${2}"
97                                         dosym ${2} /usr/bin/${1}
98                                 fi
99                                 ;;
100                 esac
101                 shift; shift;
102         done
103 }
104
105 # @FUNCTION: etexlinks
106 # @USAGE: <file>
107 # @DESCRIPTION:
108 # Mimic texlinks on a fmtutil format file
109 #
110 # $1 has to be a fmtutil format file like fmtutil.cnf
111 # etexlinks foo will install the symlinks that texlinks --cnffile foo would have
112 # created. We cannot use texlinks with portage as it is not DESTDIR aware.
113 # (It would not fail but will not create the symlinks if the target is not in
114 # the same dir as the source)
115 # Also, as this eclass must not depend on a tex distribution to be installed we
116 # cannot use texlinks from here.
117
118 etexlinks() {
119         # Install symlinks from formats to engines
120         texlive-common_do_symlinks $(sed '/^[      ]*#/d; /^[      ]*$/d' "$1" | awk '{print $1, $2}')
121 }
122
123 # @FUNCTION: dobin_texmf_scripts
124 # @USAGE: <file1> [file2] ...
125 # @DESCRIPTION:
126 # Symlinks a script from the texmf tree to /usr/bin. Requires permissions to be
127 # correctly set for the file that it will point to.
128
129 dobin_texmf_scripts() {
130         while [[ ${#} -gt 0 ]] ; do
131                 local trg=$(basename ${1} | sed 's,\.[^/]*$,,' | tr '[:upper:]' '[:lower:]')
132                 einfo "Installing ${1} as ${trg} bin wrapper"
133                 [[ -x ${ED}/usr/share/${1} ]] || die "Trying to install a non existing or non executable symlink to /usr/bin: ${1}"
134                 dosym ../share/${1} /usr/bin/${trg}
135                 shift
136         done
137 }
138
139 # @FUNCTION: etexmf-update
140 # @DESCRIPTION:
141 # Runs texmf-update if it is available and prints a warning otherwise. This
142 # function helps in factorizing some code.  Useful in ebuilds' pkg_postinst and
143 # pkg_postrm phases.
144
145 etexmf-update() {
146         if has_version 'app-text/texlive-core' ; then
147                 if [[ -z ${ROOT} && -x "${EPREFIX}"/usr/sbin/texmf-update ]] ; then
148                         "${EPREFIX}"/usr/sbin/texmf-update
149                 else
150                         ewarn "Cannot run texmf-update for some reason."
151                         ewarn "Your texmf tree might be inconsistent with your configuration"
152                         ewarn "Please try to figure what has happened"
153                 fi
154         fi
155 }
156
157 # @FUNCTION: efmtutil-sys
158 # @DESCRIPTION:
159 # Runs fmtutil-sys if it is available and prints a warning otherwise. This
160 # function helps in factorizing some code. Used in ebuilds' pkg_postinst to
161 # force a rebuild of TeX formats.
162
163 efmtutil-sys() {
164         if has_version 'app-text/texlive-core' ; then
165                 if [[ -z ${ROOT} && -x "${EPREFIX}"/usr/bin/fmtutil-sys ]] ; then
166                         einfo "Rebuilding formats"
167                         "${EPREFIX}"/usr/bin/fmtutil-sys --all &> /dev/null || die
168                 else
169                         ewarn "Cannot run fmtutil-sys for some reason."
170                         ewarn "Your formats might be inconsistent with your installed ${PN} version"
171                         ewarn "Please try to figure what has happened"
172                 fi
173         fi
174 }
175
176 fi