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

Diff of /eclass/font.eclass

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

Revision 1.1.1.1 Revision 1.58
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2015 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.1.1.1 2005/11/30 09:59:23 chriswhite Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/font.eclass,v 1.58 2015/02/21 07:20:22 yngwin 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
11inherit eutils 10inherit eutils
12 11
12EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
13 13
14# 14# @ECLASS-VARIABLE: FONT_SUFFIX
15# Variable declarations 15# @DEFAULT_UNSET
16# 16# @REQUIRED
17 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# @REQUIRED
23# @DESCRIPTION:
24# Space delimited list of directories containing the fonts.
25FONT_S=${FONT_S:-${S}}
21 26
22DOCS="" # Docs to install 27# @ECLASS-VARIABLE: FONT_PN
28# @DESCRIPTION:
29# Font name (ie. last part of FONTDIR).
30FONT_PN=${FONT_PN:-${PN}}
31
32# @ECLASS-VARIABLE: FONTDIR
33# @DESCRIPTION:
34# Full path to installation directory.
35FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
36
37# @ECLASS-VARIABLE: FONT_CONF
38# @DEFAULT_UNSET
39# @DESCRIPTION:
40# Array containing fontconfig conf files to install.
41FONT_CONF=( "" )
42
43# @ECLASS-VARIABLE: DOCS
44# @DEFAULT_UNSET
45# @DESCRIPTION:
46# Space delimited list of docs to install.
47# We always install these:
48# COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt
49DOCS=${DOCS:-}
23 50
24IUSE="X" 51IUSE="X"
25 52
26DEPEND="X? ( virtual/x11 ) 53DEPEND="X? (
27 media-libs/fontconfig" 54 x11-apps/mkfontdir
55 media-fonts/encodings
56 )"
57RDEPEND=""
28 58
29# 59# @FUNCTION: font_xfont_config
30# Public functions 60# @DESCRIPTION:
31# 61# Generate Xorg font files (mkfontscale/mkfontdir).
32
33font_xfont_config() { 62font_xfont_config() {
34 63 local dir_name
35 # create Xfont files 64 if has X ${IUSE//+} && use X ; then
36 if use X ; then 65 dir_name="${1:-${FONT_PN}}"
37 einfo "Creating fonts.scale & fonts.dir ..." 66 ebegin "Creating fonts.scale & fonts.dir in ${dir_name##*/}"
38 mkfontscale "${D}/usr/share/fonts/${PN}" 67 rm -f "${ED}${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir}
68 mkfontscale "${ED}${FONTDIR}/${1//${S}/}"
39 mkfontdir \ 69 mkfontdir \
40 -e /usr/share/fonts/encodings \ 70 -e ${EPREFIX}/usr/share/fonts/encodings \
41 -e /usr/share/fonts/encodings/large \ 71 -e ${EPREFIX}/usr/share/fonts/encodings/large \
42 "${D}/usr/share/fonts/${PN}" 72 "${ED}${FONTDIR}/${1//${S}/}"
73 eend $?
43 if [ -e "${FONT_S}/fonts.alias" ] ; then 74 if [[ -e fonts.alias ]] ; then
44 doins "${FONT_S}/fonts.alias" 75 doins fonts.alias
45 fi 76 fi
46 fi 77 fi
47
48} 78}
49 79
80# @FUNCTION: font_fontconfig
81# @DESCRIPTION:
82# Install fontconfig conf files given in FONT_CONF.
50font_xft_config() { 83font_fontconfig() {
51 84 local conffile
52 # create fontconfig cache 85 if [[ -n ${FONT_CONF[@]} ]]; then
53 einfo "Creating fontconfig cache ..." 86 insinto /etc/fonts/conf.avail/
54 # Mac OS X has fc-cache at /usr/X11R6/bin 87 for conffile in "${FONT_CONF[@]}"; do
55 HOME="/root" fc-cache -f "${D}/usr/share/fonts/${PN}" 88 [[ -e ${conffile} ]] && doins ${conffile}
56 89 done
90 fi
57} 91}
58 92
59# 93# @FUNCTION: font_cleanup_dirs
60# Public inheritable functions 94# @DESCRIPTION:
61# 95# Remove font directories containing only generated files.
96font_cleanup_dirs() {
97 local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
98 # fonts.alias isn't generated but it's a special case (see below).
99 local d f g generated candidate otherfile
62 100
101 ebegin "Cleaning up font directories"
102 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 # make sure this is a file and not a subdir
108 [[ -e ${f} || -L ${f} ]] || continue
109 for g in ${genfiles}; do
110 if [[ ${f##*/} == ${g} ]]; then
111 # this is a generated file
112 generated=true
113 break
114 fi
115 done
116 # if the file is a generated file then we know this is a font dir (as
117 # opposed to something like encodings or util) and a candidate for
118 # removal. if it's not generated then it's an "otherfile".
119 ${generated} && candidate=true || otherfile=true
120 # 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 done
124 # if in the end we only have generated files, purge the directory.
125 if [[ ${candidate} == true && ${otherfile} == false ]]; then
126 # 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 fi
136 done
137 eend 0
138}
139
140# @FUNCTION: font_pkg_setup
141# @DESCRIPTION:
142# The font pkg_setup function.
143# Collision protection and Prefix compat for eapi < 3.
144font_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# @FUNCTION: font_src_install
163# @DESCRIPTION:
164# The font src_install function.
63font_src_install() { 165font_src_install() {
166 local dir suffix commondoc
64 167
65 local suffix 168 set -- ${FONT_S:-${S}}
66 169 if [[ $# -gt 1 ]]; then
67 cd "${FONT_S}" 170 # if we have multiple FONT_S elements then we want to recreate the dir
68 171 # structure
69 insinto "/usr/share/fonts/${PN}" 172 for dir in ${FONT_S}; do
70 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}"
71 for suffix in ${FONT_SUFFIX}; do 184 for suffix in ${FONT_SUFFIX}; do
72 doins *.${suffix} 185 doins *.${suffix}
186 done
187 font_xfont_config
188 popd > /dev/null
189 fi
190
191 font_fontconfig
192
193 [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
194
195 # install common docs
196 for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
197 [[ -s ${commondoc} ]] && dodoc ${commondoc}
73 done 198 done
74
75 rm -f fonts.{dir,scale} encodings.dir
76
77 font_xfont_config
78 font_xft_config
79
80 cd "${S}"
81 # try to install some common docs
82 DOCS="${DOCS} COPYRIGHT README NEWS"
83 dodoc ${DOCS}
84
85} 199}
86 200
201# @FUNCTION: font_pkg_postinst
202# @DESCRIPTION:
203# The font pkg_postinst function.
204font_pkg_postinst() {
205 # unreadable font files = fontconfig segfaults
206 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
207 | xargs -0 chmod -v 0644 2>/dev/null
208
209 if [[ -n ${FONT_CONF[@]} ]]; then
210 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 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
225 ebegin "Updating global fontcache"
226 fc-cache -fs
227 eend $?
228 else
229 einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
230 fi
231}
232
233# @FUNCTION: font_pkg_postrm
234# @DESCRIPTION:
235# The font pkg_postrm function.
87font_pkg_setup() { 236font_pkg_postrm() {
237 font_cleanup_dirs
88 238
89 # make sure we get no colissions 239 # unreadable font files = fontconfig segfaults
90 # setup is not the nicest place, but preinst doesn't cut it 240 find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
91 rm "/usr/share/fonts/${PN}/fonts.cache-1" 241 | xargs -0 chmod -v 0644 2>/dev/null
92 242
243 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
244 ebegin "Updating global fontcache"
245 fc-cache -fs
246 eend $?
247 else
248 einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
249 fi
93} 250}
94
95EXPORT_FUNCTIONS src_install pkg_setup

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.58

  ViewVC Help
Powered by ViewVC 1.1.20