aboutsummaryrefslogtreecommitdiff
path: root/eclass/font-r1.eclass
diff options
context:
space:
mode:
Diffstat (limited to 'eclass/font-r1.eclass')
-rw-r--r--eclass/font-r1.eclass230
1 files changed, 230 insertions, 0 deletions
diff --git a/eclass/font-r1.eclass b/eclass/font-r1.eclass
new file mode 100644
index 0000000..c11f6b2
--- /dev/null
+++ b/eclass/font-r1.eclass
@@ -0,0 +1,230 @@
1# Copyright 1999-2017 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2
3
4# @ECLASS: font-r1.eclass
5# @MAINTAINER:
6# fonts@gentoo.org
7# @BLURB: Eclass to make font installation uniform
8
9[[ ${EAPI} -lt 6 ]] && inherit eutils
10
11EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
12
13# @ECLASS-VARIABLE: MY_FONT_TYPES
14# @DEFAULT_UNSET
15# @DESCRIPTION:
16# An array of font formats available for install.
17MY_FONT_TYPES=( ${MY_FONT_TYPES[@]:-} )
18MY_FONT_TYPES=( ${MY_FONT_TYPES[@]/#/font_types_} )
19MY_FONT_TYPES=( ${MY_FONT_TYPES[@]/font_types_+/+font_types_} )
20
21# @ECLASS-VARIABLE: MY_FONT_VARIANTS
22# @DEFAULT_UNSET
23# @DESCRIPTION:
24# An array of available font variants.
25MY_FONT_VARIANTS=( ${MY_FONT_VARIANTS[@]:-} )
26MY_FONT_VARIANTS=( ${MY_FONT_VARIANTS[@]/#/font_variants_} )
27MY_FONT_VARIANTS=( ${MY_FONT_VARIANTS[@]/font_variants_+/+font_variants_} )
28
29# @ECLASS-VARIABLE: MY_FONT_CHARS
30# @DEFAULT_UNSET
31# @DESCRIPTION:
32# An array of available character variations.
33MY_FONT_CHARS=( ${MY_FONT_CHARS[@]:-} )
34MY_FONT_CHARS=( ${MY_FONT_CHARS[@]/#/font_chars_} )
35MY_FONT_CHARS=( ${MY_FONT_CHARS[@]/font_chars_+/+font_chars_} )
36
37# @ECLASS-VARIABLE: FONT_SUFFIX
38# @DEFAULT_UNSET
39# @DESCRIPTION:
40# Space delimited list of font suffixes to install.
41FONT_SUFFIX=${FONT_SUFFIX:-}
42
43# @ECLASS-VARIABLE: FONT_S
44# @REQUIRED
45# @DESCRIPTION:
46# An array of directories containing the fonts, ${S} if unset.
47FONT_S=( ${FONT_S[@]:-.} )
48
49# @ECLASS-VARIABLE: FONT_PN
50# @DESCRIPTION:
51# Font name (ie. last part of FONTDIR).
52FONT_PN=${FONT_PN:-${PN}}
53
54# @ECLASS-VARIABLE: FONTDIR
55# @DESCRIPTION:
56# Full path to installation directory.
57FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
58
59# @ECLASS-VARIABLE: FONT_CONF
60# @DEFAULT_UNSET
61# @DESCRIPTION:
62# Array containing fontconfig conf files to install.
63FONT_CONF=( "" )
64
65# @ECLASS-VARIABLE: DOCS
66# @DEFAULT_UNSET
67# @DESCRIPTION:
68# Space delimited list of docs to install.
69# We always install these:
70# COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt
71DOCS=${DOCS:-}
72
73IUSE="
74X
75${MY_FONT_TYPES[@]}
76${MY_FONT_VARIANTS[@]}
77${MY_FONT_CHARS[@]}
78"
79[[ ${#MY_FONT_TYPES[@]} -ge 1 ]] && REQUIRED_USE="|| ( ${MY_FONT_TYPES[@]/+} )"
80
81DEPEND="
82 X? (
83 x11-apps/mkfontdir
84 media-fonts/encodings
85 )
86 sys-apps/findutils
87"
88RDEPEND=""
89RESTRICT+=" strip binchecks"
90
91# @FUNCTION: font-r1_xfont_config
92# @DESCRIPTION:
93# Generate Xorg font files (mkfontscale/mkfontdir).
94font-r1_xfont_config() {
95 local dir_name
96 if has X ${IUSE//+} && use X ; then
97 dir_name="${1:-${FONT_PN}}"
98 ebegin "Creating fonts.scale & fonts.dir in ${dir_name##*/}"
99 rm -f "${ED}${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir}
100 mkfontscale "${ED}${FONTDIR}/${1//${S}/}"
101 mkfontdir \
102 -e ${EPREFIX}/usr/share/fonts/encodings \
103 -e ${EPREFIX}/usr/share/fonts/encodings/large \
104 "${ED}${FONTDIR}/${1//${S}/}"
105 eend $?
106 if [[ -e fonts.alias ]] ; then
107 doins fonts.alias
108 fi
109 fi
110}
111
112# @FUNCTION: font-r1_fontconfig
113# @DESCRIPTION:
114# Install fontconfig conf files given in FONT_CONF.
115font-r1_fontconfig() {
116 local conffile
117 if [[ -n ${FONT_CONF[@]} ]]; then
118 insinto /etc/fonts/conf.avail/
119 for conffile in "${FONT_CONF[@]}"; do
120 [[ -e ${conffile} ]] && doins ${conffile}
121 done
122 fi
123}
124
125# @FUNCTION: font-r1_pkg_setup
126# @DESCRIPTION:
127# The font pkg_setup function.
128# Collision protection and Prefix compat for eapi < 3.
129font-r1_pkg_setup() {
130 # Prefix compat
131 case ${EAPI:-0} in
132 0|1|2)
133 if ! use prefix; then
134 EPREFIX=
135 ED=${D}
136 EROOT=${ROOT}
137 [[ ${EROOT} = */ ]] || EROOT+="/"
138 fi
139 ;;
140 esac
141
142 # make sure we get no collisions
143 # setup is not the nicest place, but preinst doesn't cut it
144 [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
145
146 local _t
147 for _t in ${MY_FONT_TYPES[@]/*_}; do
148 use font_types_${_t} && FONT_SUFFIX+=" ${_t}"
149 done
150 FONT_SUFFIX=${FONT_SUFFIX:-ttf}
151}
152
153# @FUNCTION: font-r1_font_install
154# @DESCRIPTION:
155# The main font install function.
156font-r1_font_install() {
157 local _s
158
159 insinto "${FONTDIR}"
160
161 for _s in ${FONT_SUFFIX}; do
162 find "${FONT_S[@]}" -mindepth 1 -maxdepth 1 -! -size 0 -type f \
163 -ipath "*.${_s}" -exec doins {} + 2>/dev/null
164
165 find "${ED}${FONTDIR}" -mindepth 1 -maxdepth 1 -! -size 0 -type f \
166 -ipath "*.${_s}" -exec false {} + && die \
167 "No ${_s} fonts were installed in ${FONTDIR}"
168 done
169}
170
171# @FUNCTION: font-r1_src_install
172# @DESCRIPTION:
173# The font src_install function.
174font-r1_src_install() {
175 font-r1_font_install
176 font-r1_xfont_config
177 font-r1_fontconfig
178
179 [[ "$(declare -p DOCS)" =~ "declare -a" ]] || DOCS=( ${DOCS} )
180 [[ -n ${DOCS} ]] && { dodoc "${DOCS[@]}" || die "docs installation failed" ; }
181
182 # install common docs
183 local commondoc
184 for commondoc in \
185 COPYRIGHT README{,.txt,.md} HISTORY NEWS AUTHORS{,.txt} BUGS TODO \
186 ChangeLog F{ont,ONT}L{og,OG}.txt CONTRIBUTORS{,.txt} relnotes.txt
187 do [[ -s ${commondoc} ]] && dodoc ${commondoc}
188 done
189}
190
191# @FUNCTION: font-r1_pkg_postinst
192# @DESCRIPTION:
193# The font pkg_postinst function.
194font-r1_pkg_postinst() {
195 if [[ -n ${FONT_CONF[@]} ]]; then
196 local conffile
197 echo
198 elog "The following fontconfig configuration files have been installed:"
199 elog
200 for conffile in "${FONT_CONF[@]}"; do
201 if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
202 elog " $(basename ${conffile})"
203 fi
204 done
205 elog
206 elog "Use \`eselect fontconfig\` to enable/disable them."
207 echo
208 fi
209
210 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
211 ebegin "Updating fontconfig cache for ${FONT_PN}"
212 fc-cache -s "${EROOT}"usr/share/fonts/${FONT_PN}
213 eend $?
214 else
215 einfo "Skipping cache update (media-libs/fontconfig is not installed or ROOT != /)"
216 fi
217}
218
219# @FUNCTION: font-r1_pkg_postrm
220# @DESCRIPTION:
221# The font pkg_postrm function.
222font-r1_pkg_postrm() {
223 if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
224 ebegin "Updating fontconfig cache for ${FONT_PN}"
225 fc-cache -s "${EROOT}"usr/share/fonts/${FONT_PN}
226 eend $?
227 else
228 einfo "Skipping cache update (media-libs/fontconfig is not installed or ROOT != /)"
229 fi
230}