1 # Copyright 1999-2014 Gentoo Foundation
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>
9 # @BLURB: Provide various functions used by both texlive-core and texlive modules
11 # Purpose: Provide various functions used by both texlive-core and texlive
14 # Note that this eclass *must* not assume the presence of any standard tex tool
18 die "EAPI='${EAPI}' is not supported anymore"
24 TEXMF_PATH=/usr/share/texmf
25 TEXMF_DIST_PATH=/usr/share/texmf-dist
26 TEXMF_VAR_PATH=/var/lib/texmf
28 # @FUNCTION: texlive-common_handle_config_files
30 # Has to be called in src_install after having installed the files in ${D}
31 # This function will move the relevant files to /etc/texmf and symling them
32 # from their original location. This is to allow easy update of texlive's
35 texlive-common_handle_config_files() {
36 # Handle config files properly
37 [ -d "${ED}${TEXMF_PATH}" ] || return
38 cd "${ED}${TEXMF_PATH}"
39 for f in $(find . -name '*.cnf' -type f -o -name '*.cfg' -type f | sed -e "s:\./::g") ; do
40 if [ "${f#*config}" != "${f}" -o "${f#doc}" != "${f}" -o "${f#source}" != "${f}" -o "${f#tex}" != "${f}" ] ; then
43 dodir /etc/texmf/$(dirname ${f}).d
44 einfo "Moving (and symlinking) ${EPREFIX}${TEXMF_PATH}/${f} to ${EPREFIX}/etc/texmf/$(dirname ${f}).d"
45 mv "${ED}/${TEXMF_PATH}/${f}" "${ED}/etc/texmf/$(dirname ${f}).d" || die "mv ${f} failed."
46 dosym /etc/texmf/$(dirname ${f}).d/$(basename ${f}) ${TEXMF_PATH}/${f}
50 # @FUNCTION: texlive-common_is_file_present_in_texmf
52 # Return if a file is present in the texmf tree
53 # Call it from the directory containing texmf and texmf-dist
55 texlive-common_is_file_present_in_texmf() {
56 local mark="${T}/$1.found"
57 [ -d texmf ] && find texmf -name $1 -exec touch "${mark}" \;
58 [ -d texmf-dist ] && find texmf-dist -name $1 -exec touch "${mark}" \;
62 # @FUNCTION: texlive-common_do_symlinks
63 # @USAGE: < src > < dest >
65 # Mimic the install_link function of texlinks
67 # Should have the same behavior as the one in /usr/bin/texlinks
68 # except that it is under the control of the package manager
69 # Note that $1 corresponds to $src and $2 to $dest in this function
70 # ( Arguments are switched because texlinks main function sends them switched )
71 # This function should not be called from an ebuild, prefer etexlinks that will
72 # also do the fmtutil file parsing.
74 texlive-common_do_symlinks() {
77 cont-??|metafun|mptopdf)
78 einfo "Symlink $1 skipped (special case)"
81 einfo "Symlink $1 -> $2 skipped (texlive-core takes care of it)"
86 einfo "Symlink $1 -> $2 skipped"
87 elif [ -e "${ED}/usr/bin/$1" -o -L "${ED}/usr/bin/$1" ];
89 einfo "Symlink $1 skipped (file exists)"
91 einfo "Making symlink from $1 to $2"
100 # @FUNCTION: etexlinks
103 # Mimic texlinks on a fmtutil format file
105 # $1 has to be a fmtutil format file like fmtutil.cnf
106 # etexlinks foo will install the symlinks that texlinks --cnffile foo would have
107 # created. We cannot use texlinks with portage as it is not DESTDIR aware.
108 # (It would not fail but will not create the symlinks if the target is not in
109 # the same dir as the source)
110 # Also, as this eclass must not depend on a tex distribution to be installed we
111 # cannot use texlinks from here.
114 # Install symlinks from formats to engines
115 texlive-common_do_symlinks $(sed '/^[ ]*#/d; /^[ ]*$/d' "$1" | awk '{print $1, $2}')
118 # @FUNCTION: dobin_texmf_scripts
119 # @USAGE: < file1 file2 ... >
121 # Symlinks a script from the texmf tree to /usr/bin. Requires permissions to be
122 # correctly set for the file that it will point to.
124 dobin_texmf_scripts() {
125 while [ $# -gt 0 ] ; do
126 local trg=$(basename ${1} | sed 's,\.[^/]*$,,' | tr '[:upper:]' '[:lower:]')
127 einfo "Installing ${1} as ${trg} bin wrapper"
128 [ -x "${ED}/usr/share/${1}" ] || die "Trying to install a non existing or non executable symlink to /usr/bin: ${1}"
129 dosym ../share/${1} /usr/bin/${trg} || die "failed to install ${1} as $trg"
134 # @FUNCTION: etexmf-update
135 # @USAGE: In ebuilds' pkg_postinst and pkg_postrm phases
137 # Runs texmf-update if it is available and prints a warning otherwise. This
138 # function helps in factorizing some code.
141 if has_version 'app-text/texlive-core' ; then
142 if [ "$ROOT" = "/" ] && [ -x "${EPREFIX}"/usr/sbin/texmf-update ] ; then
143 "${EPREFIX}"/usr/sbin/texmf-update
145 ewarn "Cannot run texmf-update for some reason."
146 ewarn "Your texmf tree might be inconsistent with your configuration"
147 ewarn "Please try to figure what has happened"
152 # @FUNCTION: efmtutil-sys
153 # @USAGE: In ebuilds' pkg_postinst to force a rebuild of TeX formats.
155 # Runs fmtutil-sys if it is available and prints a warning otherwise. This
156 # function helps in factorizing some code.
159 if has_version 'app-text/texlive-core' ; then
160 if [ "$ROOT" = "/" ] && [ -x "${EPREFIX}"/usr/bin/fmtutil-sys ] ; then
161 einfo "Rebuilding formats"
162 "${EPREFIX}"/usr/bin/fmtutil-sys --all &> /dev/null
164 ewarn "Cannot run fmtutil-sys for some reason."
165 ewarn "Your formats might be inconsistent with your installed ${PN} version"
166 ewarn "Please try to figure what has happened"