1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: texlive-common.eclass
8 # Original Author: Alexis Ballier <aballier@gentoo.org>
10 # @BLURB: Provide various functions used by both texlive-core and texlive modules
12 # Purpose: Provide various functions used by both texlive-core and texlive
15 # Note that this eclass *must* not assume the presence of any standard tex too
17 if [[ -z ${_TEXLIVE_COMMON_ECLASS} ]]; then
18 _TEXLIVE_COMMON_ECLASS=1
21 [0-6]) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
23 *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
26 TEXMF_PATH=/usr/share/texmf
27 TEXMF_DIST_PATH=/usr/share/texmf-dist
28 TEXMF_VAR_PATH=/var/lib/texmf
30 # @FUNCTION: texlive-common_handle_config_files
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
37 texlive-common_handle_config_files() {
38 # Handle config files properly
39 [[ -d ${ED}${TEXMF_PATH} ]] || return
40 cd "${ED}${TEXMF_PATH}" || die
42 while read -r -d '' i; do
43 if [[ ${f#*config} != ${f} || ${f#doc} != ${f} || ${f#source} != ${f} || ${f#tex} != ${f} ]] ; then
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")
53 # @FUNCTION: texlive-common_is_file_present_in_texmf
55 # Return if a file is present in the texmf tree
56 # Call it from the directory containing texmf and texmf-dist
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
64 if [[ -d texmf-dist ]]; then
65 find texmf-dist -name ${1} -exec touch ${mark} {} + || die
69 # @FUNCTION: texlive-common_do_symlinks
70 # @USAGE: <src> <dest>
72 # Mimic the install_link function of texlinks
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.
81 texlive-common_do_symlinks() {
82 while [[ ${#} != 0 ]]; do
84 cont-??|metafun|mptopdf)
85 einfo "Symlink ${1} skipped (special case)"
88 einfo "Symlink ${1} -> ${2} skipped (texlive-core takes care of it)"
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)"
96 einfo "Making symlink from ${1} to ${2}"
97 dosym ${2} /usr/bin/${1}
105 # @FUNCTION: etexlinks
108 # Mimic texlinks on a fmtutil format file
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.
119 # Install symlinks from formats to engines
120 texlive-common_do_symlinks $(sed '/^[ ]*#/d; /^[ ]*$/d' "$1" | awk '{print $1, $2}')
123 # @FUNCTION: dobin_texmf_scripts
124 # @USAGE: <file1> [file2] ...
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.
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}
139 # @FUNCTION: etexmf-update
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
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
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"
157 # @FUNCTION: efmtutil-sys
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.
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
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"