1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 # @BLURB: Eclass to make font installation uniform
11 EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
13 # @ECLASS-VARIABLE: FONT_SUFFIX
17 # Space delimited list of font suffixes to install.
18 FONT_SUFFIX=${FONT_SUFFIX:-}
20 # @ECLASS-VARIABLE: FONT_S
23 # Space delimited list of directories containing the fonts.
24 FONT_S=${FONT_S:-${S}}
26 # @ECLASS-VARIABLE: FONT_PN
28 # Font name (ie. last part of FONTDIR).
29 FONT_PN=${FONT_PN:-${PN}}
31 # @ECLASS-VARIABLE: FONTDIR
33 # Full path to installation directory.
34 FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
36 # @ECLASS-VARIABLE: FONT_CONF
39 # Array containing fontconfig conf files to install.
42 # @ECLASS-VARIABLE: DOCS
45 # Space delimited list of docs to install.
46 # We always install these:
47 # COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt
58 # @FUNCTION: font_xfont_config
60 # Generate Xorg font files (mkfontscale/mkfontdir).
63 if has X ${IUSE//+} && use X ; then
64 dir_name="${1:-${FONT_PN}}"
65 ebegin "Creating fonts.scale & fonts.dir in ${dir_name##*/}"
66 rm -f "${ED}${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir}
67 mkfontscale "${ED}${FONTDIR}/${1//${S}/}"
69 -e ${EPREFIX}/usr/share/fonts/encodings \
70 -e ${EPREFIX}/usr/share/fonts/encodings/large \
71 "${ED}${FONTDIR}/${1//${S}/}"
73 if [[ -e fonts.alias ]] ; then
79 # @FUNCTION: font_fontconfig
81 # Install fontconfig conf files given in FONT_CONF.
84 if [[ -n ${FONT_CONF[@]} ]]; then
85 insinto /etc/fonts/conf.avail/
86 for conffile in "${FONT_CONF[@]}"; do
87 [[ -e ${conffile} ]] && doins ${conffile}
92 # @FUNCTION: font_cleanup_dirs
94 # Remove font directories containing only generated files.
96 local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
97 # fonts.alias isn't generated but it's a special case (see below).
98 local d f g generated candidate otherfile
100 ebegin "Cleaning up font directories"
101 find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
104 for f in "${d}"/*; do
106 # make sure this is a file and not a subdir
107 [[ -e ${f} || -L ${f} ]] || continue
108 for g in ${genfiles}; do
109 if [[ ${f##*/} == ${g} ]]; then
110 # this is a generated file
115 # if the file is a generated file then we know this is a font dir (as
116 # opposed to something like encodings or util) and a candidate for
117 # removal. if it's not generated then it's an "otherfile".
118 ${generated} && candidate=true || otherfile=true
119 # if the directory is both a candidate for removal and contains at
120 # least one "otherfile" then don't remove it.
121 [[ ${candidate} == ${otherfile} ]] && break
123 # if in the end we only have generated files, purge the directory.
124 if [[ ${candidate} == true && ${otherfile} == false ]]; then
125 # we don't want to remove fonts.alias files that were installed by
126 # media-fonts/font-alias. any other fonts.alias files will have
127 # already been unmerged with their packages.
128 for g in ${genfiles}; do
129 [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] \
132 # if there's nothing left remove the directory
133 find "${d}" -maxdepth 0 -type d -empty -exec rmdir '{}' \;
139 # @FUNCTION: font_pkg_setup
141 # The font pkg_setup function.
142 # Collision protection and Prefix compat for eapi < 3.
147 if ! use prefix; then
151 [[ ${EROOT} = */ ]] || EROOT+="/"
156 # make sure we get no collisions
157 # setup is not the nicest place, but preinst doesn't cut it
158 [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
161 # @FUNCTION: font_src_install
163 # The font src_install function.
165 local dir suffix commondoc
167 set -- ${FONT_S:-${S}}
168 if [[ $# -gt 1 ]]; then
169 # if we have multiple FONT_S elements then we want to recreate the dir
171 for dir in ${FONT_S}; do
172 pushd "${dir}" > /dev/null
173 insinto "${FONTDIR}/${dir//${S}/}"
174 for suffix in ${FONT_SUFFIX}; do
177 font_xfont_config "${dir}"
181 pushd "${FONT_S}" > /dev/null
183 for suffix in ${FONT_SUFFIX}; do
192 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
194 # install common docs
195 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
196 [[ -s ${commondoc} ]] && dodoc ${commondoc}
200 # @FUNCTION: font_pkg_postinst
202 # The font pkg_postinst function.
203 font_pkg_postinst() {
204 # unreadable font files = fontconfig segfaults
205 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
206 | xargs -0 chmod -v 0644 2>/dev/null
208 if [[ -n ${FONT_CONF[@]} ]]; then
211 elog "The following fontconfig configuration files have been installed:"
213 for conffile in "${FONT_CONF[@]}"; do
214 if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
215 elog " $(basename ${conffile})"
219 elog "Use \`eselect fontconfig\` to enable/disable them."
223 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
224 ebegin "Updating global fontcache"
228 einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
232 # @FUNCTION: font_pkg_postrm
234 # The font pkg_postrm function.
238 # unreadable font files = fontconfig segfaults
239 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
240 | xargs -0 chmod -v 0644 2>/dev/null
242 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
243 ebegin "Updating global fontcache"
247 einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"