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

Diff of /eclass/font.eclass

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

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

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.50

  ViewVC Help
Powered by ViewVC 1.1.20