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

Diff of /eclass/font.eclass

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

Revision 1.46 Revision 1.51
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2010 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.46 2009/09/13 04:47:34 dirtyepic Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.51 2010/07/09 03:44:19 dirtyepic Exp $
4 4
5# @ECLASS: font.eclass 5# @ECLASS: font.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# fonts@gentoo.org 7# fonts@gentoo.org
8#
9# Author: foser <foser@gentoo.org>
10# @BLURB: Eclass to make font installation uniform 8# @BLURB: Eclass to make font installation uniform
11 9
12inherit eutils 10inherit eutils
13 11
14
15EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm 12EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
16 13
17#
18# Variable declarations
19#
20
21# @ECLASS-VARIABLE: FONT_SUFFIX 14# @ECLASS-VARIABLE: FONT_SUFFIX
22# @DESCRIPTION: 15# @DESCRIPTION:
23# Space delimited list of font suffixes to install 16# Space delimited list of font suffixes to install.
24FONT_SUFFIX=${FONT_SUFFIX:-} 17FONT_SUFFIX=${FONT_SUFFIX:=}
25 18
26# @ECLASS-VARIABLE: FONT_S 19# @ECLASS-VARIABLE: FONT_S
27# @DESCRIPTION: 20# @DESCRIPTION:
28# Dir containing the fonts 21# Working directory containing the fonts.
29FONT_S=${S} 22FONT_S=${FONT_S:=${S}}
30 23
31# @ECLASS-VARIABLE: FONT_PN 24# @ECLASS-VARIABLE: FONT_PN
32# @DESCRIPTION: 25# @DESCRIPTION:
33# Last part of $FONTDIR 26# Font name (ie. last part of FONTDIR).
34FONT_PN=${FONT_PN:-${PN}} 27FONT_PN=${FONT_PN:=${PN}}
35 28
36# @ECLASS-VARIABLE: FONTDIR 29# @ECLASS-VARIABLE: FONTDIR
37# @DESCRIPTION: 30# @DESCRIPTION:
38# This is where the fonts are installed 31# Full path to installation directory.
39FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}} 32FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
40 33
41# @ECLASS-VARIABLE: FONT_CONF 34# @ECLASS-VARIABLE: FONT_CONF
42# @DESCRIPTION: 35# @DESCRIPTION:
43# Array, which element(s) is(are) path(s) of fontconfig-2.4 file(s) to install 36# Array containing fontconfig conf files to install.
44FONT_CONF=( "" ) 37FONT_CONF=( "" )
45 38
46# @ECLASS-VARIABLE: DOCS 39# @ECLASS-VARIABLE: DOCS
47# @DESCRIPTION: 40# @DESCRIPTION:
48# Docs to install 41# Space delimited list of docs to install.
49DOCS=${DOCS:-} 42DOCS=${DOCS:-}
50 43
51IUSE="X" 44IUSE="X"
52 45
53DEPEND="X? ( x11-apps/mkfontdir 46DEPEND="X? (
47 x11-apps/mkfontdir
54 media-fonts/encodings ) 48 media-fonts/encodings
49 )
55 media-libs/fontconfig" 50 >=media-libs/fontconfig-2.4.0"
56
57#
58# Public functions
59#
60 51
61# @FUNCTION: font_xfont_config 52# @FUNCTION: font_xfont_config
62# @DESCRIPTION: 53# @DESCRIPTION:
63# Creates the Xfont files. 54# Generate Xorg font files (mkfontscale/mkfontdir).
64font_xfont_config() { 55font_xfont_config() {
65 # create Xfont files 56 if has X ${IUSE//+} && use X ; then
66 if use X ; then
67 einfo "Creating fonts.scale & fonts.dir ..." 57 ebegin "Creating fonts.scale & fonts.dir"
68 rm -f "${D}${FONTDIR}"/fonts.{dir,scale} 58 rm -f "${ED}${FONTDIR}"/fonts.{dir,scale}
69 mkfontscale "${D}${FONTDIR}" 59 mkfontscale "${ED}${FONTDIR}"
70 mkfontdir \ 60 mkfontdir \
71 -e /usr/share/fonts/encodings \ 61 -e ${EPREFIX}/usr/share/fonts/encodings \
72 -e /usr/share/fonts/encodings/large \ 62 -e ${EPREFIX}/usr/share/fonts/encodings/large \
73 "${D}${FONTDIR}" 63 "${ED}${FONTDIR}"
64 eend $?
74 if [ -e "${FONT_S}/fonts.alias" ] ; then 65 if [[ -e ${FONT_S}/fonts.alias ]] ; then
75 doins "${FONT_S}/fonts.alias" 66 doins "${FONT_S}"/fonts.alias
76 fi 67 fi
77 fi 68 fi
78} 69}
79 70
80# @FUNCTION: font_xft_config
81# @DESCRIPTION:
82# Creates the fontconfig cache if necessary.
83font_xft_config() {
84 if ! has_version '>=media-libs/fontconfig-2.4'; then
85 # create fontconfig cache
86 einfo "Creating fontconfig cache ..."
87 fc-cache -sf "${D}${FONTDIR}"
88 fi
89}
90
91# @FUNCTION: font_fontconfig 71# @FUNCTION: font_fontconfig
92# @DESCRIPTION: 72# @DESCRIPTION:
93# Installs the fontconfig config files of FONT_CONF. 73# Install fontconfig conf files given in FONT_CONF.
94font_fontconfig() { 74font_fontconfig() {
95 local conffile 75 local conffile
96 if [[ -n ${FONT_CONF[@]} ]]; then 76 if [[ -n ${FONT_CONF[@]} ]]; then
97 if has_version '>=media-libs/fontconfig-2.4'; then
98 insinto /etc/fonts/conf.avail/ 77 insinto /etc/fonts/conf.avail/
99 for conffile in "${FONT_CONF[@]}"; do 78 for conffile in "${FONT_CONF[@]}"; do
100 [[ -e ${conffile} ]] && doins ${conffile} 79 [[ -e ${conffile} ]] && doins ${conffile}
80 done
81 fi
82}
83
84# @FUNCTION: font_cleanup_dirs
85# @DESCRIPTION:
86# Remove font directories containing only generated files.
87font_cleanup_dirs() {
88 local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
89 # fonts.alias isn't generated but it's a special case (see below).
90 local d f g generated candidate otherfile
91
92 ebegin "Cleaning up font directories"
93 find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
94 candidate=false
95 otherfile=false
96 for f in "${d}"/*; do
97 generated=false
98 # make sure this is a file and not a subdir
99 [[ -e ${f} || -L ${f} ]] || continue
100 for g in ${genfiles}; do
101 if [[ ${f##*/} == ${g} ]]; then
102 # this is a generated file
103 generated=true
104 break
105 fi
101 done 106 done
107 # if the file is a generated file then we know this is a font dir (as
108 # opposed to something like encodings or util) and a candidate for
109 # removal. if it's not generated then it's an "otherfile".
110 ${generated} && candidate=true || otherfile=true
111 # if the directory is both a candidate for removal and contains at
112 # least one "otherfile" then don't remove it.
113 [[ ${candidate} == ${otherfile} ]] && break
114 done
115 # if we only have generated files, purge the directory.
116 if [[ ${candidate} == true && ${otherfile} == false ]]; then
117 # we don't want to remove fonts.alias files that were installed by
118 # media-fonts/font-alias. any other fonts.alias files will have
119 # already been unmerged with their packages.
120 for g in ${genfiles}; do
121 [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] \
122 && rm "${d}"/${g}
123 done
124 # if there's nothing left remove the directory
125 find "${d}" -maxdepth 0 -type d -empty -exec rmdir '{}' \;
102 fi 126 fi
103 fi 127 done
128 eend 0
104} 129}
105
106#
107# Public inheritable functions
108#
109 130
110# @FUNCTION: font_src_install 131# @FUNCTION: font_src_install
111# @DESCRIPTION: 132# @DESCRIPTION:
112# The font src_install function, which is exported. 133# The font src_install function.
113font_src_install() { 134font_src_install() {
114 local suffix commondoc 135 local suffix commondoc
115 136
116 cd "${FONT_S}" 137 pushd "${FONT_S}" > /dev/null
117 138
118 insinto "${FONTDIR}" 139 insinto "${FONTDIR}"
119 140
120 for suffix in ${FONT_SUFFIX}; do 141 for suffix in ${FONT_SUFFIX}; do
121 doins *.${suffix} 142 doins *.${suffix}
122 done 143 done
123 144
124 rm -f fonts.{dir,scale} encodings.dir 145 rm -f fonts.{dir,scale} encodings.dir
125 146
126 font_xfont_config 147 font_xfont_config
127 font_xft_config
128 font_fontconfig 148 font_fontconfig
129 149
130 cd "${S}" 150 popd > /dev/null
131 dodoc ${DOCS} 2> /dev/null 151
152 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
132 153
133 # install common docs 154 # install common docs
134 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do 155 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
135 [[ -s ${commondoc} ]] && dodoc ${commondoc} 156 [[ -s ${commondoc} ]] && dodoc ${commondoc}
136 done 157 done
137} 158}
138 159
139# @FUNCTION: font_pkg_setup 160# @FUNCTION: font_pkg_setup
140# @DESCRIPTION: 161# @DESCRIPTION:
141# The font pkg_setup function, which is exported. 162# The font pkg_setup function.
163# Collision protection and Prefix compat for eapi < 3.
142font_pkg_setup() { 164font_pkg_setup() {
165 # Prefix compat
166 case ${EAPI:-0} in
167 0|1|2)
168 if ! use prefix; then
169 EPREFIX=
170 ED=${D}
171 EROOT=${ROOT}
172 [[ ${EROOT} = */ ]] || EROOT+="/"
173 fi
174 ;;
175 esac
176
143 # make sure we get no collisions 177 # make sure we get no collisions
144 # setup is not the nicest place, but preinst doesn't cut it 178 # setup is not the nicest place, but preinst doesn't cut it
145 [[ -e "${FONTDIR}/fonts.cache-1" ]] && rm -f "${FONTDIR}/fonts.cache-1" 179 [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
146} 180}
147 181
148# @FUNCTION: font_pkg_postinst 182# @FUNCTION: font_pkg_postinst
149# @DESCRIPTION: 183# @DESCRIPTION:
150# The font pkg_postinst function, which is exported. 184# The font pkg_postinst function.
151font_pkg_postinst() { 185font_pkg_postinst() {
152 # unreadable font files = fontconfig segfaults 186 # unreadable font files = fontconfig segfaults
153 find "${ROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \ 187 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
154 | xargs -0 chmod -v 0644 2>/dev/null 188 | xargs -0 chmod -v 0644 2>/dev/null
155 189
156 if [[ -n ${FONT_CONF[@]} ]]; then 190 if [[ -n ${FONT_CONF[@]} ]]; then
157 if has_version '>=media-libs/fontconfig-2.4'; then
158 local conffile 191 local conffile
159 echo 192 echo
160 elog "The following fontconfig configuration files have been installed:" 193 elog "The following fontconfig configuration files have been installed:"
161 elog 194 elog
162 for conffile in "${FONT_CONF[@]}"; do 195 for conffile in "${FONT_CONF[@]}"; do
163 if [[ -e ${ROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then 196 if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
164 elog " $(basename ${conffile})" 197 elog " $(basename ${conffile})"
165 fi 198 fi
166 done 199 done
167 elog 200 elog
168 elog "Use \`eselect fontconfig\` to enable/disable them." 201 elog "Use \`eselect fontconfig\` to enable/disable them."
169 echo 202 echo
170 fi 203 fi
204
205 if [[ ${ROOT} == / ]]; then
206 ebegin "Updating global fontcache"
207 fc-cache -fs
208 eend $?
171 fi 209 fi
210}
211
212# @FUNCTION: font_pkg_postrm
213# @DESCRIPTION:
214# The font pkg_postrm function.
215font_pkg_postrm() {
216 font_cleanup_dirs
172 217
173 if has_version '>=media-libs/fontconfig-2.4'; then
174 if [[ ${ROOT} == "/" ]]; then
175 ebegin "Updating global fontcache"
176 fc-cache -fs
177 eend $?
178 fi
179 fi
180}
181
182# @FUNCTION: font_pkg_postrm
183# @DESCRIPTION:
184# The font pkg_postrm function, which is exported.
185font_pkg_postrm() {
186 # unreadable font files = fontconfig segfaults 218 # unreadable font files = fontconfig segfaults
187 find "${ROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \ 219 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
188 | xargs -0 chmod -v 0644 2>/dev/null 220 | xargs -0 chmod -v 0644 2>/dev/null
189 221
190 if has_version '>=media-libs/fontconfig-2.4'; then
191 if [[ ${ROOT} == "/" ]]; then 222 if [[ ${ROOT} == / ]]; then
192 ebegin "Updating global fontcache" 223 ebegin "Updating global fontcache"
193 fc-cache -fs 224 fc-cache -fs
194 eend $? 225 eend $?
195 fi 226 fi
196 fi
197} 227}

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.51

  ViewVC Help
Powered by ViewVC 1.1.20