dev-util/qbs: version bump
[gentoo.git] / eclass / x-modular.eclass
1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4 #
5 # DEPRECATED
6 # This eclass has been superseded by xorg-2
7 # Please modify your ebuilds to use that instead
8 #
9 # @ECLASS: x-modular.eclass
10 # @MAINTAINER:
11 # Donnie Berkholz <dberkholz@gentoo.org>
12 # x11@gentoo.org
13 # @BLURB: Reduces code duplication in the modularized X11 ebuilds.
14 # @DESCRIPTION:
15 # This eclass makes trivial X ebuilds possible for apps, fonts, drivers,
16 # and more. Many things that would normally be done in various functions
17 # can be accessed by setting variables instead, such as patching,
18 # running eautoreconf, passing options to configure and installing docs.
19 #
20 # All you need to do in a basic ebuild is inherit this eclass and set
21 # DESCRIPTION, KEYWORDS and RDEPEND/DEPEND. If your package is hosted
22 # with the other X packages, you don't need to set SRC_URI. Pretty much
23 # everything else should be automatic.
24
25 if [[ ${PV} = 9999* ]]; then
26         GIT_ECLASS="git"
27         SNAPSHOT="yes"
28         SRC_URI=""
29 fi
30
31 # If we're a font package, but not the font.alias one
32 FONT_ECLASS=""
33 if [[ "${PN/#font-}" != "${PN}" ]] \
34         && [[ "${CATEGORY}" = "media-fonts" ]] \
35         && [[ "${PN}" != "font-alias" ]] \
36         && [[ "${PN}" != "font-util" ]]; then
37         # Activate font code in the rest of the eclass
38         FONT="yes"
39
40         # Whether to inherit the font eclass
41         FONT_ECLASS="font"
42 fi
43
44 inherit eutils libtool multilib toolchain-funcs flag-o-matic autotools \
45         ${FONT_ECLASS} ${GIT_ECLASS}
46
47 EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_preinst pkg_postinst pkg_postrm"
48
49 case "${EAPI:-0}" in
50         0|1)
51                 ;;
52         2)
53                 EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare src_configure"
54                 ;;
55         *)
56                 die "Unknown EAPI ${EAPI}"
57                 ;;
58 esac
59
60 # exports must be ALWAYS after inherit
61 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
62
63 # @ECLASS-VARIABLE: XDIR
64 # @DESCRIPTION:
65 # Directory prefix to use for everything. If you want to install to a
66 # non-default prefix (e.g., /opt/xorg), change XDIR. This has not been
67 # recently tested. You may need to uncomment the setting of datadir and
68 # mandir in x-modular_src_install() or add it back in if it's no longer
69 # there. You may also want to change the SLOT.
70 XDIR="/usr"
71
72 IUSE=""
73 HOMEPAGE="http://xorg.freedesktop.org/"
74
75 # @ECLASS-VARIABLE: SNAPSHOT
76 # @DESCRIPTION:
77 # If set to 'yes' and configure.ac exists, eautoreconf will run. Set
78 # before inheriting this eclass.
79 : ${SNAPSHOT:=no}
80
81 # Set up SRC_URI for individual modular releases
82 BASE_INDIVIDUAL_URI="http://xorg.freedesktop.org/releases/individual"
83 # @ECLASS-VARIABLE: MODULE
84 # @DESCRIPTION:
85 # The subdirectory to download source from. Possible settings are app,
86 # doc, data, util, driver, font, lib, proto, xserver. Set above the
87 # inherit to override the default autoconfigured module.
88 if [[ -z ${MODULE} ]]; then
89         case ${CATEGORY} in
90                 app-doc)             MODULE="doc"     ;;
91                 media-fonts)         MODULE="font"    ;;
92                 x11-apps|x11-wm)     MODULE="app"     ;;
93                 x11-misc|x11-themes) MODULE="util"    ;;
94                 x11-drivers)         MODULE="driver"  ;;
95                 x11-base)            MODULE="xserver" ;;
96                 x11-proto)           MODULE="proto"   ;;
97                 x11-libs)            MODULE="lib"     ;;
98         esac
99 fi
100
101 if [[ -n ${GIT_ECLASS} ]]; then
102         EGIT_REPO_URI="git://anongit.freedesktop.org/git/xorg/${MODULE}/${PN}"
103 else
104         SRC_URI="${SRC_URI} ${BASE_INDIVIDUAL_URI}/${MODULE}/${P}.tar.bz2"
105 fi
106
107 SLOT="0"
108
109 # Set the license for the package. This can be overridden by setting
110 # LICENSE after the inherit. Nearly all FreeDesktop-hosted X packages
111 # are under the MIT license. (This is what Red Hat does in their rpms)
112 LICENSE="MIT"
113
114 # Set up shared dependencies
115 if [[ -n "${SNAPSHOT}" ]]; then
116 # FIXME: What's the minimal libtool version supporting arbitrary versioning?
117         DEPEND="${DEPEND}
118                 >=sys-devel/libtool-1.5
119                 >=sys-devel/m4-1.4"
120         WANT_AUTOCONF="latest"
121         WANT_AUTOMAKE="latest"
122 fi
123
124 if [[ -n "${FONT}" ]]; then
125         RDEPEND="${RDEPEND}
126                 media-fonts/encodings
127                 x11-apps/mkfontscale
128                 x11-apps/mkfontdir"
129         PDEPEND="${PDEPEND}
130                 media-fonts/font-alias"
131
132         # Starting with 7.0RC3, we can specify the font directory
133         # But oddly, we can't do the same for encodings or font-alias
134
135 # @ECLASS-VARIABLE: FONT_DIR
136 # @DESCRIPTION:
137 # If you're creating a font package and the suffix of PN is not equal to
138 # the subdirectory of /usr/share/fonts/ it should install into, set
139 # FONT_DIR to that directory or directories. Set before inheriting this
140 # eclass.
141         : ${FONT_DIR:=${PN##*-}}
142
143         # Fix case of font directories
144         FONT_DIR=${FONT_DIR/ttf/TTF}
145         FONT_DIR=${FONT_DIR/otf/OTF}
146         FONT_DIR=${FONT_DIR/type1/Type1}
147         FONT_DIR=${FONT_DIR/speedo/Speedo}
148
149         # Set up configure options, wrapped so ebuilds can override if need be
150         if [[ -z ${FONT_OPTIONS} ]]; then
151                 FONT_OPTIONS="--with-fontdir=\"/usr/share/fonts/${FONT_DIR}\""
152         fi
153
154         if [[ -n "${FONT}" ]]; then
155                 if [[ ${PN##*-} = misc ]] || [[ ${PN##*-} = 75dpi ]] || [[ ${PN##*-} = 100dpi ]] || [[ ${PN##*-} = cyrillic ]]; then
156                         IUSE="${IUSE} nls"
157                 fi
158         fi
159 fi
160
161 # If we're a driver package
162 if [[ "${PN/#xf86-video}" != "${PN}" ]] || [[ "${PN/#xf86-input}" != "${PN}" ]]; then
163         # Enable driver code in the rest of the eclass
164         DRIVER="yes"
165 fi
166
167 # Debugging -- ignore packages that can't be built with debugging
168 if [[ -z "${FONT}" ]] \
169         && [[ "${CATEGORY/app-doc}" = "${CATEGORY}" ]] \
170         && [[ "${CATEGORY/x11-proto}" = "${CATEGORY}" ]] \
171         && [[ "${PN/util-macros}" = "${PN}" ]] \
172         && [[ "${PN/xbitmaps}" = "${PN}" ]] \
173         && [[ "${PN/xkbdata}" = "${PN}" ]] \
174         && [[ "${PN/xorg-cf-files}" = "${PN}" ]] \
175         && [[ "${PN/xcursor}" = "${PN}" ]] \
176         ; then
177         DEBUGGABLE="yes"
178         IUSE="${IUSE} debug"
179 fi
180
181 DEPEND="${DEPEND}
182         virtual/pkgconfig"
183
184 if [[ "${PN/util-macros}" = "${PN}" ]]; then
185         DEPEND="${DEPEND}
186                 >=x11-misc/util-macros-1.3.0"
187 fi
188
189 RDEPEND="${RDEPEND}
190         !<=x11-base/xorg-x11-6.9"
191 # Provides virtual/x11 for temporary use until packages are ported
192 #       x11-base/x11-env"
193
194 # @FUNCTION: x-modular_specs_check
195 # @USAGE:
196 # @DESCRIPTION:
197 # Make any necessary changes related to gcc specs (generally hardened)
198 x-modular_specs_check() {
199         if [[ ${PN:0:11} = "xorg-server" ]] || [[ -n "${DRIVER}" ]]; then
200                 append-ldflags -Wl,-z,lazy
201                 # (#116698) breaks loading
202                 filter-ldflags -Wl,-z,now
203         fi
204 }
205
206 # @FUNCTION: x-modular_dri_check
207 # @USAGE:
208 # @DESCRIPTION:
209 # Ensures the server supports DRI if building a driver with DRI support
210 x-modular_dri_check() {
211         # (#120057) Enabling DRI in drivers requires that the server was built with
212         # support for it
213         # Starting with xorg-server 1.5.3, DRI support is always enabled unless
214         # USE=minimal is set (see bug #252084)
215         if [[ -n "${DRIVER}" ]]; then
216                 if has dri ${IUSE} && use dri; then
217                         einfo "Checking for direct rendering capabilities ..."
218                         if has_version '>=x11-base/xorg-server-1.5.3'; then
219                                 if built_with_use x11-base/xorg-server minimal; then
220                                         die "You must build x11-base/xorg-server with USE=-minimal."
221                                 fi
222                         else
223                                 if ! built_with_use x11-base/xorg-server dri; then
224                                         die "You must build x11-base/xorg-server with USE=dri."
225                                 fi
226                         fi
227                 fi
228         fi
229 }
230
231 # @FUNCTION: x-modular_server_supports_drivers_check
232 # @USAGE:
233 # @DESCRIPTION:
234 # Ensures the server SDK is installed if a driver is being built
235 x-modular_server_supports_drivers_check() {
236         # (#135873) Only certain servers will actually use or be capable of
237         # building external drivers, including binary drivers.
238         if [[ -n "${DRIVER}" ]]; then
239                 if has_version '>=x11-base/xorg-server-1.1'; then
240                         if ! built_with_use x11-base/xorg-server xorg; then
241                                 eerror "x11-base/xorg-server is not built with support for external drivers."
242                                 die "You must build x11-base/xorg-server with USE=xorg."
243                         fi
244                 fi
245         fi
246 }
247
248 # @FUNCTION: x-modular_unpack_source
249 # @USAGE:
250 # @DESCRIPTION:
251 # Simply unpack source code. Nothing else.
252 x-modular_unpack_source() {
253         if [[ -n ${GIT_ECLASS} ]]; then
254                 git_src_unpack
255         else
256                 unpack ${A}
257         fi
258         cd "${S}"
259
260         if [[ -n ${FONT_OPTIONS} ]]; then
261                 einfo "Detected font directory: ${FONT_DIR}"
262         fi
263 }
264
265 # @FUNCTION: x-modular_patch_source
266 # @USAGE:
267 # @DESCRIPTION:
268 # Apply all patches
269 x-modular_patch_source() {
270         # Use standardized names and locations with bulk patching
271         # Patch directory is ${WORKDIR}/patch
272         # See epatch() in eutils.eclass for more documentation
273         if [[ -z "${EPATCH_SUFFIX}" ]] ; then
274                 EPATCH_SUFFIX="patch"
275         fi
276
277 # @VARIABLE: PATCHES
278 # @DESCRIPTION:
279 # If you have any patches to apply, set PATCHES to their locations and epatch
280 # will apply them. It also handles epatch-style bulk patches, if you know how to
281 # use them and set the correct variables. If you don't, read eutils.eclass.
282         if [[ ${#PATCHES[@]} -gt 1 ]]; then
283                 for x in "${PATCHES[@]}"; do
284                         epatch "${x}"
285                 done
286         elif [[ -n "${PATCHES}" ]]; then
287                 for x in ${PATCHES}; do
288                         epatch "${x}"
289                 done
290         # For non-default directory bulk patching
291         elif [[ -n "${PATCH_LOC}" ]] ; then
292                 epatch ${PATCH_LOC}
293         # For standard bulk patching
294         elif [[ -d "${EPATCH_SOURCE}" ]] ; then
295                 epatch
296         fi
297 }
298
299 # @FUNCTION: x-modular_reconf_source
300 # @USAGE:
301 # @DESCRIPTION:
302 # Run eautoreconf if necessary, and run elibtoolize.
303 x-modular_reconf_source() {
304         if [[ "${SNAPSHOT}" = "yes" ]]
305         then
306                 # If possible, generate configure if it doesn't exist
307                 if [ -f "./configure.ac" ]
308                 then
309                         eautoreconf
310                 fi
311         fi
312
313         # Joshua Baergen - October 23, 2005
314         # Fix shared lib issues on MIPS, FBSD, etc etc
315         elibtoolize
316 }
317
318 # @FUNCTION: x-modular_src_prepare
319 # @USAGE:
320 # @DESCRIPTION:
321 # Prepare a package after unpacking, performing all X-related tasks.
322 x-modular_src_prepare() {
323         [[ -n ${GIT_ECLASS} ]] && has src_prepare ${EXPORTED_FUNCTIONS} \
324                 && git_src_prepare
325         x-modular_patch_source
326         x-modular_reconf_source
327 }
328
329 # @FUNCTION: x-modular_src_unpack
330 # @USAGE:
331 # @DESCRIPTION:
332 # Unpack a package, performing all X-related tasks.
333 x-modular_src_unpack() {
334         x-modular_specs_check
335         x-modular_server_supports_drivers_check
336         x-modular_dri_check
337         x-modular_unpack_source
338         has src_prepare ${EXPORTED_FUNCTIONS} || x-modular_src_prepare
339 }
340
341 # @FUNCTION: x-modular_font_configure
342 # @USAGE:
343 # @DESCRIPTION:
344 # If a font package, perform any necessary configuration steps
345 x-modular_font_configure() {
346         if [[ -n "${FONT}" ]]; then
347                 # Might be worth adding an option to configure your desired font
348                 # and exclude all others. Also, should this USE be nls or minimal?
349                 if has nls ${IUSE//+} && ! use nls; then
350                         FONT_OPTIONS="${FONT_OPTIONS}
351                                 --disable-iso8859-2
352                                 --disable-iso8859-3
353                                 --disable-iso8859-4
354                                 --disable-iso8859-5
355                                 --disable-iso8859-6
356                                 --disable-iso8859-7
357                                 --disable-iso8859-8
358                                 --disable-iso8859-9
359                                 --disable-iso8859-10
360                                 --disable-iso8859-11
361                                 --disable-iso8859-12
362                                 --disable-iso8859-13
363                                 --disable-iso8859-14
364                                 --disable-iso8859-15
365                                 --disable-iso8859-16
366                                 --disable-jisx0201
367                                 --disable-koi8-r"
368                 fi
369         fi
370 }
371
372 # @FUNCTION: x-modular_debug_setup
373 # @USAGE:
374 # @DESCRIPTION:
375 # Set up CFLAGS for a debug build
376 x-modular_debug_setup() {
377         if [[ -n "${DEBUGGABLE}" ]]; then
378                 if use debug; then
379                         strip-flags
380                         append-flags -g
381                 fi
382         fi
383 }
384
385 # @FUNCTION: x-modular_src_configure
386 # @USAGE:
387 # @DESCRIPTION:
388 # Perform any necessary pre-configuration steps, then run configure
389 x-modular_src_configure() {
390         x-modular_font_configure
391         x-modular_debug_setup
392
393 # @VARIABLE: CONFIGURE_OPTIONS
394 # @DESCRIPTION:
395 # Any extra options to pass to configure
396
397         # If prefix isn't set here, .pc files cause problems
398         if [[ -x ${ECONF_SOURCE:-.}/configure ]]; then
399                 econf --prefix=${XDIR} \
400                         --datadir=${XDIR}/share \
401                         ${FONT_OPTIONS} \
402                         ${DRIVER_OPTIONS} \
403                         ${CONFIGURE_OPTIONS}
404         fi
405 }
406
407 # @FUNCTION: x-modular_src_make
408 # @USAGE:
409 # @DESCRIPTION:
410 # Run make.
411 x-modular_src_make() {
412         emake || die "emake failed"
413 }
414
415 # @FUNCTION: x-modular_src_compile
416 # @USAGE:
417 # @DESCRIPTION:
418 # Compile a package, performing all X-related tasks.
419 x-modular_src_compile() {
420         has src_configure ${EXPORTED_FUNCTIONS} || x-modular_src_configure
421         x-modular_src_make
422 }
423
424 # @FUNCTION: x-modular_src_install
425 # @USAGE:
426 # @DESCRIPTION:
427 # Install a built package to ${D}, performing any necessary steps.
428 # Creates a ChangeLog from git if using live ebuilds.
429 x-modular_src_install() {
430         # Install everything to ${XDIR}
431         if [[ ${CATEGORY} = x11-proto ]]; then
432                 make \
433                         ${PN/proto/}docdir=/usr/share/doc/${PF} \
434                         DESTDIR="${D}" \
435                         install \
436                         || die
437         else
438                 make \
439                         docdir=/usr/share/doc/${PF} \
440                         DESTDIR="${D}" \
441                         install \
442                         || die
443         fi
444 # Shouldn't be necessary in XDIR=/usr
445 # einstall forces datadir, so we need to re-force it
446 #               datadir=${XDIR}/share \
447 #               mandir=${XDIR}/share/man \
448
449         if [[ -n ${GIT_ECLASS} ]]; then
450                 pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
451                 git log ${GIT_TREE} > "${S}"/ChangeLog
452                 popd
453         fi
454
455         if [[ -e ${S}/ChangeLog ]]; then
456                 dodoc "${S}"/ChangeLog
457         fi
458 # @VARIABLE: DOCS
459 # @DESCRIPTION:
460 # Any documentation to install via dodoc
461         [[ -n ${DOCS} ]] && dodoc ${DOCS}
462
463         # Don't install libtool archives for server modules
464         if [[ -e ${D}/usr/$(get_libdir)/xorg/modules ]]; then
465                 find "${D}"/usr/$(get_libdir)/xorg/modules -name '*.la' \
466                         | xargs rm -f
467         fi
468
469         if [[ -n "${FONT}" ]]; then
470                 remove_font_metadata
471         fi
472
473         if [[ -n "${DRIVER}" ]]; then
474                 install_driver_hwdata
475         fi
476 }
477
478 # @FUNCTION: x-modular_pkg_preinst
479 # @USAGE:
480 # @DESCRIPTION:
481 # This function doesn't do anything right now, but it may in the future.
482 x-modular_pkg_preinst() {
483         # We no longer do anything here, but we can't remove it from the API
484         :
485 }
486
487 # @FUNCTION: x-modular_pkg_postinst
488 # @USAGE:
489 # @DESCRIPTION:
490 # Run X-specific post-installation tasks on the live filesystem. The
491 # only task right now is some setup for font packages.
492 x-modular_pkg_postinst() {
493         if [[ -n "${FONT}" ]]; then
494                 setup_fonts
495         fi
496 }
497
498 # @FUNCTION: x-modular_pkg_postrm
499 # @USAGE:
500 # @DESCRIPTION:
501 # Run X-specific post-removal tasks on the live filesystem. The only
502 # task right now is some cleanup for font packages.
503 x-modular_pkg_postrm() {
504         if [[ -n "${FONT}" ]]; then
505                 font_pkg_postrm
506         fi
507 }
508
509 # @FUNCTION: setup_fonts
510 # @USAGE:
511 # @DESCRIPTION:
512 # Generates needed files for fonts and fixes font permissions
513 setup_fonts() {
514         if [[ ! -n "${FONT_DIR}" ]]; then
515                 msg="FONT_DIR is empty. The ebuild should set it to at least one subdir of /usr/share/fonts."
516                 eerror "${msg}"
517                 die "${msg}"
518         fi
519
520         create_fonts_scale
521         create_fonts_dir
522         create_font_cache
523 }
524
525 # @FUNCTION: remove_font_metadata
526 # @USAGE:
527 # @DESCRIPTION:
528 # Don't let the package install generated font files that may overlap
529 # with other packages. Instead, they're generated in pkg_postinst().
530 remove_font_metadata() {
531         local DIR
532         for DIR in ${FONT_DIR}; do
533                 if [[ "${DIR}" != "Speedo" ]] && \
534                         [[ "${DIR}" != "CID" ]] ; then
535                         # Delete font metadata files
536                         # fonts.scale, fonts.dir, fonts.cache-1
537                         rm -f "${D}"/usr/share/fonts/${DIR}/fonts.{scale,dir,cache-1}
538                 fi
539         done
540 }
541
542 # @FUNCTION: install_driver_hwdata
543 # @USAGE:
544 # @DESCRIPTION:
545 # Installs device-to-driver mappings for system-config-display and
546 # anything else that uses hwdata.
547 install_driver_hwdata() {
548         insinto /usr/share/hwdata/videoaliases
549         for i in "${FILESDIR}"/*.xinf; do
550                 # We need this for the case when none exist,
551                 # so *.xinf doesn't expand
552                 if [[ -e $i ]]; then
553                         doins $i
554                 fi
555         done
556 }
557
558 # @FUNCTION: discover_font_dirs
559 # @USAGE:
560 # @DESCRIPTION:
561 # Deprecated. Sets up the now-unused FONT_DIRS variable.
562 discover_font_dirs() {
563         FONT_DIRS="${FONT_DIR}"
564 }
565
566 # @FUNCTION: create_fonts_scale
567 # @USAGE:
568 # @DESCRIPTION:
569 # Create fonts.scale file, used by the old server-side fonts subsystem.
570 create_fonts_scale() {
571         ebegin "Creating fonts.scale files"
572                 local x
573                 for DIR in ${FONT_DIR}; do
574                         x=${ROOT}/usr/share/fonts/${DIR}
575                         [[ -z "$(ls ${x}/)" ]] && continue
576                         [[ "$(ls ${x}/)" = "fonts.cache-1" ]] && continue
577
578                         # Only generate .scale files if truetype, opentype or type1
579                         # fonts are present ...
580
581                         # NOTE: There is no way to regenerate Speedo/CID fonts.scale
582                         # <dberkholz@gentoo.org> 2 August 2004
583                         if [[ "${x/encodings}" = "${x}" ]] \
584                                 && [[ -n "$(find ${x} -iname '*.[pot][ft][abcf]' -print)" ]]; then
585                                 mkfontscale \
586                                         -a "${ROOT}"/usr/share/fonts/encodings/encodings.dir \
587                                         -- ${x}
588                         fi
589                 done
590         eend 0
591 }
592
593 # @FUNCTION: create_fonts_dir
594 # @USAGE:
595 # @DESCRIPTION:
596 # Create fonts.dir file, used by the old server-side fonts subsystem.
597 create_fonts_dir() {
598         ebegin "Generating fonts.dir files"
599                 for DIR in ${FONT_DIR}; do
600                         x=${ROOT}/usr/share/fonts/${DIR}
601                         [[ -z "$(ls ${x}/)" ]] && continue
602                         [[ "$(ls ${x}/)" = "fonts.cache-1" ]] && continue
603
604                         if [[ "${x/encodings}" = "${x}" ]]; then
605                                 mkfontdir \
606                                         -e "${ROOT}"/usr/share/fonts/encodings \
607                                         -e "${ROOT}"/usr/share/fonts/encodings/large \
608                                         -- ${x}
609                         fi
610                 done
611         eend 0
612 }
613
614 # @FUNCTION: create_font_cache
615 # @USAGE:
616 # @DESCRIPTION:
617 # Create fonts.cache-1 files, used by the new client-side fonts
618 # subsystem.
619 create_font_cache() {
620         font_pkg_postinst
621 }