1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: texlive-common.eclass
9 # 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 tool
19 die "EAPI='${EAPI}' is not supported anymore"
25 TEXMF_PATH=/usr/share/texmf
26 TEXMF_DIST_PATH=/usr/share/texmf-dist
27 TEXMF_VAR_PATH=/var/lib/texmf
29 # @FUNCTION: texlive-common_handle_config_files
31 # Has to be called in src_install after having installed the files in ${D}
32 # This function will move the relevant files to /etc/texmf and symling them
33 # from their original location. This is to allow easy update of texlive's
36 texlive-common_handle_config_files() {
37 # Handle config files properly
38 [ -d "${ED}${TEXMF_PATH}" ] || return
39 cd "${ED}${TEXMF_PATH}"
40 for f in $(find . -name '*.cnf' -type f -o -name '*.cfg' -type f | sed -e "s:\./::g") ; do
41 if [ "${f#*config}" != "${f}" -o "${f#doc}" != "${f}" -o "${f#source}" != "${f}" -o "${f#tex}" != "${f}" ] ; then
44 dodir /etc/texmf/$(dirname ${f}).d
45 einfo "Moving (and symlinking) ${EPREFIX}${TEXMF_PATH}/${f} to ${EPREFIX}/etc/texmf/$(dirname ${f}).d"
46 mv "${ED}/${TEXMF_PATH}/${f}" "${ED}/etc/texmf/$(dirname ${f}).d" || die "mv ${f} failed."
47 dosym /etc/texmf/$(dirname ${f}).d/$(basename ${f}) ${TEXMF_PATH}/${f}
51 # @FUNCTION: texlive-common_is_file_present_in_texmf
53 # Return if a file is present in the texmf tree
54 # Call it from the directory containing texmf and texmf-dist
56 texlive-common_is_file_present_in_texmf() {
57 local mark="${T}/$1.found"
58 [ -d texmf ] && find texmf -name $1 -exec touch "${mark}" \;
59 [ -d texmf-dist ] && find texmf-dist -name $1 -exec touch "${mark}" \;
63 # @FUNCTION: texlive-common_do_symlinks
64 # @USAGE: < src > < dest >
66 # Mimic the install_link function of texlinks
68 # Should have the same behavior as the one in /usr/bin/texlinks
69 # except that it is under the control of the package manager
70 # Note that $1 corresponds to $src and $2 to $dest in this function
71 # ( Arguments are switched because texlinks main function sends them switched )
72 # This function should not be called from an ebuild, prefer etexlinks that will
73 # also do the fmtutil file parsing.
75 texlive-common_do_symlinks() {
78 cont-??|metafun|mptopdf)
79 einfo "Symlink $1 skipped (special case)"
82 einfo "Symlink $1 -> $2 skipped (texlive-core takes care of it)"
87 einfo "Symlink $1 -> $2 skipped"
88 elif [ -e "${ED}/usr/bin/$1" -o -L "${ED}/usr/bin/$1" ];
90 einfo "Symlink $1 skipped (file exists)"
92 einfo "Making symlink from $1 to $2"
101 # @FUNCTION: etexlinks
104 # Mimic texlinks on a fmtutil format file
106 # $1 has to be a fmtutil format file like fmtutil.cnf
107 # etexlinks foo will install the symlinks that texlinks --cnffile foo would have
108 # created. We cannot use texlinks with portage as it is not DESTDIR aware.
109 # (It would not fail but will not create the symlinks if the target is not in
110 # the same dir as the source)
111 # Also, as this eclass must not depend on a tex distribution to be installed we
112 # cannot use texlinks from here.
115 # Install symlinks from formats to engines
116 texlive-common_do_symlinks $(sed '/^[ ]*#/d; /^[ ]*$/d' "$1" | awk '{print $1, $2}')
119 # @FUNCTION: dobin_texmf_scripts
120 # @USAGE: < file1 file2 ... >
122 # Symlinks a script from the texmf tree to /usr/bin. Requires permissions to be
123 # correctly set for the file that it will point to.
125 dobin_texmf_scripts() {
126 while [ $# -gt 0 ] ; do
127 local trg=$(basename ${1} | sed 's,\.[^/]*$,,' | tr '[:upper:]' '[:lower:]')
128 einfo "Installing ${1} as ${trg} bin wrapper"
129 [ -x "${ED}/usr/share/${1}" ] || die "Trying to install a non existing or non executable symlink to /usr/bin: ${1}"
130 dosym ../share/${1} /usr/bin/${trg} || die "failed to install ${1} as $trg"
135 # @FUNCTION: etexmf-update
136 # @USAGE: In ebuilds' pkg_postinst and pkg_postrm phases
138 # Runs texmf-update if it is available and prints a warning otherwise. This
139 # function helps in factorizing some code.
142 if has_version 'app-text/texlive-core' ; then
143 if [ "$ROOT" = "/" ] && [ -x "${EPREFIX}"/usr/sbin/texmf-update ] ; then
144 "${EPREFIX}"/usr/sbin/texmf-update
146 ewarn "Cannot run texmf-update for some reason."
147 ewarn "Your texmf tree might be inconsistent with your configuration"
148 ewarn "Please try to figure what has happened"
153 # @FUNCTION: efmtutil-sys
154 # @USAGE: In ebuilds' pkg_postinst to force a rebuild of TeX formats.
156 # Runs fmtutil-sys if it is available and prints a warning otherwise. This
157 # function helps in factorizing some code.
160 if has_version 'app-text/texlive-core' ; then
161 if [ "$ROOT" = "/" ] && [ -x "${EPREFIX}"/usr/bin/fmtutil-sys ] ; then
162 einfo "Rebuilding formats"
163 "${EPREFIX}"/usr/bin/fmtutil-sys --all &> /dev/null
165 ewarn "Cannot run fmtutil-sys for some reason."
166 ewarn "Your formats might be inconsistent with your installed ${PN} version"
167 ewarn "Please try to figure what has happened"