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