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

Contents of /eclass/font.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.56 - (show annotations) (download)
Sun Jun 9 02:08:23 2013 UTC (18 months, 2 weeks ago) by lu_zero
Branch: MAIN
Changes since 1.55: +5 -5 lines
Do not require fontconfig at runtime, it isn't necessary for many purposes, thanks to Nikoli for the original patch

1 # Copyright 1999-2013 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.55 2013/04/05 13:25:25 yngwin 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 RDEPEND=""
60
61 # @FUNCTION: font_xfont_config
62 # @DESCRIPTION:
63 # Generate Xorg font files (mkfontscale/mkfontdir).
64 font_xfont_config() {
65 if has X ${IUSE//+} && use X ; then
66 ebegin "Creating fonts.scale & fonts.dir"
67 rm -f "${ED}${FONTDIR}"/fonts.{dir,scale}
68 mkfontscale "${ED}${FONTDIR}"
69 mkfontdir \
70 -e ${EPREFIX}/usr/share/fonts/encodings \
71 -e ${EPREFIX}/usr/share/fonts/encodings/large \
72 "${ED}${FONTDIR}"
73 eend $?
74 if [[ -e ${FONT_S}/fonts.alias ]] ; then
75 doins "${FONT_S}"/fonts.alias
76 fi
77 fi
78 }
79
80 # @FUNCTION: font_fontconfig
81 # @DESCRIPTION:
82 # Install fontconfig conf files given in FONT_CONF.
83 font_fontconfig() {
84 local conffile
85 if [[ -n ${FONT_CONF[@]} ]]; then
86 insinto /etc/fonts/conf.avail/
87 for conffile in "${FONT_CONF[@]}"; do
88 [[ -e ${conffile} ]] && doins ${conffile}
89 done
90 fi
91 }
92
93 # @FUNCTION: font_cleanup_dirs
94 # @DESCRIPTION:
95 # Remove font directories containing only generated files.
96 font_cleanup_dirs() {
97 local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
98 # fonts.alias isn't generated but it's a special case (see below).
99 local d f g generated candidate otherfile
100
101 ebegin "Cleaning up font directories"
102 find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
103 candidate=false
104 otherfile=false
105 for f in "${d}"/*; do
106 generated=false
107 # make sure this is a file and not a subdir
108 [[ -e ${f} || -L ${f} ]] || continue
109 for g in ${genfiles}; do
110 if [[ ${f##*/} == ${g} ]]; then
111 # this is a generated file
112 generated=true
113 break
114 fi
115 done
116 # if the file is a generated file then we know this is a font dir (as
117 # opposed to something like encodings or util) and a candidate for
118 # removal. if it's not generated then it's an "otherfile".
119 ${generated} && candidate=true || otherfile=true
120 # if the directory is both a candidate for removal and contains at
121 # least one "otherfile" then don't remove it.
122 [[ ${candidate} == ${otherfile} ]] && break
123 done
124 # if in the end we only have generated files, purge the directory.
125 if [[ ${candidate} == true && ${otherfile} == false ]]; then
126 # we don't want to remove fonts.alias files that were installed by
127 # media-fonts/font-alias. any other fonts.alias files will have
128 # already been unmerged with their packages.
129 for g in ${genfiles}; do
130 [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] \
131 && rm "${d}"/${g}
132 done
133 # if there's nothing left remove the directory
134 find "${d}" -maxdepth 0 -type d -empty -exec rmdir '{}' \;
135 fi
136 done
137 eend 0
138 }
139
140 # @FUNCTION: font_pkg_setup
141 # @DESCRIPTION:
142 # The font pkg_setup function.
143 # Collision protection and Prefix compat for eapi < 3.
144 font_pkg_setup() {
145 # Prefix compat
146 case ${EAPI:-0} in
147 0|1|2)
148 if ! use prefix; then
149 EPREFIX=
150 ED=${D}
151 EROOT=${ROOT}
152 [[ ${EROOT} = */ ]] || EROOT+="/"
153 fi
154 ;;
155 esac
156
157 # make sure we get no collisions
158 # setup is not the nicest place, but preinst doesn't cut it
159 [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
160 }
161
162 # @FUNCTION: font_src_install
163 # @DESCRIPTION:
164 # The font src_install function.
165 font_src_install() {
166 local suffix commondoc
167
168 pushd "${FONT_S}" > /dev/null
169
170 insinto "${FONTDIR}"
171
172 for suffix in ${FONT_SUFFIX}; do
173 doins *.${suffix}
174 done
175
176 rm -f fonts.{dir,scale} encodings.dir
177
178 font_xfont_config
179 font_fontconfig
180
181 popd > /dev/null
182
183 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
184
185 # install common docs
186 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
187 [[ -s ${commondoc} ]] && dodoc ${commondoc}
188 done
189 }
190
191 # @FUNCTION: font_pkg_postinst
192 # @DESCRIPTION:
193 # The font pkg_postinst function.
194 font_pkg_postinst() {
195 # unreadable font files = fontconfig segfaults
196 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
197 | xargs -0 chmod -v 0644 2>/dev/null
198
199 if [[ -n ${FONT_CONF[@]} ]]; then
200 local conffile
201 echo
202 elog "The following fontconfig configuration files have been installed:"
203 elog
204 for conffile in "${FONT_CONF[@]}"; do
205 if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
206 elog " $(basename ${conffile})"
207 fi
208 done
209 elog
210 elog "Use \`eselect fontconfig\` to enable/disable them."
211 echo
212 fi
213
214 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
215 ebegin "Updating global fontcache"
216 fc-cache -fs
217 eend $?
218 fi
219 }
220
221 # @FUNCTION: font_pkg_postrm
222 # @DESCRIPTION:
223 # The font pkg_postrm function.
224 font_pkg_postrm() {
225 font_cleanup_dirs
226
227 # unreadable font files = fontconfig segfaults
228 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
229 | xargs -0 chmod -v 0644 2>/dev/null
230
231 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
232 ebegin "Updating global fontcache"
233 fc-cache -fs
234 eend $?
235 fi
236 }

  ViewVC Help
Powered by ViewVC 1.1.20