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

Contents of /eclass/font.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.51 - (hide annotations) (download)
Fri Jul 9 03:44:19 2010 UTC (3 years, 9 months ago) by dirtyepic
Branch: MAIN
Changes since 1.50: +21 -6 lines
When cleaning up generated files leave any fonts.alias from media-fonts/font-alias alone.  Add documentation. (bug #315369)

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.51 # $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.50 2010/05/15 05:25:32 dirtyepic Exp $
4 foser 1.1
5 pva 1.38 # @ECLASS: font.eclass
6     # @MAINTAINER:
7 dirtyepic 1.50 # fonts@gentoo.org
8 pva 1.38 # @BLURB: Eclass to make font installation uniform
9 foser 1.1
10 kugelfang 1.7 inherit eutils
11    
12 dirtyepic 1.45 EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
13    
14 pva 1.38 # @ECLASS-VARIABLE: FONT_SUFFIX
15     # @DESCRIPTION:
16 dirtyepic 1.50 # Space delimited list of font suffixes to install.
17 scarabeus 1.48 FONT_SUFFIX=${FONT_SUFFIX:=}
18 pva 1.38
19     # @ECLASS-VARIABLE: FONT_S
20     # @DESCRIPTION:
21 dirtyepic 1.50 # Working directory containing the fonts.
22 scarabeus 1.48 FONT_S=${FONT_S:=${S}}
23 pva 1.38
24     # @ECLASS-VARIABLE: FONT_PN
25     # @DESCRIPTION:
26 dirtyepic 1.50 # Font name (ie. last part of FONTDIR).
27 scarabeus 1.48 FONT_PN=${FONT_PN:=${PN}}
28 pva 1.38
29     # @ECLASS-VARIABLE: FONTDIR
30     # @DESCRIPTION:
31 dirtyepic 1.50 # Full path to installation directory.
32 dirtyepic 1.46 FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
33 pva 1.38
34     # @ECLASS-VARIABLE: FONT_CONF
35     # @DESCRIPTION:
36 dirtyepic 1.50 # Array containing fontconfig conf files to install.
37 maekke 1.43 FONT_CONF=( "" )
38 pva 1.38
39     # @ECLASS-VARIABLE: DOCS
40     # @DESCRIPTION:
41 dirtyepic 1.50 # Space delimited list of docs to install.
42 dirtyepic 1.46 DOCS=${DOCS:-}
43 foser 1.1
44 swegener 1.15 IUSE="X"
45 foser 1.1
46 scarabeus 1.48 DEPEND="X? (
47     x11-apps/mkfontdir
48     media-fonts/encodings
49     )
50     >=media-libs/fontconfig-2.4.0"
51 foser 1.1
52 pva 1.38 # @FUNCTION: font_xfont_config
53     # @DESCRIPTION:
54 dirtyepic 1.50 # Generate Xorg font files (mkfontscale/mkfontdir).
55 foser 1.2 font_xfont_config() {
56 scarabeus 1.48 if has X ${IUSE//+} && use X ; then
57     ebegin "Creating fonts.scale & fonts.dir"
58     rm -f "${ED}${FONTDIR}"/fonts.{dir,scale}
59     mkfontscale "${ED}${FONTDIR}"
60 foser 1.1 mkfontdir \
61 scarabeus 1.48 -e ${EPREFIX}/usr/share/fonts/encodings \
62     -e ${EPREFIX}/usr/share/fonts/encodings/large \
63     "${ED}${FONTDIR}"
64     eend $?
65 dirtyepic 1.50 if [[ -e ${FONT_S}/fonts.alias ]] ; then
66     doins "${FONT_S}"/fonts.alias
67 usata 1.3 fi
68 foser 1.1 fi
69 foser 1.2 }
70    
71 pva 1.38 # @FUNCTION: font_fontconfig
72     # @DESCRIPTION:
73 dirtyepic 1.50 # Install fontconfig conf files given in FONT_CONF.
74 dirtyepic 1.24 font_fontconfig() {
75     local conffile
76 pva 1.36 if [[ -n ${FONT_CONF[@]} ]]; then
77 scarabeus 1.48 insinto /etc/fonts/conf.avail/
78     for conffile in "${FONT_CONF[@]}"; do
79     [[ -e ${conffile} ]] && doins ${conffile}
80     done
81 dirtyepic 1.24 fi
82     }
83    
84 dirtyepic 1.49 # @FUNCTION: font_cleanup_dirs
85     # @DESCRIPTION:
86 dirtyepic 1.50 # Remove font directories containing only generated files.
87 dirtyepic 1.49 font_cleanup_dirs() {
88     local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
89 dirtyepic 1.51 # fonts.alias isn't generated but it's a special case (see below).
90 dirtyepic 1.49 local d f g generated candidate otherfile
91    
92 dirtyepic 1.51 ebegin "Cleaning up font directories"
93 dirtyepic 1.49 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 dirtyepic 1.51 # make sure this is a file and not a subdir
99 dirtyepic 1.49 [[ -e ${f} || -L ${f} ]] || continue
100     for g in ${genfiles}; do
101     if [[ ${f##*/} == ${g} ]]; then
102 dirtyepic 1.51 # this is a generated file
103 dirtyepic 1.49 generated=true
104     break
105     fi
106     done
107 dirtyepic 1.51 # 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 dirtyepic 1.49 ${generated} && candidate=true || otherfile=true
111 dirtyepic 1.51 # 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 dirtyepic 1.49 done
115 dirtyepic 1.51 # if we only have generated files, purge the directory.
116 dirtyepic 1.49 if [[ ${candidate} == true && ${otherfile} == false ]]; then
117 dirtyepic 1.51 # 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 '{}' \;
126 dirtyepic 1.49 fi
127     done
128     eend 0
129     }
130    
131 pva 1.38 # @FUNCTION: font_src_install
132     # @DESCRIPTION:
133 scarabeus 1.48 # The font src_install function.
134 foser 1.2 font_src_install() {
135 dirtyepic 1.23 local suffix commondoc
136 foser 1.2
137 scarabeus 1.48 pushd "${FONT_S}" > /dev/null
138 foser 1.2
139 robbat2 1.18 insinto "${FONTDIR}"
140 swegener 1.15
141 foser 1.2 for suffix in ${FONT_SUFFIX}; do
142 dirtyepic 1.28 doins *.${suffix}
143 foser 1.2 done
144    
145     rm -f fonts.{dir,scale} encodings.dir
146    
147     font_xfont_config
148 dirtyepic 1.24 font_fontconfig
149 foser 1.2
150 scarabeus 1.48 popd > /dev/null
151    
152     [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
153 foser 1.11
154 dirtyepic 1.23 # install common docs
155 dirtyepic 1.37 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
156 dirtyepic 1.24 [[ -s ${commondoc} ]] && dodoc ${commondoc}
157 dirtyepic 1.23 done
158 foser 1.1 }
159    
160 pva 1.38 # @FUNCTION: font_pkg_setup
161     # @DESCRIPTION:
162 scarabeus 1.48 # The font pkg_setup function.
163 dirtyepic 1.50 # Collision protection and Prefix compat for eapi < 3.
164 foser 1.12 font_pkg_setup() {
165 scarabeus 1.48 # 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    
177 dirtyepic 1.24 # make sure we get no collisions
178 foser 1.12 # setup is not the nicest place, but preinst doesn't cut it
179 scarabeus 1.48 [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
180 foser 1.19 }
181    
182 pva 1.38 # @FUNCTION: font_pkg_postinst
183     # @DESCRIPTION:
184 scarabeus 1.48 # The font pkg_postinst function.
185 foser 1.19 font_pkg_postinst() {
186 dirtyepic 1.31 # unreadable font files = fontconfig segfaults
187 scarabeus 1.48 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
188 dirtyepic 1.33 | xargs -0 chmod -v 0644 2>/dev/null
189 dirtyepic 1.30
190 dirtyepic 1.45 if [[ -n ${FONT_CONF[@]} ]]; then
191 scarabeus 1.48 local conffile
192     echo
193     elog "The following fontconfig configuration files have been installed:"
194     elog
195     for conffile in "${FONT_CONF[@]}"; do
196     if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
197     elog " $(basename ${conffile})"
198     fi
199     done
200     elog
201     elog "Use \`eselect fontconfig\` to enable/disable them."
202     echo
203     fi
204    
205     if [[ ${ROOT} == / ]]; then
206     ebegin "Updating global fontcache"
207     fc-cache -fs
208     eend $?
209 foser 1.19 fi
210     }
211    
212 pva 1.38 # @FUNCTION: font_pkg_postrm
213     # @DESCRIPTION:
214 scarabeus 1.48 # The font pkg_postrm function.
215 foser 1.19 font_pkg_postrm() {
216 dirtyepic 1.49 font_cleanup_dirs
217    
218 dirtyepic 1.31 # unreadable font files = fontconfig segfaults
219 scarabeus 1.48 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
220 dirtyepic 1.33 | xargs -0 chmod -v 0644 2>/dev/null
221 dirtyepic 1.30
222 scarabeus 1.48 if [[ ${ROOT} == / ]]; then
223     ebegin "Updating global fontcache"
224     fc-cache -fs
225     eend $?
226 foser 1.19 fi
227 foser 1.12 }

  ViewVC Help
Powered by ViewVC 1.1.20