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

Diff of /eclass/font.eclass

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

Revision 1.1.1.1 Revision 1.57
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2013 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.1.1.1 2005/11/30 09:59:23 chriswhite Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.57 2013/07/25 13:13:18 pva 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 more uniform 8# @BLURB: Eclass to make font installation uniform
10 9
11inherit eutils 10inherit eutils
12 11
12EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
13 13
14# 14# @ECLASS-VARIABLE: FONT_SUFFIX
15# Variable declarations 15# @DEFAULT_UNSET
16# 16# @REQUIRED
17 17# @DESCRIPTION:
18FONT_SUFFIX="" # Space delimited list of font suffixes to install 18# Space delimited list of font suffixes to install.
19FONT_SUFFIX=${FONT_SUFFIX:-}
19 20
20FONT_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}}
21 27
22DOCS="" # Docs to install 28# @ECLASS-VARIABLE: FONT_PN
29# @DESCRIPTION:
30# Font name (ie. last part of FONTDIR).
31FONT_PN=${FONT_PN:-${PN}}
32
33# @ECLASS-VARIABLE: FONTDIR
34# @DESCRIPTION:
35# Full path to installation directory.
36FONTDIR=${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.
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:-}
23 51
24IUSE="X" 52IUSE="X"
25 53
26DEPEND="X? ( virtual/x11 ) 54DEPEND="X? (
27 media-libs/fontconfig" 55 x11-apps/mkfontdir
56 media-fonts/encodings
57 )"
58RDEPEND=""
28 59
29# 60# @FUNCTION: font_xfont_config
30# Public functions 61# @DESCRIPTION:
31# 62# Generate Xorg font files (mkfontscale/mkfontdir).
32
33font_xfont_config() { 63font_xfont_config() {
34 64 if has X ${IUSE//+} && use X ; then
35 # create Xfont files
36 if use X ; then
37 einfo "Creating fonts.scale & fonts.dir ..." 65 ebegin "Creating fonts.scale & fonts.dir"
38 mkfontscale "${D}/usr/share/fonts/${PN}" 66 rm -f "${ED}${FONTDIR}"/fonts.{dir,scale}
67 mkfontscale "${ED}${FONTDIR}"
39 mkfontdir \ 68 mkfontdir \
40 -e /usr/share/fonts/encodings \ 69 -e ${EPREFIX}/usr/share/fonts/encodings \
41 -e /usr/share/fonts/encodings/large \ 70 -e ${EPREFIX}/usr/share/fonts/encodings/large \
42 "${D}/usr/share/fonts/${PN}" 71 "${ED}${FONTDIR}"
72 eend $?
43 if [ -e "${FONT_S}/fonts.alias" ] ; then 73 if [[ -e ${FONT_S}/fonts.alias ]] ; then
44 doins "${FONT_S}/fonts.alias" 74 doins "${FONT_S}"/fonts.alias
45 fi 75 fi
46 fi 76 fi
47
48} 77}
49 78
79# @FUNCTION: font_fontconfig
80# @DESCRIPTION:
81# Install fontconfig conf files given in FONT_CONF.
50font_xft_config() { 82font_fontconfig() {
51 83 local conffile
52 # create fontconfig cache 84 if [[ -n ${FONT_CONF[@]} ]]; then
53 einfo "Creating fontconfig cache ..." 85 insinto /etc/fonts/conf.avail/
54 # Mac OS X has fc-cache at /usr/X11R6/bin 86 for conffile in "${FONT_CONF[@]}"; do
55 HOME="/root" fc-cache -f "${D}/usr/share/fonts/${PN}" 87 [[ -e ${conffile} ]] && doins ${conffile}
56 88 done
89 fi
57} 90}
58 91
59# 92# @FUNCTION: font_cleanup_dirs
60# Public inheritable functions 93# @DESCRIPTION:
61# 94# Remove font directories containing only generated files.
95font_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
62 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.
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
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.
63font_src_install() { 164font_src_install() {
165 local suffix commondoc
64 166
65 local suffix 167 pushd "${FONT_S}" > /dev/null
66 168
67 cd "${FONT_S}" 169 insinto "${FONTDIR}"
68
69 insinto "/usr/share/fonts/${PN}"
70 170
71 for suffix in ${FONT_SUFFIX}; do 171 for suffix in ${FONT_SUFFIX}; do
72 doins *.${suffix} 172 doins *.${suffix}
73 done 173 done
74 174
75 rm -f fonts.{dir,scale} encodings.dir 175 rm -f fonts.{dir,scale} encodings.dir
76 176
77 font_xfont_config 177 font_xfont_config
78 font_xft_config 178 font_fontconfig
79 179
80 cd "${S}" 180 popd > /dev/null
181
182 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
183
81 # try to install some common docs 184 # install common docs
82 DOCS="${DOCS} COPYRIGHT README NEWS" 185 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
83 dodoc ${DOCS} 186 [[ -s ${commondoc} ]] && dodoc ${commondoc}
84 187 done
85} 188}
86 189
190# @FUNCTION: font_pkg_postinst
191# @DESCRIPTION:
192# The font pkg_postinst function.
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
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 has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
214 ebegin "Updating global fontcache"
215 fc-cache -fs
216 eend $?
217 else
218 einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
219 fi
220}
221
222# @FUNCTION: font_pkg_postrm
223# @DESCRIPTION:
224# The font pkg_postrm function.
87font_pkg_setup() { 225font_pkg_postrm() {
226 font_cleanup_dirs
88 227
89 # make sure we get no colissions 228 # unreadable font files = fontconfig segfaults
90 # setup is not the nicest place, but preinst doesn't cut it 229 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
91 rm "/usr/share/fonts/${PN}/fonts.cache-1" 230 | xargs -0 chmod -v 0644 2>/dev/null
92 231
232 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
233 ebegin "Updating global fontcache"
234 fc-cache -fs
235 eend $?
236 else
237 einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
238 fi
93} 239}
94
95EXPORT_FUNCTIONS src_install pkg_setup

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.57

  ViewVC Help
Powered by ViewVC 1.1.20