/[gentoo-x86]/eclass/x-modular.eclass
Gentoo

Contents of /eclass/x-modular.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (show annotations) (download)
Wed Dec 7 11:19:47 2005 UTC (8 years, 11 months ago) by spyderous
Branch: MAIN
Changes since 1.24: +107 -6 lines
Major rework of font handling for 7.0RC3's new --with-fontdir and --disable-iso8859-*. Add a default pkg_postrm() to clean out font directories only containing metadata.

1 # Copyright 1999-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/x-modular.eclass,v 1.24 2005/12/06 02:22:16 spyderous Exp $
4 #
5 # Author: Donnie Berkholz <spyderous@gentoo.org>
6 #
7 # This eclass is designed to reduce code duplication in the modularized X11
8 # ebuilds.
9 #
10 # If the ebuild installs fonts, set FONT="yes" at the top and set FONT_DIRS to
11 # the subdirectories within /usr/share/fonts to which it installs fonts.
12
13 EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_preinst pkg_postinst pkg_postrm
14
15 inherit eutils libtool
16
17 # Directory prefix to use for everything
18 XDIR="/usr"
19
20 IUSE=""
21 HOMEPAGE="http://xorg.freedesktop.org/"
22 SRC_URI="http://xorg.freedesktop.org/releases/X11R7.0-RC3/everything/${P}.tar.bz2
23 http://xorg.freedesktop.org/releases/X11R7.0-RC2/everything/${P}.tar.bz2
24 http://xorg.freedesktop.org/releases/X11R7.0-RC1/everything/${P}.tar.bz2
25 http://xorg.freedesktop.org/releases/X11R7.0-RC0/everything/${P}.tar.bz2"
26 LICENSE="X11"
27 SLOT="0"
28
29 # Set up shared dependencies
30 if [ -n "${SNAPSHOT}" ]; then
31 # FIXME: What's the minimal libtool version supporting arbitrary versioning?
32 DEPEND="${DEPEND}
33 >=sys-devel/autoconf-2.57
34 >=sys-devel/automake-1.7
35 >=sys-devel/libtool-1.5
36 >=sys-devel/m4-1.4"
37 fi
38
39 # If we're a font package, but not the font.alias one
40 if [[ "${PN/#font-}" != "${PN}" ]] \
41 && [[ "${PN}" != "font-alias" ]] \
42 && [[ "${PN}" != "font-util" ]]; then
43 # Activate font code in the rest of the eclass
44 FONT="yes"
45
46 RDEPEND="${RDEPEND}
47 media-fonts/encodings"
48 PDEPEND="${PDEPEND}
49 media-fonts/font-alias"
50
51 # Starting with 7.0RC3, we can specify the font directory
52 # But oddly, we can't do the same for encodings or font-alias
53
54 # Wrap in `if` so ebuilds can set it too
55 if [[ -z ${FONT_DIR} ]]; then
56 FONT_DIR=${PN##*-}
57
58 fi
59
60 # Fix case of font directories
61 FONT_DIR=${FONT_DIR/ttf/TTF}
62 FONT_DIR=${FONT_DIR/otf/OTF}
63 FONT_DIR=${FONT_DIR/type1/Type1}
64 FONT_DIR=${FONT_DIR/speedo/Speedo}
65
66 # Set up configure option
67 FONT_OPTIONS="--with-fontdir=\"/usr/share/fonts/${FONT_DIR}\""
68
69 if [[ -n "${FONT}" ]]; then
70 if [[ ${PN##*-} = misc ]] || [[ ${PN##*-} = 75dpi ]] || [[ ${PN##*-} = 100dpi ]]; then
71 IUSE="${IUSE} nls"
72 fi
73 fi
74 fi
75
76 # If we're a driver package
77 if [[ "${PN/#xf86-video}" != "${PN}" ]] || [[ "${PN/#xf86-input}" != "${PN}" ]]; then
78 # Don't build static driver modules
79 DRIVER_OPTIONS="--disable-static"
80 fi
81
82 DEPEND="${DEPEND}
83 >=dev-util/pkgconfig-0.18
84 >=x11-misc/util-macros-0.99.2"
85
86 # >=sys-apps/man-1.6b-r2 required to look in [0-8]x/ directories
87 RDEPEND="${RDEPEND}
88 !<=x11-base/xorg-x11-6.9
89 >=sys-apps/man-1.6b-r2"
90 # Provides virtual/x11 for temporary use until packages are ported
91 # x11-base/x11-env"
92
93 x-modular_unpack_source() {
94 unpack ${A}
95 cd ${S}
96
97 # Joshua Baergen - October 23, 2005
98 # Fix shared lib issues on MIPS, FBSD, etc etc
99 elibtoolize
100
101 if [[ -n ${FONT_OPTIONS} ]]; then
102 einfo "Detected font directory: ${FONT_DIR}"
103 fi
104 }
105
106 x-modular_patch_source() {
107 # Use standardized names and locations with bulk patching
108 # Patch directory is ${WORKDIR}/patch
109 # See epatch() in eutils.eclass for more documentation
110 if [ -z "${EPATCH_SUFFIX}" ] ; then
111 EPATCH_SUFFIX="patch"
112 fi
113
114 # For specific list of patches
115 if [ -n "${PATCHES}" ] ; then
116 for PATCH in ${PATCHES}
117 do
118 epatch ${PATCH}
119 done
120 # For non-default directory bulk patching
121 elif [ -n "${PATCH_LOC}" ] ; then
122 epatch ${PATCH_LOC}
123 # For standard bulk patching
124 elif [ -d "${EPATCH_SOURCE}" ] ; then
125 epatch
126 fi
127 }
128
129 x-modular_reconf_source() {
130 # Run autoreconf for CVS snapshots only
131 if [ "${SNAPSHOT}" = "yes" ]
132 then
133 # If possible, generate configure if it doesn't exist
134 if [ -f "${S}/configure.ac" ]
135 then
136 einfo "Running autoreconf..."
137 autoreconf -v --force --install
138 fi
139 fi
140
141 }
142
143 x-modular_src_unpack() {
144 x-modular_unpack_source
145 x-modular_patch_source
146 x-modular_reconf_source
147 }
148
149 x-modular_font_configure() {
150 if [[ -n "${FONT}" ]]; then
151 # Might be worth adding an option to configure your desired font
152 # and exclude all others. Also, should this USE be nls or minimal?
153 if ! use nls; then
154 FONT_OPTIONS="${FONT_OPTIONS}
155 --disable-iso8859-2
156 --disable-iso8859-3
157 --disable-iso8859-4
158 --disable-iso8859-5
159 --disable-iso8859-6
160 --disable-iso8859-7
161 --disable-iso8859-8
162 --disable-iso8859-9
163 --disable-iso8859-10
164 --disable-iso8859-11
165 --disable-iso8859-12
166 --disable-iso8859-13
167 --disable-iso8859-14
168 --disable-iso8859-15
169 --disable-iso8859-16
170 --disable-jisx0201
171 --disable-koi8-r"
172 fi
173 fi
174 }
175
176 x-modular_src_configure() {
177 x-modular_font_configure
178
179 # If prefix isn't set here, .pc files cause problems
180 if [ -x ./configure ]; then
181 econf --prefix=${XDIR} \
182 --datadir=${XDIR}/share \
183 ${FONT_OPTIONS} \
184 ${DRIVER_OPTIONS} \
185 ${CONFIGURE_OPTIONS}
186 fi
187 }
188
189 x-modular_src_make() {
190 emake || die "emake failed"
191 }
192
193 x-modular_src_compile() {
194 x-modular_src_configure
195 x-modular_src_make
196 }
197
198 x-modular_src_install() {
199 # Install everything to ${XDIR}
200 make \
201 DESTDIR="${D}" \
202 install
203 # Shouldn't be necessary in XDIR=/usr
204 # einstall forces datadir, so we need to re-force it
205 # datadir=${XDIR}/share \
206 # mandir=${XDIR}/share/man \
207
208 # Don't install libtool archives for server modules
209 if [[ -e ${D}/usr/lib/xorg/modules ]]; then
210 find ${D}/usr/lib/xorg/modules -name '*.la' \
211 | xargs rm -f
212 fi
213 }
214
215 x-modular_pkg_preinst() {
216 if [[ -n "${FONT}" ]]; then
217 discover_font_dirs
218 fi
219 }
220
221 x-modular_pkg_postinst() {
222 if [[ -n "${FONT}" ]]; then
223 setup_fonts
224 fi
225 }
226
227 x-modular_pkg_postrm() {
228 if [[ -n "${FONT}" ]]; then
229 cleanup_fonts
230 fi
231 }
232
233 cleanup_fonts() {
234 local ALLOWED_FILES="encodings.dir fonts.cache-1 fonts.dir fonts.scale"
235 for DIR in ${FONT_DIR}; do
236 unset KEEP_FONTDIR
237 REAL_DIR=${ROOT}usr/share/fonts/${DIR}
238
239 ebegin "Checking ${REAL_DIR} for useless files"
240 pushd ${REAL_DIR} &> /dev/null
241 for FILE in *; do
242 unset MATCH
243 for ALLOWED_FILE in ${ALLOWED_FILES}; do
244 if [[ ${FILE} = ${ALLOWED_FILE} ]]; then
245 # If it's allowed, then move on to the next file
246 MATCH="yes"
247 break
248 fi
249 done
250 # If we found a match in allowed files, move on to the next file
251 if [[ -n ${MATCH} ]]; then
252 continue
253 fi
254 # If we get this far, there wasn't a match in the allowed files
255 KEEP_FONTDIR="yes"
256 # We don't need to check more files if we're already keeping it
257 break
258 done
259 popd &> /dev/null
260 # If there are no files worth keeping, then get rid of the dir
261 if [[ -z "${KEEP_FONTDIR}" ]]; then
262 rm -rf ${REAL_DIR}
263 fi
264 eend 0
265 done
266 }
267
268 setup_fonts() {
269 if [[ ! -n "${FONT_DIRS}" ]]; then
270 msg="FONT_DIRS is empty. The ebuild should set it to at least one subdir of /usr/share/fonts."
271 eerror "${msg}"
272 die "${msg}"
273 fi
274
275 create_fonts_scale
276 create_fonts_dir
277 fix_font_permissions
278 create_font_cache
279 }
280
281 discover_font_dirs() {
282 pushd ${IMAGE}/usr/share/fonts
283 FONT_DIRS="$(find . -maxdepth 1 -mindepth 1 -type d)"
284 FONT_DIRS="$(echo ${FONT_DIRS} | sed -e 's:./::g')"
285 popd
286 }
287
288 create_fonts_scale() {
289 ebegin "Creating fonts.scale files"
290 local x
291 for FONT_DIR in ${FONT_DIRS}; do
292 x=${ROOT}/usr/share/fonts/${FONT_DIR}
293 [ -z "$(ls ${x}/)" ] && continue
294 [ "$(ls ${x}/)" = "fonts.cache-1" ] && continue
295
296 # Only generate .scale files if truetype, opentype or type1
297 # fonts are present ...
298
299 # First truetype (ttf,ttc)
300 # NOTE: ttmkfdir does NOT work on type1 fonts (#53753)
301 # Also, there is no way to regenerate Speedo/CID fonts.scale
302 # <spyderous@gentoo.org> 2 August 2004
303 if [ "${x/encodings}" = "${x}" -a \
304 -n "$(find ${x} -iname '*.tt[cf]' -print)" ]; then
305 if [ -x ${ROOT}/usr/bin/ttmkfdir ]; then
306 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ROOT}/usr/$(get_libdir)" \
307 ${ROOT}/usr/bin/ttmkfdir -x 2 \
308 -e ${ROOT}/usr/share/fonts/encodings/encodings.dir \
309 -o ${x}/fonts.scale -d ${x}
310 # ttmkfdir fails on some stuff, so try mkfontscale if it does
311 local ttmkfdir_return=$?
312 else
313 # We didn't use ttmkfdir at all
314 local ttmkfdir_return=2
315 fi
316 if [ ${ttmkfdir_return} -ne 0 ]; then
317 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ROOT}/usr/$(get_libdir)" \
318 ${ROOT}/usr/bin/mkfontscale \
319 -a /usr/share/fonts/encodings/encodings.dir \
320 -- ${x}
321 fi
322 # Next type1 and opentype (pfa,pfb,otf,otc)
323 elif [ "${x/encodings}" = "${x}" -a \
324 -n "$(find ${x} -iname '*.[po][ft][abcf]' -print)" ]; then
325 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ROOT}/usr/$(get_libdir)" \
326 ${ROOT}/usr/bin/mkfontscale \
327 -a ${ROOT}/usr/share/fonts/encodings/encodings.dir \
328 -- ${x}
329 fi
330 done
331 eend 0
332 }
333
334 create_fonts_dir() {
335 ebegin "Generating fonts.dir files"
336 for FONT_DIR in ${FONT_DIRS}; do
337 x=${ROOT}/usr/share/fonts/${FONT_DIR}
338 [ -z "$(ls ${x}/)" ] && continue
339 [ "$(ls ${x}/)" = "fonts.cache-1" ] && continue
340
341 if [ "${x/encodings}" = "${x}" ]; then
342 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ROOT}/usr/$(get_libdir)" \
343 ${ROOT}/usr/bin/mkfontdir \
344 -e ${ROOT}/usr/share/fonts/encodings \
345 -e ${ROOT}/usr/share/fonts/encodings/large \
346 -- ${x}
347 fi
348 done
349 eend 0
350 }
351
352 fix_font_permissions() {
353 ebegin "Fixing permissions"
354 for FONT_DIR in ${FONT_DIRS}; do
355 find ${ROOT}/usr/share/fonts/${FONT_DIR} -type f -name 'font.*' \
356 -exec chmod 0644 {} \;
357 done
358 eend 0
359 }
360
361 create_font_cache() {
362 # danarmak found out that fc-cache should be run AFTER all the above
363 # stuff, as otherwise the cache is invalid, and has to be run again
364 # as root anyway
365 if [ -x ${ROOT}/usr/bin/fc-cache ]; then
366 ebegin "Creating FC font cache"
367 HOME="/root" ${ROOT}/usr/bin/fc-cache
368 eend 0
369 fi
370 }

  ViewVC Help
Powered by ViewVC 1.1.20