app-admin/lastpass-cli: serve man from devspace #654846
[gentoo.git] / eclass / texlive-common.eclass
1 # Copyright 1999-2014 Gentoo Foundation
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 # @BLURB: Provide various functions used by both texlive-core and texlive modules
10 # @DESCRIPTION:
11 # Purpose: Provide various functions used by both texlive-core and texlive
12 # modules.
13 #
14 # Note that this eclass *must* not assume the presence of any standard tex tool
15
16 case "${EAPI:-0}" in
17         0|1|2)
18                 die "EAPI='${EAPI}' is not supported anymore"
19                 ;;
20         *)
21                 ;;
22 esac
23
24 TEXMF_PATH=/usr/share/texmf
25 TEXMF_DIST_PATH=/usr/share/texmf-dist
26 TEXMF_VAR_PATH=/var/lib/texmf
27
28 # @FUNCTION: texlive-common_handle_config_files
29 # @DESCRIPTION:
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
33 # configuration
34
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
41                         continue
42                 fi
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}
47         done
48 }
49
50 # @FUNCTION: texlive-common_is_file_present_in_texmf
51 # @DESCRIPTION:
52 # Return if a file is present in the texmf tree
53 # Call it from the directory containing texmf and texmf-dist
54
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}" \;
59         [ -f "${mark}" ]
60 }
61
62 # @FUNCTION: texlive-common_do_symlinks
63 # @USAGE: < src > < dest >
64 # @DESCRIPTION:
65 # Mimic the install_link function of texlinks
66 #
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.
73
74 texlive-common_do_symlinks() {
75         while [ $# != 0 ]; do
76                 case $1 in
77                         cont-??|metafun|mptopdf)
78                                 einfo "Symlink $1 skipped (special case)"
79                                 ;;
80                         mf)
81                                 einfo "Symlink $1 -> $2 skipped (texlive-core takes care of it)"
82                                 ;;
83                         *)
84                                 if [ $1 = $2 ];
85                                 then
86                                         einfo "Symlink $1 -> $2 skipped"
87                                 elif [ -e "${ED}/usr/bin/$1" -o -L "${ED}/usr/bin/$1" ];
88                                 then
89                                         einfo "Symlink $1 skipped (file exists)"
90                                 else
91                                         einfo "Making symlink from $1 to $2"
92                                         dosym $2 /usr/bin/$1
93                                 fi
94                                 ;;
95                 esac
96                 shift; shift;
97         done
98 }
99
100 # @FUNCTION: etexlinks
101 # @USAGE: < file >
102 # @DESCRIPTION:
103 # Mimic texlinks on a fmtutil format file
104 #
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.
112
113 etexlinks() {
114         # Install symlinks from formats to engines
115         texlive-common_do_symlinks $(sed '/^[      ]*#/d; /^[      ]*$/d' "$1" | awk '{print $1, $2}')
116 }
117
118 # @FUNCTION: dobin_texmf_scripts
119 # @USAGE: < file1 file2 ... >
120 # @DESCRIPTION:
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.
123
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"
130                 shift
131         done
132 }
133
134 # @FUNCTION: etexmf-update
135 # @USAGE: In ebuilds' pkg_postinst and pkg_postrm phases
136 # @DESCRIPTION:
137 # Runs texmf-update if it is available and prints a warning otherwise. This
138 # function helps in factorizing some code.
139
140 etexmf-update() {
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
144                 else
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"
148                 fi
149         fi
150 }
151
152 # @FUNCTION: efmtutil-sys
153 # @USAGE: In ebuilds' pkg_postinst to force a rebuild of TeX formats.
154 # @DESCRIPTION:
155 # Runs fmtutil-sys if it is available and prints a warning otherwise. This
156 # function helps in factorizing some code.
157
158 efmtutil-sys() {
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
163                 else
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"
167                 fi
168         fi
169 }