/[gentoo-x86]/eclass/font.eclass
Gentoo

Diff of /eclass/font.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.23 Revision 1.54
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2011 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.23 2007/06/24 06:15:21 dirtyepic Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.54 2011/08/29 01:28:10 vapier Exp $
4 4
5# Author: foser <foser@gentoo.org> 5# @ECLASS: font.eclass
6 6# @MAINTAINER:
7# Font Eclass 7# fonts@gentoo.org
8#
9# Eclass to make font installation uniform 8# @BLURB: Eclass to make font installation uniform
10 9
11inherit eutils 10inherit eutils
12 11
13# 12EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
14# Variable declarations
15#
16 13
14# @ECLASS-VARIABLE: FONT_SUFFIX
15# @DEFAULT_UNSET
16# @REQUIRED
17# @DESCRIPTION:
17FONT_SUFFIX="" # Space delimited list of font suffixes to install 18# Space delimited list of font suffixes to install.
19FONT_SUFFIX=${FONT_SUFFIX:-}
18 20
19FONT_S="${S}" # Dir containing the fonts 21# @ECLASS-VARIABLE: FONT_S
22# @DEFAULT_UNSET
23# @REQUIRED
24# @DESCRIPTION:
25# Working directory containing the fonts.
26FONT_S=${FONT_S:-${S}}
20 27
21FONT_PN="${PN}" # Last part of $FONTDIR 28# @ECLASS-VARIABLE: FONT_PN
29# @DESCRIPTION:
30# Font name (ie. last part of FONTDIR).
31FONT_PN=${FONT_PN:-${PN}}
22 32
23FONTDIR="/usr/share/fonts/${FONT_PN}" # this is where the fonts are installed 33# @ECLASS-VARIABLE: FONTDIR
34# @DESCRIPTION:
35# Full path to installation directory.
36FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
24 37
25DOCS="" # Docs to install 38# @ECLASS-VARIABLE: FONT_CONF
39# @DEFAULT_UNSET
40# @DESCRIPTION:
41# Array containing fontconfig conf files to install.
42FONT_CONF=( "" )
43
44# @ECLASS-VARIABLE: DOCS
45# @DEFAULT_UNSET
46# @DESCRIPTION:
47# Space delimited list of docs to install.
48# We always install these:
49# COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt
50DOCS=${DOCS:-}
26 51
27IUSE="X" 52IUSE="X"
28 53
29DEPEND="X? ( x11-apps/mkfontdir ) 54DEPEND="X? (
55 x11-apps/mkfontdir
56 media-fonts/encodings
57 )
30 media-libs/fontconfig" 58 >=media-libs/fontconfig-2.4.0"
31 59
32# 60# @FUNCTION: font_xfont_config
33# Public functions 61# @DESCRIPTION:
34# 62# Generate Xorg font files (mkfontscale/mkfontdir).
35
36font_xfont_config() { 63font_xfont_config() {
37 64 if has X ${IUSE//+} && use X ; then
38 # create Xfont files
39 if use X ; then
40 einfo "Creating fonts.scale & fonts.dir ..." 65 ebegin "Creating fonts.scale & fonts.dir"
66 rm -f "${ED}${FONTDIR}"/fonts.{dir,scale}
41 mkfontscale "${D}${FONTDIR}" 67 mkfontscale "${ED}${FONTDIR}"
42 mkfontdir \ 68 mkfontdir \
43 -e /usr/share/fonts/encodings \ 69 -e ${EPREFIX}/usr/share/fonts/encodings \
44 -e /usr/share/fonts/encodings/large \ 70 -e ${EPREFIX}/usr/share/fonts/encodings/large \
45 "${D}${FONTDIR}" 71 "${ED}${FONTDIR}"
72 eend $?
46 if [ -e "${FONT_S}/fonts.alias" ] ; then 73 if [[ -e ${FONT_S}/fonts.alias ]] ; then
47 doins "${FONT_S}/fonts.alias" 74 doins "${FONT_S}"/fonts.alias
48 fi 75 fi
49 fi 76 fi
50
51} 77}
52 78
79# @FUNCTION: font_fontconfig
80# @DESCRIPTION:
81# Install fontconfig conf files given in FONT_CONF.
53font_xft_config() { 82font_fontconfig() {
83 local conffile
84 if [[ -n ${FONT_CONF[@]} ]]; then
85 insinto /etc/fonts/conf.avail/
86 for conffile in "${FONT_CONF[@]}"; do
87 [[ -e ${conffile} ]] && doins ${conffile}
88 done
89 fi
90}
54 91
55 if ! has_version '>=media-libs/fontconfig-2.4'; then 92# @FUNCTION: font_cleanup_dirs
56 # create fontconfig cache 93# @DESCRIPTION:
57 einfo "Creating fontconfig cache ..." 94# Remove font directories containing only generated files.
58 # Mac OS X has fc-cache at /usr/X11R6/bin 95font_cleanup_dirs() {
59 HOME="/root" fc-cache -f "${D}${FONTDIR}" 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
99
100 ebegin "Cleaning up font directories"
101 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 # 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
111 generated=true
112 break
113 fi
114 done
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
122 done
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} ) ]] \
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 '{}' \;
60 fi 134 fi
135 done
136 eend 0
61} 137}
62 138
63# 139# @FUNCTION: font_pkg_setup
64# Public inheritable functions 140# @DESCRIPTION:
65# 141# The font pkg_setup function.
142# Collision protection and Prefix compat for eapi < 3.
143font_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
66 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# @FUNCTION: font_src_install
162# @DESCRIPTION:
163# The font src_install function.
67font_src_install() { 164font_src_install() {
68
69 local suffix commondoc 165 local suffix commondoc
70 166
71 cd "${FONT_S}" 167 pushd "${FONT_S}" > /dev/null
72 168
73 insinto "${FONTDIR}" 169 insinto "${FONTDIR}"
74 170
75 for suffix in ${FONT_SUFFIX}; do 171 for suffix in ${FONT_SUFFIX}; do
76 doins *.${suffix} 172 doins *.${suffix}
77 done 173 done
78 174
79 rm -f fonts.{dir,scale} encodings.dir 175 rm -f fonts.{dir,scale} encodings.dir
80 176
81 font_xfont_config 177 font_xfont_config
82 font_xft_config 178 font_fontconfig
83 179
84 cd "${S}" 180 popd > /dev/null
85 dodoc ${DOCS} 2> /dev/null 181
182 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
86 183
87 # install common docs 184 # install common docs
88 for commondoc in COPYRIGHT README NEWS AUTHORS BUGS ChangeLog; do 185 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
89 [ -s ${commondoc} ] && dodoc ${commondoc} 186 [[ -s ${commondoc} ]] && dodoc ${commondoc}
90 done 187 done
91} 188}
92 189
93font_pkg_setup() { 190# @FUNCTION: font_pkg_postinst
94 191# @DESCRIPTION:
95 # make sure we get no colissions 192# The font pkg_postinst function.
96 # setup is not the nicest place, but preinst doesn't cut it
97 [[ -e "${FONTDIR}/fonts.cache-1" ]] && rm -f "${FONTDIR}/fonts.cache-1"
98
99}
100
101font_pkg_postinst() { 193font_pkg_postinst() {
194 # unreadable font files = fontconfig segfaults
195 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
196 | xargs -0 chmod -v 0644 2>/dev/null
102 197
103 if has_version '>=media-libs/fontconfig-2.4'; then 198 if [[ -n ${FONT_CONF[@]} ]]; then
199 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
104 if [ ${ROOT} == "/" ]; then 213 if [[ ${ROOT} == / ]]; then
105 ebegin "Updating global fontcache" 214 ebegin "Updating global fontcache"
106 fc-cache -s 215 fc-cache -fs
107 eend $? 216 eend $?
108 fi 217 fi
109 fi
110
111} 218}
112 219
220# @FUNCTION: font_pkg_postrm
221# @DESCRIPTION:
222# The font pkg_postrm function.
113font_pkg_postrm() { 223font_pkg_postrm() {
224 font_cleanup_dirs
114 225
115 if has_version '>=media-libs/fontconfig-2.4'; then 226 # unreadable font files = fontconfig segfaults
227 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
228 | xargs -0 chmod -v 0644 2>/dev/null
229
116 if [ ${ROOT} == "/" ]; then 230 if [[ ${ROOT} == / ]]; then
117 ebegin "Updating global fontcache" 231 ebegin "Updating global fontcache"
118 fc-cache -s 232 fc-cache -fs
119 eend $? 233 eend $?
120 fi 234 fi
121 fi
122
123} 235}
124
125EXPORT_FUNCTIONS src_install pkg_setup pkg_postinst pkg_postrm

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.54

  ViewVC Help
Powered by ViewVC 1.1.20