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

Contents of /eclass/font.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.58 - (hide annotations) (download)
Sat Feb 21 07:20:22 2015 UTC (5 months, 1 week ago) by yngwin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.57: +34 -23 lines
Apply patch from Ryan Hill to font.eclass to support multiple FONT_S directories (bug #338634)

1 yngwin 1.58 # Copyright 1999-2015 Gentoo Foundation
2 foser 1.1 # Distributed under the terms of the GNU General Public License v2
3 yngwin 1.58 # $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.57 2013/07/25 13:13:18 pva Exp $
4 foser 1.1
5 pva 1.38 # @ECLASS: font.eclass
6     # @MAINTAINER:
7 vapier 1.53 # 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 dirtyepic 1.52 # @DEFAULT_UNSET
16     # @REQUIRED
17 pva 1.38 # @DESCRIPTION:
18 dirtyepic 1.50 # Space delimited list of font suffixes to install.
19 dirtyepic 1.52 FONT_SUFFIX=${FONT_SUFFIX:-}
20 pva 1.38
21     # @ECLASS-VARIABLE: FONT_S
22 dirtyepic 1.52 # @REQUIRED
23 pva 1.38 # @DESCRIPTION:
24 yngwin 1.58 # Space delimited list of directories containing the fonts.
25 dirtyepic 1.52 FONT_S=${FONT_S:-${S}}
26 pva 1.38
27     # @ECLASS-VARIABLE: FONT_PN
28     # @DESCRIPTION:
29 dirtyepic 1.50 # Font name (ie. last part of FONTDIR).
30 dirtyepic 1.52 FONT_PN=${FONT_PN:-${PN}}
31 pva 1.38
32     # @ECLASS-VARIABLE: FONTDIR
33     # @DESCRIPTION:
34 dirtyepic 1.50 # Full path to installation directory.
35 dirtyepic 1.46 FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
36 pva 1.38
37     # @ECLASS-VARIABLE: FONT_CONF
38 dirtyepic 1.52 # @DEFAULT_UNSET
39 pva 1.38 # @DESCRIPTION:
40 dirtyepic 1.50 # Array containing fontconfig conf files to install.
41 maekke 1.43 FONT_CONF=( "" )
42 pva 1.38
43     # @ECLASS-VARIABLE: DOCS
44 dirtyepic 1.52 # @DEFAULT_UNSET
45 pva 1.38 # @DESCRIPTION:
46 dirtyepic 1.50 # Space delimited list of docs to install.
47 vapier 1.53 # We always install these:
48 dirtyepic 1.52 # COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt
49 dirtyepic 1.46 DOCS=${DOCS:-}
50 foser 1.1
51 swegener 1.15 IUSE="X"
52 foser 1.1
53 scarabeus 1.48 DEPEND="X? (
54     x11-apps/mkfontdir
55     media-fonts/encodings
56 pva 1.57 )"
57 lu_zero 1.56 RDEPEND=""
58 foser 1.1
59 pva 1.38 # @FUNCTION: font_xfont_config
60     # @DESCRIPTION:
61 dirtyepic 1.50 # Generate Xorg font files (mkfontscale/mkfontdir).
62 foser 1.2 font_xfont_config() {
63 yngwin 1.58 local dir_name
64 scarabeus 1.48 if has X ${IUSE//+} && use X ; then
65 yngwin 1.58 dir_name="${1:-${FONT_PN}}"
66     ebegin "Creating fonts.scale & fonts.dir in ${dir_name##*/}"
67     rm -f "${ED}${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir}
68     mkfontscale "${ED}${FONTDIR}/${1//${S}/}"
69 foser 1.1 mkfontdir \
70 scarabeus 1.48 -e ${EPREFIX}/usr/share/fonts/encodings \
71     -e ${EPREFIX}/usr/share/fonts/encodings/large \
72 yngwin 1.58 "${ED}${FONTDIR}/${1//${S}/}"
73 scarabeus 1.48 eend $?
74 yngwin 1.58 if [[ -e fonts.alias ]] ; then
75     doins fonts.alias
76 usata 1.3 fi
77 foser 1.1 fi
78 foser 1.2 }
79    
80 pva 1.38 # @FUNCTION: font_fontconfig
81     # @DESCRIPTION:
82 dirtyepic 1.50 # Install fontconfig conf files given in FONT_CONF.
83 dirtyepic 1.24 font_fontconfig() {
84     local conffile
85 pva 1.36 if [[ -n ${FONT_CONF[@]} ]]; then
86 scarabeus 1.48 insinto /etc/fonts/conf.avail/
87     for conffile in "${FONT_CONF[@]}"; do
88     [[ -e ${conffile} ]] && doins ${conffile}
89     done
90 dirtyepic 1.24 fi
91     }
92    
93 dirtyepic 1.49 # @FUNCTION: font_cleanup_dirs
94     # @DESCRIPTION:
95 dirtyepic 1.50 # Remove font directories containing only generated files.
96 dirtyepic 1.49 font_cleanup_dirs() {
97     local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
98 dirtyepic 1.51 # fonts.alias isn't generated but it's a special case (see below).
99 dirtyepic 1.49 local d f g generated candidate otherfile
100    
101 dirtyepic 1.51 ebegin "Cleaning up font directories"
102 dirtyepic 1.49 find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
103     candidate=false
104     otherfile=false
105     for f in "${d}"/*; do
106     generated=false
107 dirtyepic 1.51 # make sure this is a file and not a subdir
108 dirtyepic 1.49 [[ -e ${f} || -L ${f} ]] || continue
109     for g in ${genfiles}; do
110     if [[ ${f##*/} == ${g} ]]; then
111 dirtyepic 1.51 # this is a generated file
112 dirtyepic 1.49 generated=true
113     break
114     fi
115     done
116 dirtyepic 1.51 # if the file is a generated file then we know this is a font dir (as
117 dirtyepic 1.52 # opposed to something like encodings or util) and a candidate for
118 dirtyepic 1.51 # removal. if it's not generated then it's an "otherfile".
119 dirtyepic 1.49 ${generated} && candidate=true || otherfile=true
120 dirtyepic 1.51 # if the directory is both a candidate for removal and contains at
121     # least one "otherfile" then don't remove it.
122     [[ ${candidate} == ${otherfile} ]] && break
123 dirtyepic 1.49 done
124 dirtyepic 1.52 # if in the end we only have generated files, purge the directory.
125 dirtyepic 1.49 if [[ ${candidate} == true && ${otherfile} == false ]]; then
126 dirtyepic 1.51 # we don't want to remove fonts.alias files that were installed by
127     # media-fonts/font-alias. any other fonts.alias files will have
128     # already been unmerged with their packages.
129     for g in ${genfiles}; do
130     [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] \
131     && rm "${d}"/${g}
132     done
133     # if there's nothing left remove the directory
134     find "${d}" -maxdepth 0 -type d -empty -exec rmdir '{}' \;
135 dirtyepic 1.49 fi
136     done
137     eend 0
138     }
139    
140 dirtyepic 1.52 # @FUNCTION: font_pkg_setup
141     # @DESCRIPTION:
142     # The font pkg_setup function.
143     # Collision protection and Prefix compat for eapi < 3.
144     font_pkg_setup() {
145     # Prefix compat
146     case ${EAPI:-0} in
147     0|1|2)
148     if ! use prefix; then
149     EPREFIX=
150     ED=${D}
151     EROOT=${ROOT}
152     [[ ${EROOT} = */ ]] || EROOT+="/"
153     fi
154     ;;
155     esac
156    
157     # make sure we get no collisions
158     # setup is not the nicest place, but preinst doesn't cut it
159     [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
160     }
161    
162 pva 1.38 # @FUNCTION: font_src_install
163     # @DESCRIPTION:
164 scarabeus 1.48 # The font src_install function.
165 foser 1.2 font_src_install() {
166 yngwin 1.58 local dir suffix commondoc
167 foser 1.2
168 yngwin 1.58 set -- ${FONT_S:-${S}}
169     if [[ $# -gt 1 ]]; then
170     # if we have multiple FONT_S elements then we want to recreate the dir
171     # structure
172     for dir in ${FONT_S}; do
173     pushd "${dir}" > /dev/null
174     insinto "${FONTDIR}/${dir//${S}/}"
175     for suffix in ${FONT_SUFFIX}; do
176     doins *.${suffix}
177     done
178     font_xfont_config "${dir}"
179     popd > /dev/null
180     done
181     else
182     pushd "${FONT_S}" > /dev/null
183     insinto "${FONTDIR}"
184     for suffix in ${FONT_SUFFIX}; do
185     doins *.${suffix}
186     done
187     font_xfont_config
188     popd > /dev/null
189     fi
190 foser 1.2
191 dirtyepic 1.24 font_fontconfig
192 foser 1.2
193 scarabeus 1.48 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
194 foser 1.11
195 dirtyepic 1.23 # install common docs
196 dirtyepic 1.37 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
197 dirtyepic 1.24 [[ -s ${commondoc} ]] && dodoc ${commondoc}
198 dirtyepic 1.23 done
199 foser 1.1 }
200    
201 pva 1.38 # @FUNCTION: font_pkg_postinst
202     # @DESCRIPTION:
203 scarabeus 1.48 # The font pkg_postinst function.
204 foser 1.19 font_pkg_postinst() {
205 dirtyepic 1.31 # unreadable font files = fontconfig segfaults
206 scarabeus 1.48 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
207 dirtyepic 1.33 | xargs -0 chmod -v 0644 2>/dev/null
208 dirtyepic 1.30
209 dirtyepic 1.45 if [[ -n ${FONT_CONF[@]} ]]; then
210 scarabeus 1.48 local conffile
211     echo
212     elog "The following fontconfig configuration files have been installed:"
213     elog
214     for conffile in "${FONT_CONF[@]}"; do
215     if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
216     elog " $(basename ${conffile})"
217     fi
218     done
219     elog
220     elog "Use \`eselect fontconfig\` to enable/disable them."
221     echo
222     fi
223    
224 lu_zero 1.56 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
225 scarabeus 1.48 ebegin "Updating global fontcache"
226     fc-cache -fs
227     eend $?
228 pva 1.57 else
229     einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
230 foser 1.19 fi
231     }
232    
233 pva 1.38 # @FUNCTION: font_pkg_postrm
234     # @DESCRIPTION:
235 scarabeus 1.48 # The font pkg_postrm function.
236 foser 1.19 font_pkg_postrm() {
237 dirtyepic 1.49 font_cleanup_dirs
238 vapier 1.54
239 dirtyepic 1.31 # unreadable font files = fontconfig segfaults
240 scarabeus 1.48 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
241 dirtyepic 1.33 | xargs -0 chmod -v 0644 2>/dev/null
242 dirtyepic 1.30
243 lu_zero 1.56 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
244 scarabeus 1.48 ebegin "Updating global fontcache"
245     fc-cache -fs
246     eend $?
247 pva 1.57 else
248     einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
249 foser 1.19 fi
250 foser 1.12 }

  ViewVC Help
Powered by ViewVC 1.1.20