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

Diff of /eclass/font.eclass

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

Revision 1.2 Revision 1.52
1# Copyright 1999-2004 Gentoo Technologies, Inc. 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.2 2004/05/31 14:59:26 foser Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.52 2010/09/30 03:46:11 dirtyepic 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
11ECLASS="font" 10inherit eutils
12INHERITED="$INHERITED $ECLASS"
13 11
14# 12EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
15# Variable declarations
16#
17 13
14# @ECLASS-VARIABLE: FONT_SUFFIX
15# @DEFAULT_UNSET
16# @REQUIRED
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}}
23 32
24IUSE="${IUSE} X" 33# @ECLASS-VARIABLE: FONTDIR
34# @DESCRIPTION:
35# Full path to installation directory.
36FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
25 37
26DEPEND="${DEPEND} \ 38# @ECLASS-VARIABLE: FONT_CONF
27 X? ( virtual/x11 ) \ 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:-}
51
52IUSE="X"
53
54DEPEND="X? (
55 x11-apps/mkfontdir
56 media-fonts/encodings
57 )
28 media-libs/fontconfig" 58 >=media-libs/fontconfig-2.4.0"
29 59
30# 60# @FUNCTION: font_xfont_config
31# Public functions 61# @DESCRIPTION:
32# 62# Generate Xorg font files (mkfontscale/mkfontdir).
33
34font_xfont_config() { 63font_xfont_config() {
35 64 if has X ${IUSE//+} && use X ; then
36 # create Xfont files
37 if [ -n "`use X`" ] ;
38 then
39 einfo "Creating fonts.scale & fonts.dir..." 65 ebegin "Creating fonts.scale & fonts.dir"
40 mkfontscale ${D}/usr/share/fonts/${PN} 66 rm -f "${ED}${FONTDIR}"/fonts.{dir,scale}
67 mkfontscale "${ED}${FONTDIR}"
41 mkfontdir \ 68 mkfontdir \
42 -e /usr/share/fonts/encodings \ 69 -e ${EPREFIX}/usr/share/fonts/encodings \
43 -e /usr/share/fonts/encodings/large \ 70 -e ${EPREFIX}/usr/share/fonts/encodings/large \
44 -e /usr/X11R6/lib/X11/fonts/encodings \ 71 "${ED}${FONTDIR}"
45 ${D}/usr/share/fonts/${PN} 72 eend $?
73 if [[ -e ${FONT_S}/fonts.alias ]] ; then
46 doins ${FONT_S}/fonts.alias 74 doins "${FONT_S}"/fonts.alias
47 fi 75 fi
48 76 fi
49} 77}
50 78
79# @FUNCTION: font_fontconfig
80# @DESCRIPTION:
81# Install fontconfig conf files given in FONT_CONF.
51font_xft_config() { 82font_fontconfig() {
52 83 local conffile
53 # create fontconfig cache 84 if [[ -n ${FONT_CONF[@]} ]]; then
54 einfo "Creating fontconfig cache..." 85 insinto /etc/fonts/conf.avail/
55 HOME="/root" /usr/bin/fc-cache -f ${D}/usr/share/fonts/${PN} 86 for conffile in "${FONT_CONF[@]}"; do
56 87 [[ -e ${conffile} ]] && doins ${conffile}
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() {
64
65 local suffix doc 165 local suffix commondoc
66 166
67 cd ${FONT_S} 167 pushd "${FONT_S}" > /dev/null
68 168
69 insinto /usr/share/fonts/${PN} 169 insinto "${FONTDIR}"
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 for doc in ${DOCS}; do 186 [[ -s ${commondoc} ]] && dodoc ${commondoc}
84 dodoc ${doc}
85 done 187 done
86
87} 188}
88 189
89EXPORT_FUNCTIONS src_install 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 [[ ${ROOT} == / ]]; then
214 ebegin "Updating global fontcache"
215 fc-cache -fs
216 eend $?
217 fi
218}
219
220# @FUNCTION: font_pkg_postrm
221# @DESCRIPTION:
222# The font pkg_postrm function.
223font_pkg_postrm() {
224 font_cleanup_dirs
225
226 # unreadable font files = fontconfig segfaults
227 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
228 | xargs -0 chmod -v 0644 2>/dev/null
229
230 if [[ ${ROOT} == / ]]; then
231 ebegin "Updating global fontcache"
232 fc-cache -fs
233 eend $?
234 fi
235}

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.52

  ViewVC Help
Powered by ViewVC 1.1.20