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

Contents of /eclass/font.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.54 - (show annotations) (download)
Mon Aug 29 01:28:10 2011 UTC (3 years, 2 months ago) by vapier
Branch: MAIN
Changes since 1.53: +2 -2 lines
trim useless trailing whitespace

1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.53 2011/08/22 04:46:31 vapier Exp $
4
5 # @ECLASS: font.eclass
6 # @MAINTAINER:
7 # fonts@gentoo.org
8 # @BLURB: Eclass to make font installation uniform
9
10 inherit eutils
11
12 EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
13
14 # @ECLASS-VARIABLE: FONT_SUFFIX
15 # @DEFAULT_UNSET
16 # @REQUIRED
17 # @DESCRIPTION:
18 # Space delimited list of font suffixes to install.
19 FONT_SUFFIX=${FONT_SUFFIX:-}
20
21 # @ECLASS-VARIABLE: FONT_S
22 # @DEFAULT_UNSET
23 # @REQUIRED
24 # @DESCRIPTION:
25 # Working directory containing the fonts.
26 FONT_S=${FONT_S:-${S}}
27
28 # @ECLASS-VARIABLE: FONT_PN
29 # @DESCRIPTION:
30 # Font name (ie. last part of FONTDIR).
31 FONT_PN=${FONT_PN:-${PN}}
32
33 # @ECLASS-VARIABLE: FONTDIR
34 # @DESCRIPTION:
35 # Full path to installation directory.
36 FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
37
38 # @ECLASS-VARIABLE: FONT_CONF
39 # @DEFAULT_UNSET
40 # @DESCRIPTION:
41 # Array containing fontconfig conf files to install.
42 FONT_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
50 DOCS=${DOCS:-}
51
52 IUSE="X"
53
54 DEPEND="X? (
55 x11-apps/mkfontdir
56 media-fonts/encodings
57 )
58 >=media-libs/fontconfig-2.4.0"
59
60 # @FUNCTION: font_xfont_config
61 # @DESCRIPTION:
62 # Generate Xorg font files (mkfontscale/mkfontdir).
63 font_xfont_config() {
64 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 mkfontdir \
69 -e ${EPREFIX}/usr/share/fonts/encodings \
70 -e ${EPREFIX}/usr/share/fonts/encodings/large \
71 "${ED}${FONTDIR}"
72 eend $?
73 if [[ -e ${FONT_S}/fonts.alias ]] ; then
74 doins "${FONT_S}"/fonts.alias
75 fi
76 fi
77 }
78
79 # @FUNCTION: font_fontconfig
80 # @DESCRIPTION:
81 # Install fontconfig conf files given in FONT_CONF.
82 font_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 }
91
92 # @FUNCTION: font_cleanup_dirs
93 # @DESCRIPTION:
94 # Remove font directories containing only generated files.
95 font_cleanup_dirs() {
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 '{}' \;
134 fi
135 done
136 eend 0
137 }
138
139 # @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 # @FUNCTION: font_src_install
162 # @DESCRIPTION:
163 # The font src_install function.
164 font_src_install() {
165 local suffix commondoc
166
167 pushd "${FONT_S}" > /dev/null
168
169 insinto "${FONTDIR}"
170
171 for suffix in ${FONT_SUFFIX}; do
172 doins *.${suffix}
173 done
174
175 rm -f fonts.{dir,scale} encodings.dir
176
177 font_xfont_config
178 font_fontconfig
179
180 popd > /dev/null
181
182 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
183
184 # install common docs
185 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
186 [[ -s ${commondoc} ]] && dodoc ${commondoc}
187 done
188 }
189
190 # @FUNCTION: font_pkg_postinst
191 # @DESCRIPTION:
192 # The font pkg_postinst function.
193 font_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
197
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
213 if [[ ${ROOT} == / ]]; then
214 ebegin "Updating global fontcache"
215 fc-cache -fs
216 eend $?
217 fi
218 }
219
220 # @FUNCTION: font_pkg_postrm
221 # @DESCRIPTION:
222 # The font pkg_postrm function.
223 font_pkg_postrm() {
224 font_cleanup_dirs
225
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
230 if [[ ${ROOT} == / ]]; then
231 ebegin "Updating global fontcache"
232 fc-cache -fs
233 eend $?
234 fi
235 }

  ViewVC Help
Powered by ViewVC 1.1.20