1 |
On Sonntag, 24. März 2019 19:41:24 CEST Michał Górny wrote: |
2 |
> -U9999, please. This is a huge eclass and probably requires more work |
3 |
> than you're showing us ;-). |
4 |
|
5 |
As requested, without any changes to v2 - and if this does not receive |
6 |
a reply I'll assume silent ack by fonts proj. |
7 |
|
8 |
|
9 |
--- a/eclass/font.eclass 2019-04-04 08:28:12.336171811 +0200 |
10 |
+++ b/eclass/font.eclass 2019-03-25 20:34:15.306062926 +0100 |
11 |
@@ -1,254 +1,257 @@ |
12 |
-# Copyright 1999-2015 Gentoo Foundation |
13 |
+# Copyright 1999-2019 Gentoo Foundation |
14 |
# Distributed under the terms of the GNU General Public License v2 |
15 |
|
16 |
# @ECLASS: font.eclass |
17 |
# @MAINTAINER: |
18 |
# fonts@g.o |
19 |
# @BLURB: Eclass to make font installation uniform |
20 |
|
21 |
case ${EAPI:-0} in |
22 |
- 0|1|2|3|4|5|6) ;; |
23 |
- *) die "EAPI ${EAPI} is not supported by font.eclass." ;; |
24 |
+ 0|1|2|3|4|5|6) inherit eutils ;; |
25 |
+ 7) ;; |
26 |
+ *) die "EAPI ${EAPI} is not supported by font.eclass." ;; |
27 |
esac |
28 |
|
29 |
-inherit eutils |
30 |
- |
31 |
EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm |
32 |
|
33 |
# @ECLASS-VARIABLE: FONT_SUFFIX |
34 |
# @DEFAULT_UNSET |
35 |
# @REQUIRED |
36 |
# @DESCRIPTION: |
37 |
# Space delimited list of font suffixes to install. |
38 |
FONT_SUFFIX=${FONT_SUFFIX:-} |
39 |
|
40 |
# @ECLASS-VARIABLE: FONT_S |
41 |
# @REQUIRED |
42 |
# @DESCRIPTION: |
43 |
# Space delimited list of directories containing the fonts. |
44 |
FONT_S=${FONT_S:-${S}} |
45 |
|
46 |
# @ECLASS-VARIABLE: FONT_PN |
47 |
# @DESCRIPTION: |
48 |
# Font name (ie. last part of FONTDIR). |
49 |
FONT_PN=${FONT_PN:-${PN}} |
50 |
|
51 |
# @ECLASS-VARIABLE: FONTDIR |
52 |
# @DESCRIPTION: |
53 |
# Full path to installation directory. |
54 |
FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}} |
55 |
|
56 |
# @ECLASS-VARIABLE: FONT_CONF |
57 |
# @DEFAULT_UNSET |
58 |
# @DESCRIPTION: |
59 |
# Array containing fontconfig conf files to install. |
60 |
FONT_CONF=( "" ) |
61 |
|
62 |
# @ECLASS-VARIABLE: DOCS |
63 |
# @DEFAULT_UNSET |
64 |
# @DESCRIPTION: |
65 |
# Space delimited list of docs to install. |
66 |
# We always install these: |
67 |
# COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt |
68 |
DOCS=${DOCS:-} |
69 |
|
70 |
IUSE="X" |
71 |
|
72 |
DEPEND="X? ( |
73 |
|| ( >=x11-apps/mkfontscale-1.2.0 x11-apps/mkfontdir ) |
74 |
media-fonts/encodings |
75 |
)" |
76 |
RDEPEND="" |
77 |
|
78 |
# @FUNCTION: font_xfont_config |
79 |
# @DESCRIPTION: |
80 |
# Generate Xorg font files (mkfontscale/mkfontdir). |
81 |
font_xfont_config() { |
82 |
local dir_name |
83 |
if has X ${IUSE//+} && use X ; then |
84 |
dir_name="${1:-${FONT_PN}}" |
85 |
+ rm -f "${ED%/}/${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir} \ |
86 |
+ || die "failed to prepare ${FONTDIR}/${1//${S}/}" |
87 |
ebegin "Creating fonts.scale & fonts.dir in ${dir_name##*/}" |
88 |
- rm -f "${ED}${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir} |
89 |
- mkfontscale "${ED}${FONTDIR}/${1//${S}/}" |
90 |
+ mkfontscale "${ED%/}/${FONTDIR}/${1//${S}/}" || eerror "failed to create fonts.scale" |
91 |
mkfontdir \ |
92 |
-e ${EPREFIX}/usr/share/fonts/encodings \ |
93 |
-e ${EPREFIX}/usr/share/fonts/encodings/large \ |
94 |
- "${ED}${FONTDIR}/${1//${S}/}" |
95 |
- eend $? |
96 |
- if [[ -e fonts.alias ]] ; then |
97 |
- doins fonts.alias |
98 |
+ "${ED%/}/${FONTDIR}/${1//${S}/}" || eerror "failed to create fonts.dir" |
99 |
+ if ! eend $? ; then |
100 |
+ die "failed to run mkfontscale or mkfontdir" |
101 |
fi |
102 |
+ [[ -e fonts.alias ]] && doins fonts.alias |
103 |
fi |
104 |
} |
105 |
|
106 |
# @FUNCTION: font_fontconfig |
107 |
# @DESCRIPTION: |
108 |
# Install fontconfig conf files given in FONT_CONF. |
109 |
font_fontconfig() { |
110 |
local conffile |
111 |
if [[ -n ${FONT_CONF[@]} ]]; then |
112 |
insinto /etc/fonts/conf.avail/ |
113 |
for conffile in "${FONT_CONF[@]}"; do |
114 |
[[ -e ${conffile} ]] && doins ${conffile} |
115 |
done |
116 |
fi |
117 |
} |
118 |
|
119 |
# @FUNCTION: font_cleanup_dirs |
120 |
# @DESCRIPTION: |
121 |
# Remove font directories containing only generated files. |
122 |
font_cleanup_dirs() { |
123 |
local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale" |
124 |
# fonts.alias isn't generated but it's a special case (see below). |
125 |
local d f g generated candidate otherfile |
126 |
|
127 |
ebegin "Cleaning up font directories" |
128 |
- find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do |
129 |
+ while read d; do |
130 |
candidate=false |
131 |
otherfile=false |
132 |
for f in "${d}"/*; do |
133 |
generated=false |
134 |
# make sure this is a file and not a subdir |
135 |
[[ -e ${f} || -L ${f} ]] || continue |
136 |
for g in ${genfiles}; do |
137 |
if [[ ${f##*/} == ${g} ]]; then |
138 |
# this is a generated file |
139 |
generated=true |
140 |
break |
141 |
fi |
142 |
done |
143 |
# if the file is a generated file then we know this is a font dir (as |
144 |
# opposed to something like encodings or util) and a candidate for |
145 |
# removal. if it's not generated then it's an "otherfile". |
146 |
${generated} && candidate=true || otherfile=true |
147 |
# if the directory is both a candidate for removal and contains at |
148 |
# least one "otherfile" then don't remove it. |
149 |
[[ ${candidate} == ${otherfile} ]] && break |
150 |
done |
151 |
# if in the end we only have generated files, purge the directory. |
152 |
if [[ ${candidate} == true && ${otherfile} == false ]]; then |
153 |
# we don't want to remove fonts.alias files that were installed by |
154 |
# media-fonts/font-alias. any other fonts.alias files will have |
155 |
# already been unmerged with their packages. |
156 |
for g in ${genfiles}; do |
157 |
- [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] \ |
158 |
- && rm "${d}"/${g} |
159 |
+ if [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] ; then |
160 |
+ rm "${d}"/${g} || eerror "failed to remove ${d}/${g}" |
161 |
+ fi |
162 |
done |
163 |
# if there's nothing left remove the directory |
164 |
- find "${d}" -maxdepth 0 -type d -empty -exec rmdir '{}' \; |
165 |
+ find "${d}" -maxdepth 0 -type d -empty -delete || eerror "failed to purge ${d}" |
166 |
fi |
167 |
- done |
168 |
+ done < <(find -L "${EROOT%/}"/usr/share/fonts/ -type d -print0) |
169 |
eend 0 |
170 |
} |
171 |
|
172 |
# @FUNCTION: font_pkg_setup |
173 |
# @DESCRIPTION: |
174 |
# The font pkg_setup function. |
175 |
# Collision protection and Prefix compat for eapi < 3. |
176 |
font_pkg_setup() { |
177 |
# Prefix compat |
178 |
case ${EAPI:-0} in |
179 |
0|1|2) |
180 |
if ! use prefix; then |
181 |
EPREFIX= |
182 |
ED=${D} |
183 |
EROOT=${ROOT} |
184 |
[[ ${EROOT} = */ ]] || EROOT+="/" |
185 |
fi |
186 |
;; |
187 |
esac |
188 |
|
189 |
# make sure we get no collisions |
190 |
# setup is not the nicest place, but preinst doesn't cut it |
191 |
- [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1" |
192 |
+ if [[ -e "${EROOT%/}/${FONTDIR}/fonts.cache-1" ]] ; then |
193 |
+ rm "${EROOT%/}/${FONTDIR}/fonts.cache-1" || die "failed to remove fonts.cache-1" |
194 |
+ fi |
195 |
} |
196 |
|
197 |
# @FUNCTION: font_src_install |
198 |
# @DESCRIPTION: |
199 |
# The font src_install function. |
200 |
font_src_install() { |
201 |
local dir suffix commondoc |
202 |
|
203 |
set -- ${FONT_S:-${S}} |
204 |
if [[ $# -gt 1 ]]; then |
205 |
# if we have multiple FONT_S elements then we want to recreate the dir |
206 |
# structure |
207 |
for dir in ${FONT_S}; do |
208 |
pushd "${dir}" > /dev/null |
209 |
insinto "${FONTDIR}/${dir//${S}/}" |
210 |
for suffix in ${FONT_SUFFIX}; do |
211 |
doins *.${suffix} |
212 |
done |
213 |
font_xfont_config "${dir}" |
214 |
popd > /dev/null |
215 |
done |
216 |
else |
217 |
pushd "${FONT_S}" > /dev/null |
218 |
insinto "${FONTDIR}" |
219 |
for suffix in ${FONT_SUFFIX}; do |
220 |
doins *.${suffix} |
221 |
done |
222 |
font_xfont_config |
223 |
popd > /dev/null |
224 |
fi |
225 |
|
226 |
font_fontconfig |
227 |
|
228 |
- [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; } |
229 |
+ [[ -n ${DOCS} ]] && dodoc ${DOCS} |
230 |
|
231 |
# install common docs |
232 |
for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do |
233 |
[[ -s ${commondoc} ]] && dodoc ${commondoc} |
234 |
done |
235 |
} |
236 |
|
237 |
+# @FUNCTION: _update_fontcache |
238 |
+# @DESCRIPTION: |
239 |
+# Updates fontcache if !prefix and media-libs/fontconfig installed |
240 |
+_update_fontcache() { |
241 |
+ # unreadable font files = fontconfig segfaults |
242 |
+ find "${EROOT%/}"/usr/share/fonts/ -type f '!' -perm 0644 \ |
243 |
+ -exec chmod -v 0644 2>/dev/null {} + || die "failed to fix font files perms" |
244 |
+ |
245 |
+ if [[ -z ${ROOT%/} ]] ; then |
246 |
+ if has_version media-libs/fontconfig ; then |
247 |
+ ebegin "Updating global fontcache" |
248 |
+ fc-cache -fs |
249 |
+ if ! eend $? ; then |
250 |
+ die "failed to update global fontcache" |
251 |
+ fi |
252 |
+ else |
253 |
+ einfo "Skipping fontcache update (media-libs/fontconfig not installed)" |
254 |
+ fi |
255 |
+ else |
256 |
+ einfo "Skipping fontcache update (ROOT != /)" |
257 |
+ fi |
258 |
+} |
259 |
+ |
260 |
# @FUNCTION: font_pkg_postinst |
261 |
# @DESCRIPTION: |
262 |
# The font pkg_postinst function. |
263 |
font_pkg_postinst() { |
264 |
- # unreadable font files = fontconfig segfaults |
265 |
- find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \ |
266 |
- | xargs -0 chmod -v 0644 2>/dev/null |
267 |
- |
268 |
if [[ -n ${FONT_CONF[@]} ]]; then |
269 |
local conffile |
270 |
- echo |
271 |
elog "The following fontconfig configuration files have been installed:" |
272 |
elog |
273 |
for conffile in "${FONT_CONF[@]}"; do |
274 |
- if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then |
275 |
- elog " $(basename ${conffile})" |
276 |
+ if [[ -e "${EROOT%/}"/etc/fonts/conf.avail/${conffile##*/} ]]; then |
277 |
+ elog " ${conffile##*/}" |
278 |
fi |
279 |
done |
280 |
elog |
281 |
elog "Use \`eselect fontconfig\` to enable/disable them." |
282 |
- echo |
283 |
fi |
284 |
|
285 |
- if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then |
286 |
- ebegin "Updating global fontcache" |
287 |
- fc-cache -fs |
288 |
- eend $? |
289 |
- else |
290 |
- einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)" |
291 |
- fi |
292 |
+ _update_fontcache |
293 |
} |
294 |
|
295 |
# @FUNCTION: font_pkg_postrm |
296 |
# @DESCRIPTION: |
297 |
# The font pkg_postrm function. |
298 |
font_pkg_postrm() { |
299 |
font_cleanup_dirs |
300 |
- |
301 |
- # unreadable font files = fontconfig segfaults |
302 |
- find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \ |
303 |
- | xargs -0 chmod -v 0644 2>/dev/null |
304 |
- |
305 |
- if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then |
306 |
- ebegin "Updating global fontcache" |
307 |
- fc-cache -fs |
308 |
- eend $? |
309 |
- else |
310 |
- einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)" |
311 |
- fi |
312 |
+ _update_fontcache |
313 |
} |