| 1 |
vapier |
1.53 |
# Copyright 1999-2011 Gentoo Foundation |
| 2 |
foser |
1.1 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
vapier |
1.54 |
# $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.53 2011/08/22 04:46:31 vapier Exp $ |
| 4 |
foser |
1.1 |
|
| 5 |
pva |
1.38 |
# @ECLASS: font.eclass |
| 6 |
|
|
# @MAINTAINER: |
| 7 |
vapier |
1.53 |
# fonts@gentoo.org |
| 8 |
pva |
1.38 |
# @BLURB: Eclass to make font installation uniform |
| 9 |
foser |
1.1 |
|
| 10 |
kugelfang |
1.7 |
inherit eutils |
| 11 |
|
|
|
| 12 |
dirtyepic |
1.45 |
EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm |
| 13 |
|
|
|
| 14 |
pva |
1.38 |
# @ECLASS-VARIABLE: FONT_SUFFIX |
| 15 |
dirtyepic |
1.52 |
# @DEFAULT_UNSET |
| 16 |
|
|
# @REQUIRED |
| 17 |
pva |
1.38 |
# @DESCRIPTION: |
| 18 |
dirtyepic |
1.50 |
# Space delimited list of font suffixes to install. |
| 19 |
dirtyepic |
1.52 |
FONT_SUFFIX=${FONT_SUFFIX:-} |
| 20 |
pva |
1.38 |
|
| 21 |
|
|
# @ECLASS-VARIABLE: FONT_S |
| 22 |
dirtyepic |
1.52 |
# @DEFAULT_UNSET |
| 23 |
|
|
# @REQUIRED |
| 24 |
pva |
1.38 |
# @DESCRIPTION: |
| 25 |
dirtyepic |
1.50 |
# Working directory containing the fonts. |
| 26 |
dirtyepic |
1.52 |
FONT_S=${FONT_S:-${S}} |
| 27 |
pva |
1.38 |
|
| 28 |
|
|
# @ECLASS-VARIABLE: FONT_PN |
| 29 |
|
|
# @DESCRIPTION: |
| 30 |
dirtyepic |
1.50 |
# Font name (ie. last part of FONTDIR). |
| 31 |
dirtyepic |
1.52 |
FONT_PN=${FONT_PN:-${PN}} |
| 32 |
pva |
1.38 |
|
| 33 |
|
|
# @ECLASS-VARIABLE: FONTDIR |
| 34 |
|
|
# @DESCRIPTION: |
| 35 |
dirtyepic |
1.50 |
# Full path to installation directory. |
| 36 |
dirtyepic |
1.46 |
FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}} |
| 37 |
pva |
1.38 |
|
| 38 |
|
|
# @ECLASS-VARIABLE: FONT_CONF |
| 39 |
dirtyepic |
1.52 |
# @DEFAULT_UNSET |
| 40 |
pva |
1.38 |
# @DESCRIPTION: |
| 41 |
dirtyepic |
1.50 |
# Array containing fontconfig conf files to install. |
| 42 |
maekke |
1.43 |
FONT_CONF=( "" ) |
| 43 |
pva |
1.38 |
|
| 44 |
|
|
# @ECLASS-VARIABLE: DOCS |
| 45 |
dirtyepic |
1.52 |
# @DEFAULT_UNSET |
| 46 |
pva |
1.38 |
# @DESCRIPTION: |
| 47 |
dirtyepic |
1.50 |
# Space delimited list of docs to install. |
| 48 |
vapier |
1.53 |
# We always install these: |
| 49 |
dirtyepic |
1.52 |
# COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt |
| 50 |
dirtyepic |
1.46 |
DOCS=${DOCS:-} |
| 51 |
foser |
1.1 |
|
| 52 |
swegener |
1.15 |
IUSE="X" |
| 53 |
foser |
1.1 |
|
| 54 |
scarabeus |
1.48 |
DEPEND="X? ( |
| 55 |
|
|
x11-apps/mkfontdir |
| 56 |
|
|
media-fonts/encodings |
| 57 |
|
|
) |
| 58 |
|
|
>=media-libs/fontconfig-2.4.0" |
| 59 |
foser |
1.1 |
|
| 60 |
pva |
1.38 |
# @FUNCTION: font_xfont_config |
| 61 |
|
|
# @DESCRIPTION: |
| 62 |
dirtyepic |
1.50 |
# Generate Xorg font files (mkfontscale/mkfontdir). |
| 63 |
foser |
1.2 |
font_xfont_config() { |
| 64 |
scarabeus |
1.48 |
if has X ${IUSE//+} && use X ; then |
| 65 |
|
|
ebegin "Creating fonts.scale & fonts.dir" |
| 66 |
|
|
rm -f "${ED}${FONTDIR}"/fonts.{dir,scale} |
| 67 |
|
|
mkfontscale "${ED}${FONTDIR}" |
| 68 |
foser |
1.1 |
mkfontdir \ |
| 69 |
scarabeus |
1.48 |
-e ${EPREFIX}/usr/share/fonts/encodings \ |
| 70 |
|
|
-e ${EPREFIX}/usr/share/fonts/encodings/large \ |
| 71 |
|
|
"${ED}${FONTDIR}" |
| 72 |
|
|
eend $? |
| 73 |
dirtyepic |
1.50 |
if [[ -e ${FONT_S}/fonts.alias ]] ; then |
| 74 |
|
|
doins "${FONT_S}"/fonts.alias |
| 75 |
usata |
1.3 |
fi |
| 76 |
foser |
1.1 |
fi |
| 77 |
foser |
1.2 |
} |
| 78 |
|
|
|
| 79 |
pva |
1.38 |
# @FUNCTION: font_fontconfig |
| 80 |
|
|
# @DESCRIPTION: |
| 81 |
dirtyepic |
1.50 |
# Install fontconfig conf files given in FONT_CONF. |
| 82 |
dirtyepic |
1.24 |
font_fontconfig() { |
| 83 |
|
|
local conffile |
| 84 |
pva |
1.36 |
if [[ -n ${FONT_CONF[@]} ]]; then |
| 85 |
scarabeus |
1.48 |
insinto /etc/fonts/conf.avail/ |
| 86 |
|
|
for conffile in "${FONT_CONF[@]}"; do |
| 87 |
|
|
[[ -e ${conffile} ]] && doins ${conffile} |
| 88 |
|
|
done |
| 89 |
dirtyepic |
1.24 |
fi |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
dirtyepic |
1.49 |
# @FUNCTION: font_cleanup_dirs |
| 93 |
|
|
# @DESCRIPTION: |
| 94 |
dirtyepic |
1.50 |
# Remove font directories containing only generated files. |
| 95 |
dirtyepic |
1.49 |
font_cleanup_dirs() { |
| 96 |
|
|
local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale" |
| 97 |
dirtyepic |
1.51 |
# fonts.alias isn't generated but it's a special case (see below). |
| 98 |
dirtyepic |
1.49 |
local d f g generated candidate otherfile |
| 99 |
|
|
|
| 100 |
dirtyepic |
1.51 |
ebegin "Cleaning up font directories" |
| 101 |
dirtyepic |
1.49 |
find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do |
| 102 |
|
|
candidate=false |
| 103 |
|
|
otherfile=false |
| 104 |
|
|
for f in "${d}"/*; do |
| 105 |
|
|
generated=false |
| 106 |
dirtyepic |
1.51 |
# make sure this is a file and not a subdir |
| 107 |
dirtyepic |
1.49 |
[[ -e ${f} || -L ${f} ]] || continue |
| 108 |
|
|
for g in ${genfiles}; do |
| 109 |
|
|
if [[ ${f##*/} == ${g} ]]; then |
| 110 |
dirtyepic |
1.51 |
# this is a generated file |
| 111 |
dirtyepic |
1.49 |
generated=true |
| 112 |
|
|
break |
| 113 |
|
|
fi |
| 114 |
|
|
done |
| 115 |
dirtyepic |
1.51 |
# if the file is a generated file then we know this is a font dir (as |
| 116 |
dirtyepic |
1.52 |
# opposed to something like encodings or util) and a candidate for |
| 117 |
dirtyepic |
1.51 |
# removal. if it's not generated then it's an "otherfile". |
| 118 |
dirtyepic |
1.49 |
${generated} && candidate=true || otherfile=true |
| 119 |
dirtyepic |
1.51 |
# 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 |
| 122 |
dirtyepic |
1.49 |
done |
| 123 |
dirtyepic |
1.52 |
# if in the end we only have generated files, purge the directory. |
| 124 |
dirtyepic |
1.49 |
if [[ ${candidate} == true && ${otherfile} == false ]]; then |
| 125 |
dirtyepic |
1.51 |
# 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} ) ]] \ |
| 130 |
|
|
&& rm "${d}"/${g} |
| 131 |
|
|
done |
| 132 |
|
|
# if there's nothing left remove the directory |
| 133 |
|
|
find "${d}" -maxdepth 0 -type d -empty -exec rmdir '{}' \; |
| 134 |
dirtyepic |
1.49 |
fi |
| 135 |
|
|
done |
| 136 |
|
|
eend 0 |
| 137 |
|
|
} |
| 138 |
|
|
|
| 139 |
dirtyepic |
1.52 |
# @FUNCTION: font_pkg_setup |
| 140 |
|
|
# @DESCRIPTION: |
| 141 |
|
|
# The font pkg_setup function. |
| 142 |
|
|
# Collision protection and Prefix compat for eapi < 3. |
| 143 |
|
|
font_pkg_setup() { |
| 144 |
|
|
# Prefix compat |
| 145 |
|
|
case ${EAPI:-0} in |
| 146 |
|
|
0|1|2) |
| 147 |
|
|
if ! use prefix; then |
| 148 |
|
|
EPREFIX= |
| 149 |
|
|
ED=${D} |
| 150 |
|
|
EROOT=${ROOT} |
| 151 |
|
|
[[ ${EROOT} = */ ]] || EROOT+="/" |
| 152 |
|
|
fi |
| 153 |
|
|
;; |
| 154 |
|
|
esac |
| 155 |
|
|
|
| 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" |
| 159 |
|
|
} |
| 160 |
|
|
|
| 161 |
pva |
1.38 |
# @FUNCTION: font_src_install |
| 162 |
|
|
# @DESCRIPTION: |
| 163 |
scarabeus |
1.48 |
# The font src_install function. |
| 164 |
foser |
1.2 |
font_src_install() { |
| 165 |
dirtyepic |
1.23 |
local suffix commondoc |
| 166 |
foser |
1.2 |
|
| 167 |
scarabeus |
1.48 |
pushd "${FONT_S}" > /dev/null |
| 168 |
foser |
1.2 |
|
| 169 |
robbat2 |
1.18 |
insinto "${FONTDIR}" |
| 170 |
swegener |
1.15 |
|
| 171 |
foser |
1.2 |
for suffix in ${FONT_SUFFIX}; do |
| 172 |
dirtyepic |
1.28 |
doins *.${suffix} |
| 173 |
foser |
1.2 |
done |
| 174 |
|
|
|
| 175 |
|
|
rm -f fonts.{dir,scale} encodings.dir |
| 176 |
|
|
|
| 177 |
|
|
font_xfont_config |
| 178 |
dirtyepic |
1.24 |
font_fontconfig |
| 179 |
foser |
1.2 |
|
| 180 |
scarabeus |
1.48 |
popd > /dev/null |
| 181 |
|
|
|
| 182 |
|
|
[[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; } |
| 183 |
foser |
1.11 |
|
| 184 |
dirtyepic |
1.23 |
# install common docs |
| 185 |
dirtyepic |
1.37 |
for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do |
| 186 |
dirtyepic |
1.24 |
[[ -s ${commondoc} ]] && dodoc ${commondoc} |
| 187 |
dirtyepic |
1.23 |
done |
| 188 |
foser |
1.1 |
} |
| 189 |
|
|
|
| 190 |
pva |
1.38 |
# @FUNCTION: font_pkg_postinst |
| 191 |
|
|
# @DESCRIPTION: |
| 192 |
scarabeus |
1.48 |
# The font pkg_postinst function. |
| 193 |
foser |
1.19 |
font_pkg_postinst() { |
| 194 |
dirtyepic |
1.31 |
# unreadable font files = fontconfig segfaults |
| 195 |
scarabeus |
1.48 |
find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \ |
| 196 |
dirtyepic |
1.33 |
| xargs -0 chmod -v 0644 2>/dev/null |
| 197 |
dirtyepic |
1.30 |
|
| 198 |
dirtyepic |
1.45 |
if [[ -n ${FONT_CONF[@]} ]]; then |
| 199 |
scarabeus |
1.48 |
local conffile |
| 200 |
|
|
echo |
| 201 |
|
|
elog "The following fontconfig configuration files have been installed:" |
| 202 |
|
|
elog |
| 203 |
|
|
for conffile in "${FONT_CONF[@]}"; do |
| 204 |
|
|
if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then |
| 205 |
|
|
elog " $(basename ${conffile})" |
| 206 |
|
|
fi |
| 207 |
|
|
done |
| 208 |
|
|
elog |
| 209 |
|
|
elog "Use \`eselect fontconfig\` to enable/disable them." |
| 210 |
|
|
echo |
| 211 |
|
|
fi |
| 212 |
|
|
|
| 213 |
|
|
if [[ ${ROOT} == / ]]; then |
| 214 |
|
|
ebegin "Updating global fontcache" |
| 215 |
|
|
fc-cache -fs |
| 216 |
|
|
eend $? |
| 217 |
foser |
1.19 |
fi |
| 218 |
|
|
} |
| 219 |
|
|
|
| 220 |
pva |
1.38 |
# @FUNCTION: font_pkg_postrm |
| 221 |
|
|
# @DESCRIPTION: |
| 222 |
scarabeus |
1.48 |
# The font pkg_postrm function. |
| 223 |
foser |
1.19 |
font_pkg_postrm() { |
| 224 |
dirtyepic |
1.49 |
font_cleanup_dirs |
| 225 |
vapier |
1.54 |
|
| 226 |
dirtyepic |
1.31 |
# unreadable font files = fontconfig segfaults |
| 227 |
scarabeus |
1.48 |
find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \ |
| 228 |
dirtyepic |
1.33 |
| xargs -0 chmod -v 0644 2>/dev/null |
| 229 |
dirtyepic |
1.30 |
|
| 230 |
scarabeus |
1.48 |
if [[ ${ROOT} == / ]]; then |
| 231 |
|
|
ebegin "Updating global fontcache" |
| 232 |
|
|
fc-cache -fs |
| 233 |
|
|
eend $? |
| 234 |
foser |
1.19 |
fi |
| 235 |
foser |
1.12 |
} |