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

Contents of /eclass/font.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.49 - (hide annotations) (download)
Tue Apr 20 04:06:59 2010 UTC (4 years, 5 months ago) by dirtyepic
Branch: MAIN
Changes since 1.48: +36 -1 lines
Add new function font_cleanup_dirs, called in pkg_postrm, to clean up font directories that only contain generated files (bug #315369).  Based on code taken from xorg-2.eclass.  Note that due to portage caching pkg_postrm, currently installed font packages will not trigger this code until the second time they are reinstalled.

1 scarabeus 1.48 # Copyright 1999-2010 Gentoo Foundation
2 foser 1.1 # Distributed under the terms of the GNU General Public License v2
3 dirtyepic 1.49 # $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.48 2010/02/09 17:15:08 scarabeus Exp $
4 foser 1.1
5 pva 1.38 # @ECLASS: font.eclass
6     # @MAINTAINER:
7     # fonts@gentoo.org
8 scarabeus 1.48
9     # Author: Tomáš Chvátal <scarabeus@gentoo.org>
10 foser 1.1 # Author: foser <foser@gentoo.org>
11 pva 1.38 # @BLURB: Eclass to make font installation uniform
12 foser 1.1
13 kugelfang 1.7 inherit eutils
14    
15 dirtyepic 1.45 EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
16    
17 pva 1.38 # @ECLASS-VARIABLE: FONT_SUFFIX
18     # @DESCRIPTION:
19     # Space delimited list of font suffixes to install
20 scarabeus 1.48 FONT_SUFFIX=${FONT_SUFFIX:=}
21 pva 1.38
22     # @ECLASS-VARIABLE: FONT_S
23     # @DESCRIPTION:
24     # Dir containing the fonts
25 scarabeus 1.48 FONT_S=${FONT_S:=${S}}
26 pva 1.38
27     # @ECLASS-VARIABLE: FONT_PN
28     # @DESCRIPTION:
29     # Last part of $FONTDIR
30 scarabeus 1.48 FONT_PN=${FONT_PN:=${PN}}
31 pva 1.38
32     # @ECLASS-VARIABLE: FONTDIR
33     # @DESCRIPTION:
34     # This is where the fonts are installed
35 dirtyepic 1.46 FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
36 pva 1.38
37     # @ECLASS-VARIABLE: FONT_CONF
38     # @DESCRIPTION:
39     # Array, which element(s) is(are) path(s) of fontconfig-2.4 file(s) to install
40 maekke 1.43 FONT_CONF=( "" )
41 pva 1.38
42     # @ECLASS-VARIABLE: DOCS
43     # @DESCRIPTION:
44     # Docs to install
45 dirtyepic 1.46 DOCS=${DOCS:-}
46 foser 1.1
47 swegener 1.15 IUSE="X"
48 foser 1.1
49 scarabeus 1.48 DEPEND="X? (
50     x11-apps/mkfontdir
51     media-fonts/encodings
52     )
53     >=media-libs/fontconfig-2.4.0"
54 foser 1.1
55 pva 1.38 # @FUNCTION: font_xfont_config
56     # @DESCRIPTION:
57     # Creates the Xfont files.
58 foser 1.2 font_xfont_config() {
59 foser 1.1 # create Xfont files
60 scarabeus 1.48 if has X ${IUSE//+} && use X ; then
61     ebegin "Creating fonts.scale & fonts.dir"
62     rm -f "${ED}${FONTDIR}"/fonts.{dir,scale}
63     mkfontscale "${ED}${FONTDIR}"
64 foser 1.1 mkfontdir \
65 scarabeus 1.48 -e ${EPREFIX}/usr/share/fonts/encodings \
66     -e ${EPREFIX}/usr/share/fonts/encodings/large \
67     "${ED}${FONTDIR}"
68     eend $?
69 foser 1.11 if [ -e "${FONT_S}/fonts.alias" ] ; then
70 usata 1.8 doins "${FONT_S}/fonts.alias"
71 usata 1.3 fi
72 foser 1.1 fi
73 foser 1.2 }
74    
75 pva 1.38 # @FUNCTION: font_fontconfig
76     # @DESCRIPTION:
77     # Installs the fontconfig config files of FONT_CONF.
78 dirtyepic 1.24 font_fontconfig() {
79     local conffile
80 pva 1.36 if [[ -n ${FONT_CONF[@]} ]]; then
81 scarabeus 1.48 insinto /etc/fonts/conf.avail/
82     for conffile in "${FONT_CONF[@]}"; do
83     [[ -e ${conffile} ]] && doins ${conffile}
84     done
85 dirtyepic 1.24 fi
86     }
87    
88 dirtyepic 1.49 # @FUNCTION: font_cleanup_dirs
89     # @DESCRIPTION:
90     # Remove any font directories only containing generated files.
91     # Runs in pkg_postrm.
92     font_cleanup_dirs() {
93     local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
94     local d f g generated candidate otherfile
95    
96     ebegin "Purging empty font directories"
97     find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
98     candidate=false
99     otherfile=false
100     for f in "${d}"/*; do
101     generated=false
102     [[ -e ${f} || -L ${f} ]] || continue
103     for g in ${genfiles}; do
104     if [[ ${f##*/} == ${g} ]]; then
105     generated=true
106     break
107     fi
108     done
109     ${generated} && candidate=true || otherfile=true
110     [[ ${candidate} == ${otherfile} ]] && break # both are true, keep the dir
111     done
112     if [[ ${candidate} == true && ${otherfile} == false ]]; then
113     ebegin "Removing ${d}"
114     rm -rf "${d}"
115     eend $?
116     fi
117     done
118     eend 0
119     }
120    
121 pva 1.38 # @FUNCTION: font_src_install
122     # @DESCRIPTION:
123 scarabeus 1.48 # The font src_install function.
124 foser 1.2 font_src_install() {
125 dirtyepic 1.23 local suffix commondoc
126 foser 1.2
127 scarabeus 1.48 pushd "${FONT_S}" > /dev/null
128 foser 1.2
129 robbat2 1.18 insinto "${FONTDIR}"
130 swegener 1.15
131 foser 1.2 for suffix in ${FONT_SUFFIX}; do
132 dirtyepic 1.28 doins *.${suffix}
133 foser 1.2 done
134    
135     rm -f fonts.{dir,scale} encodings.dir
136    
137     font_xfont_config
138 dirtyepic 1.24 font_fontconfig
139 foser 1.2
140 scarabeus 1.48 popd > /dev/null
141    
142     [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
143 foser 1.11
144 dirtyepic 1.23 # install common docs
145 dirtyepic 1.37 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
146 dirtyepic 1.24 [[ -s ${commondoc} ]] && dodoc ${commondoc}
147 dirtyepic 1.23 done
148 foser 1.1 }
149    
150 pva 1.38 # @FUNCTION: font_pkg_setup
151     # @DESCRIPTION:
152 scarabeus 1.48 # The font pkg_setup function.
153     # Collision portection and Prefix compat for eapi < 3.
154 foser 1.12 font_pkg_setup() {
155 scarabeus 1.48 # Prefix compat
156     case ${EAPI:-0} in
157     0|1|2)
158     if ! use prefix; then
159     EPREFIX=
160     ED=${D}
161     EROOT=${ROOT}
162     [[ ${EROOT} = */ ]] || EROOT+="/"
163     fi
164     ;;
165     esac
166    
167 dirtyepic 1.24 # make sure we get no collisions
168 foser 1.12 # setup is not the nicest place, but preinst doesn't cut it
169 scarabeus 1.48 [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
170 foser 1.19 }
171    
172 pva 1.38 # @FUNCTION: font_pkg_postinst
173     # @DESCRIPTION:
174 scarabeus 1.48 # The font pkg_postinst function.
175     # Update global font cache and fix permissions.
176 foser 1.19 font_pkg_postinst() {
177 dirtyepic 1.31 # unreadable font files = fontconfig segfaults
178 scarabeus 1.48 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
179 dirtyepic 1.33 | xargs -0 chmod -v 0644 2>/dev/null
180 dirtyepic 1.30
181 dirtyepic 1.45 if [[ -n ${FONT_CONF[@]} ]]; then
182 scarabeus 1.48 local conffile
183     echo
184     elog "The following fontconfig configuration files have been installed:"
185     elog
186     for conffile in "${FONT_CONF[@]}"; do
187     if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
188     elog " $(basename ${conffile})"
189     fi
190     done
191     elog
192     elog "Use \`eselect fontconfig\` to enable/disable them."
193     echo
194     fi
195    
196     if [[ ${ROOT} == / ]]; then
197     ebegin "Updating global fontcache"
198     fc-cache -fs
199     eend $?
200 foser 1.19 fi
201     }
202    
203 pva 1.38 # @FUNCTION: font_pkg_postrm
204     # @DESCRIPTION:
205 scarabeus 1.48 # The font pkg_postrm function.
206     # Updates global font cache
207 foser 1.19 font_pkg_postrm() {
208 dirtyepic 1.49 font_cleanup_dirs
209    
210 dirtyepic 1.31 # unreadable font files = fontconfig segfaults
211 scarabeus 1.48 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
212 dirtyepic 1.33 | xargs -0 chmod -v 0644 2>/dev/null
213 dirtyepic 1.30
214 scarabeus 1.48 if [[ ${ROOT} == / ]]; then
215     ebegin "Updating global fontcache"
216     fc-cache -fs
217     eend $?
218 foser 1.19 fi
219 foser 1.12 }

  ViewVC Help
Powered by ViewVC 1.1.20