/[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.49
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.49 2010/04/20 04:06:59 dirtyepic Exp $
4 4
5# @ECLASS: font.eclass
6# @MAINTAINER:
7# fonts@gentoo.org
8
9# Author: Tomáš Chvátal <scarabeus@gentoo.org>
5# Author: foser <foser@gentoo.org> 10# Author: foser <foser@gentoo.org>
6
7# Font Eclass
8#
9# Eclass to make font installation more uniform 11# @BLURB: Eclass to make font installation uniform
10 12
11ECLASS="font" 13inherit eutils
12INHERITED="$INHERITED $ECLASS"
13 14
14# 15EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
15# Variable declarations
16#
17 16
17# @ECLASS-VARIABLE: FONT_SUFFIX
18# @DESCRIPTION:
18FONT_SUFFIX="" # Space delimited list of font suffixes to install 19# Space delimited list of font suffixes to install
20FONT_SUFFIX=${FONT_SUFFIX:=}
19 21
22# @ECLASS-VARIABLE: FONT_S
23# @DESCRIPTION:
20FONT_S="${S}" # Dir containing the fonts 24# Dir containing the fonts
25FONT_S=${FONT_S:=${S}}
21 26
27# @ECLASS-VARIABLE: FONT_PN
28# @DESCRIPTION:
29# Last part of $FONTDIR
30FONT_PN=${FONT_PN:=${PN}}
31
32# @ECLASS-VARIABLE: FONTDIR
33# @DESCRIPTION:
34# This is where the fonts are installed
35FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
36
37# @ECLASS-VARIABLE: FONT_CONF
38# @DESCRIPTION:
39# Array, which element(s) is(are) path(s) of fontconfig-2.4 file(s) to install
40FONT_CONF=( "" )
41
42# @ECLASS-VARIABLE: DOCS
43# @DESCRIPTION:
22DOCS="" # Docs to install 44# Docs to install
45DOCS=${DOCS:-}
23 46
24IUSE="${IUSE} X" 47IUSE="X"
25 48
26DEPEND="${DEPEND} \ 49DEPEND="X? (
27 X? ( virtual/x11 ) \ 50 x11-apps/mkfontdir
51 media-fonts/encodings
52 )
28 media-libs/fontconfig" 53 >=media-libs/fontconfig-2.4.0"
29 54
30# 55# @FUNCTION: font_xfont_config
31# Public functions 56# @DESCRIPTION:
32# 57# Creates the Xfont files.
33
34font_xfont_config() { 58font_xfont_config() {
35
36 # create Xfont files 59 # create Xfont files
37 if [ -n "`use X`" ] ; 60 if has X ${IUSE//+} && use X ; then
38 then
39 einfo "Creating fonts.scale & fonts.dir..." 61 ebegin "Creating fonts.scale & fonts.dir"
40 mkfontscale ${D}/usr/share/fonts/${PN} 62 rm -f "${ED}${FONTDIR}"/fonts.{dir,scale}
63 mkfontscale "${ED}${FONTDIR}"
41 mkfontdir \ 64 mkfontdir \
42 -e /usr/share/fonts/encodings \ 65 -e ${EPREFIX}/usr/share/fonts/encodings \
43 -e /usr/share/fonts/encodings/large \ 66 -e ${EPREFIX}/usr/share/fonts/encodings/large \
44 -e /usr/X11R6/lib/X11/fonts/encodings \ 67 "${ED}${FONTDIR}"
45 ${D}/usr/share/fonts/${PN} 68 eend $?
69 if [ -e "${FONT_S}/fonts.alias" ] ; then
46 doins ${FONT_S}/fonts.alias 70 doins "${FONT_S}/fonts.alias"
47 fi 71 fi
48 72 fi
49} 73}
50 74
75# @FUNCTION: font_fontconfig
76# @DESCRIPTION:
77# Installs the fontconfig config files of FONT_CONF.
51font_xft_config() { 78font_fontconfig() {
52 79 local conffile
53 # create fontconfig cache 80 if [[ -n ${FONT_CONF[@]} ]]; then
54 einfo "Creating fontconfig cache..." 81 insinto /etc/fonts/conf.avail/
55 HOME="/root" /usr/bin/fc-cache -f ${D}/usr/share/fonts/${PN} 82 for conffile in "${FONT_CONF[@]}"; do
56 83 [[ -e ${conffile} ]] && doins ${conffile}
84 done
85 fi
57} 86}
58 87
59# 88# @FUNCTION: font_cleanup_dirs
60# Public inheritable functions 89# @DESCRIPTION:
61# 90# Remove any font directories only containing generated files.
91# Runs in pkg_postrm.
92font_cleanup_dirs() {
93 local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
94 local d f g generated candidate otherfile
62 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# @FUNCTION: font_src_install
122# @DESCRIPTION:
123# The font src_install function.
63font_src_install() { 124font_src_install() {
64
65 local suffix doc 125 local suffix commondoc
66 126
67 cd ${FONT_S} 127 pushd "${FONT_S}" > /dev/null
68 128
69 insinto /usr/share/fonts/${PN} 129 insinto "${FONTDIR}"
70 130
71 for suffix in ${FONT_SUFFIX}; do 131 for suffix in ${FONT_SUFFIX}; do
72 doins *.${suffix} 132 doins *.${suffix}
73 done 133 done
74 134
75 rm -f fonts.{dir,scale} encodings.dir 135 rm -f fonts.{dir,scale} encodings.dir
76 136
77 font_xfont_config 137 font_xfont_config
78 font_xft_config 138 font_fontconfig
79 139
80 cd ${S} 140 popd > /dev/null
141
142 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
143
81 # try to install some common docs 144 # install common docs
82 DOCS="${DOCS} COPYRIGHT README NEWS" 145 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
83 for doc in ${DOCS}; do 146 [[ -s ${commondoc} ]] && dodoc ${commondoc}
84 dodoc ${doc}
85 done 147 done
86
87} 148}
88 149
89EXPORT_FUNCTIONS src_install 150# @FUNCTION: font_pkg_setup
151# @DESCRIPTION:
152# The font pkg_setup function.
153# Collision portection and Prefix compat for eapi < 3.
154font_pkg_setup() {
155 # 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 # make sure we get no collisions
168 # setup is not the nicest place, but preinst doesn't cut it
169 [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
170}
171
172# @FUNCTION: font_pkg_postinst
173# @DESCRIPTION:
174# The font pkg_postinst function.
175# Update global font cache and fix permissions.
176font_pkg_postinst() {
177 # unreadable font files = fontconfig segfaults
178 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
179 | xargs -0 chmod -v 0644 2>/dev/null
180
181 if [[ -n ${FONT_CONF[@]} ]]; then
182 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 fi
201}
202
203# @FUNCTION: font_pkg_postrm
204# @DESCRIPTION:
205# The font pkg_postrm function.
206# Updates global font cache
207font_pkg_postrm() {
208 font_cleanup_dirs
209
210 # unreadable font files = fontconfig segfaults
211 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
212 | xargs -0 chmod -v 0644 2>/dev/null
213
214 if [[ ${ROOT} == / ]]; then
215 ebegin "Updating global fontcache"
216 fc-cache -fs
217 eend $?
218 fi
219}

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

  ViewVC Help
Powered by ViewVC 1.1.20