1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # Removal on 2018-02-01.
8 # This eclass has been superseded by xorg-2
9 # Please modify your ebuilds to use that instead
11 # @ECLASS: x-modular.eclass
14 # @BLURB: Reduces code duplication in the modularized X11 ebuilds.
16 # This eclass makes trivial X ebuilds possible for apps, fonts, drivers,
17 # and more. Many things that would normally be done in various functions
18 # can be accessed by setting variables instead, such as patching,
19 # running eautoreconf, passing options to configure and installing docs.
21 # All you need to do in a basic ebuild is inherit this eclass and set
22 # DESCRIPTION, KEYWORDS and RDEPEND/DEPEND. If your package is hosted
23 # with the other X packages, you don't need to set SRC_URI. Pretty much
24 # everything else should be automatic.
26 if [[ ${PV} = 9999* ]]; then
32 # If we're a font package, but not the font.alias one
34 if [[ "${PN/#font-}" != "${PN}" ]] \
35 && [[ "${CATEGORY}" = "media-fonts" ]] \
36 && [[ "${PN}" != "font-alias" ]] \
37 && [[ "${PN}" != "font-util" ]]; then
38 # Activate font code in the rest of the eclass
41 # Whether to inherit the font eclass
45 inherit eutils libtool multilib toolchain-funcs flag-o-matic autotools \
46 ${FONT_ECLASS} ${GIT_ECLASS}
48 EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_preinst pkg_postinst pkg_postrm"
54 EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare src_configure"
57 die "Unknown EAPI ${EAPI}"
61 # exports must be ALWAYS after inherit
62 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
64 # @ECLASS-VARIABLE: XDIR
66 # Directory prefix to use for everything. If you want to install to a
67 # non-default prefix (e.g., /opt/xorg), change XDIR. This has not been
68 # recently tested. You may need to uncomment the setting of datadir and
69 # mandir in x-modular_src_install() or add it back in if it's no longer
70 # there. You may also want to change the SLOT.
74 HOMEPAGE="https://www.x.org/wiki/"
76 # @ECLASS-VARIABLE: SNAPSHOT
78 # If set to 'yes' and configure.ac exists, eautoreconf will run. Set
79 # before inheriting this eclass.
82 # Set up SRC_URI for individual modular releases
83 BASE_INDIVIDUAL_URI="https://www.x.org/releases/individual"
84 # @ECLASS-VARIABLE: MODULE
86 # The subdirectory to download source from. Possible settings are app,
87 # doc, data, util, driver, font, lib, proto, xserver. Set above the
88 # inherit to override the default autoconfigured module.
89 if [[ -z ${MODULE} ]]; then
91 app-doc) MODULE="doc" ;;
92 media-fonts) MODULE="font" ;;
93 x11-apps|x11-wm) MODULE="app" ;;
94 x11-misc|x11-themes) MODULE="util" ;;
95 x11-drivers) MODULE="driver" ;;
96 x11-base) MODULE="xserver" ;;
97 x11-proto) MODULE="proto" ;;
98 x11-libs) MODULE="lib" ;;
102 if [[ -n ${GIT_ECLASS} ]]; then
103 EGIT_REPO_URI="https://anongit.freedesktop.org/git/xorg/${MODULE}/${PN}.git"
105 SRC_URI="${SRC_URI} ${BASE_INDIVIDUAL_URI}/${MODULE}/${P}.tar.bz2"
110 # Set the license for the package. This can be overridden by setting
111 # LICENSE after the inherit. Nearly all FreeDesktop-hosted X packages
112 # are under the MIT license. (This is what Red Hat does in their rpms)
115 # Set up shared dependencies
116 if [[ -n "${SNAPSHOT}" ]]; then
117 # FIXME: What's the minimal libtool version supporting arbitrary versioning?
119 >=sys-devel/libtool-1.5
121 WANT_AUTOCONF="latest"
122 WANT_AUTOMAKE="latest"
125 if [[ -n "${FONT}" ]]; then
127 media-fonts/encodings
131 media-fonts/font-alias"
133 # Starting with 7.0RC3, we can specify the font directory
134 # But oddly, we can't do the same for encodings or font-alias
136 # @ECLASS-VARIABLE: FONT_DIR
138 # If you're creating a font package and the suffix of PN is not equal to
139 # the subdirectory of /usr/share/fonts/ it should install into, set
140 # FONT_DIR to that directory or directories. Set before inheriting this
142 : ${FONT_DIR:=${PN##*-}}
144 # Fix case of font directories
145 FONT_DIR=${FONT_DIR/ttf/TTF}
146 FONT_DIR=${FONT_DIR/otf/OTF}
147 FONT_DIR=${FONT_DIR/type1/Type1}
148 FONT_DIR=${FONT_DIR/speedo/Speedo}
150 # Set up configure options, wrapped so ebuilds can override if need be
151 if [[ -z ${FONT_OPTIONS} ]]; then
152 FONT_OPTIONS="--with-fontdir=\"/usr/share/fonts/${FONT_DIR}\""
155 if [[ -n "${FONT}" ]]; then
156 if [[ ${PN##*-} = misc ]] || [[ ${PN##*-} = 75dpi ]] || [[ ${PN##*-} = 100dpi ]] || [[ ${PN##*-} = cyrillic ]]; then
162 # If we're a driver package
163 if [[ "${PN/#xf86-video}" != "${PN}" ]] || [[ "${PN/#xf86-input}" != "${PN}" ]]; then
164 # Enable driver code in the rest of the eclass
168 # Debugging -- ignore packages that can't be built with debugging
169 if [[ -z "${FONT}" ]] \
170 && [[ "${CATEGORY/app-doc}" = "${CATEGORY}" ]] \
171 && [[ "${CATEGORY/x11-proto}" = "${CATEGORY}" ]] \
172 && [[ "${PN/util-macros}" = "${PN}" ]] \
173 && [[ "${PN/xbitmaps}" = "${PN}" ]] \
174 && [[ "${PN/xkbdata}" = "${PN}" ]] \
175 && [[ "${PN/xorg-cf-files}" = "${PN}" ]] \
176 && [[ "${PN/xcursor}" = "${PN}" ]] \
185 if [[ "${PN/util-macros}" = "${PN}" ]]; then
187 >=x11-misc/util-macros-1.3.0"
191 !<=x11-base/xorg-x11-6.9"
192 # Provides virtual/x11 for temporary use until packages are ported
195 # @FUNCTION: x-modular_specs_check
198 # Make any necessary changes related to gcc specs (generally hardened)
199 x-modular_specs_check() {
200 if [[ ${PN:0:11} = "xorg-server" ]] || [[ -n "${DRIVER}" ]]; then
201 append-ldflags -Wl,-z,lazy
202 # (#116698) breaks loading
203 filter-ldflags -Wl,-z,now
207 # @FUNCTION: x-modular_dri_check
210 # Ensures the server supports DRI if building a driver with DRI support
211 x-modular_dri_check() {
212 # (#120057) Enabling DRI in drivers requires that the server was built with
214 # Starting with xorg-server 1.5.3, DRI support is always enabled unless
215 # USE=minimal is set (see bug #252084)
216 if [[ -n "${DRIVER}" ]]; then
217 if has dri ${IUSE} && use dri; then
218 einfo "Checking for direct rendering capabilities ..."
219 if has_version '>=x11-base/xorg-server-1.5.3'; then
220 if built_with_use x11-base/xorg-server minimal; then
221 die "You must build x11-base/xorg-server with USE=-minimal."
224 if ! built_with_use x11-base/xorg-server dri; then
225 die "You must build x11-base/xorg-server with USE=dri."
232 # @FUNCTION: x-modular_server_supports_drivers_check
235 # Ensures the server SDK is installed if a driver is being built
236 x-modular_server_supports_drivers_check() {
237 # (#135873) Only certain servers will actually use or be capable of
238 # building external drivers, including binary drivers.
239 if [[ -n "${DRIVER}" ]]; then
240 if has_version '>=x11-base/xorg-server-1.1'; then
241 if ! built_with_use x11-base/xorg-server xorg; then
242 eerror "x11-base/xorg-server is not built with support for external drivers."
243 die "You must build x11-base/xorg-server with USE=xorg."
249 # @FUNCTION: x-modular_unpack_source
252 # Simply unpack source code. Nothing else.
253 x-modular_unpack_source() {
254 if [[ -n ${GIT_ECLASS} ]]; then
261 if [[ -n ${FONT_OPTIONS} ]]; then
262 einfo "Detected font directory: ${FONT_DIR}"
266 # @FUNCTION: x-modular_patch_source
270 x-modular_patch_source() {
271 # Use standardized names and locations with bulk patching
272 # Patch directory is ${WORKDIR}/patch
273 # See epatch() in eutils.eclass for more documentation
274 if [[ -z "${EPATCH_SUFFIX}" ]] ; then
275 EPATCH_SUFFIX="patch"
280 # If you have any patches to apply, set PATCHES to their locations and epatch
281 # will apply them. It also handles epatch-style bulk patches, if you know how to
282 # use them and set the correct variables. If you don't, read eutils.eclass.
283 if [[ ${#PATCHES[@]} -gt 1 ]]; then
284 for x in "${PATCHES[@]}"; do
287 elif [[ -n "${PATCHES}" ]]; then
288 for x in ${PATCHES}; do
291 # For non-default directory bulk patching
292 elif [[ -n "${PATCH_LOC}" ]] ; then
294 # For standard bulk patching
295 elif [[ -d "${EPATCH_SOURCE}" ]] ; then
300 # @FUNCTION: x-modular_reconf_source
303 # Run eautoreconf if necessary, and run elibtoolize.
304 x-modular_reconf_source() {
305 if [[ "${SNAPSHOT}" = "yes" ]]
307 # If possible, generate configure if it doesn't exist
308 if [ -f "./configure.ac" ]
314 # Joshua Baergen - October 23, 2005
315 # Fix shared lib issues on MIPS, FBSD, etc etc
319 # @FUNCTION: x-modular_src_prepare
322 # Prepare a package after unpacking, performing all X-related tasks.
323 x-modular_src_prepare() {
324 [[ -n ${GIT_ECLASS} ]] && has src_prepare ${EXPORTED_FUNCTIONS} \
326 x-modular_patch_source
327 x-modular_reconf_source
330 # @FUNCTION: x-modular_src_unpack
333 # Unpack a package, performing all X-related tasks.
334 x-modular_src_unpack() {
335 x-modular_specs_check
336 x-modular_server_supports_drivers_check
338 x-modular_unpack_source
339 has src_prepare ${EXPORTED_FUNCTIONS} || x-modular_src_prepare
342 # @FUNCTION: x-modular_font_configure
345 # If a font package, perform any necessary configuration steps
346 x-modular_font_configure() {
347 if [[ -n "${FONT}" ]]; then
348 # Might be worth adding an option to configure your desired font
349 # and exclude all others. Also, should this USE be nls or minimal?
350 if has nls ${IUSE//+} && ! use nls; then
351 FONT_OPTIONS="${FONT_OPTIONS}
373 # @FUNCTION: x-modular_debug_setup
376 # Set up CFLAGS for a debug build
377 x-modular_debug_setup() {
378 if [[ -n "${DEBUGGABLE}" ]]; then
386 # @FUNCTION: x-modular_src_configure
389 # Perform any necessary pre-configuration steps, then run configure
390 x-modular_src_configure() {
391 x-modular_font_configure
392 x-modular_debug_setup
394 # @VARIABLE: CONFIGURE_OPTIONS
396 # Any extra options to pass to configure
398 # If prefix isn't set here, .pc files cause problems
399 if [[ -x ${ECONF_SOURCE:-.}/configure ]]; then
400 econf --prefix=${XDIR} \
401 --datadir=${XDIR}/share \
408 # @FUNCTION: x-modular_src_make
412 x-modular_src_make() {
413 emake || die "emake failed"
416 # @FUNCTION: x-modular_src_compile
419 # Compile a package, performing all X-related tasks.
420 x-modular_src_compile() {
421 has src_configure ${EXPORTED_FUNCTIONS} || x-modular_src_configure
425 # @FUNCTION: x-modular_src_install
428 # Install a built package to ${D}, performing any necessary steps.
429 # Creates a ChangeLog from git if using live ebuilds.
430 x-modular_src_install() {
431 # Install everything to ${XDIR}
432 if [[ ${CATEGORY} = x11-proto ]]; then
434 ${PN/proto/}docdir=/usr/share/doc/${PF} \
440 docdir=/usr/share/doc/${PF} \
445 # Shouldn't be necessary in XDIR=/usr
446 # einstall forces datadir, so we need to re-force it
447 # datadir=${XDIR}/share \
448 # mandir=${XDIR}/share/man \
450 if [[ -n ${GIT_ECLASS} ]]; then
451 pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
452 git log ${GIT_TREE} > "${S}"/ChangeLog
456 if [[ -e ${S}/ChangeLog ]]; then
457 dodoc "${S}"/ChangeLog
461 # Any documentation to install via dodoc
462 [[ -n ${DOCS} ]] && dodoc ${DOCS}
464 # Don't install libtool archives for server modules
465 if [[ -e ${D}/usr/$(get_libdir)/xorg/modules ]]; then
466 find "${D}"/usr/$(get_libdir)/xorg/modules -name '*.la' \
470 if [[ -n "${FONT}" ]]; then
474 if [[ -n "${DRIVER}" ]]; then
475 install_driver_hwdata
479 # @FUNCTION: x-modular_pkg_preinst
482 # This function doesn't do anything right now, but it may in the future.
483 x-modular_pkg_preinst() {
484 # We no longer do anything here, but we can't remove it from the API
488 # @FUNCTION: x-modular_pkg_postinst
491 # Run X-specific post-installation tasks on the live filesystem. The
492 # only task right now is some setup for font packages.
493 x-modular_pkg_postinst() {
494 if [[ -n "${FONT}" ]]; then
499 # @FUNCTION: x-modular_pkg_postrm
502 # Run X-specific post-removal tasks on the live filesystem. The only
503 # task right now is some cleanup for font packages.
504 x-modular_pkg_postrm() {
505 if [[ -n "${FONT}" ]]; then
510 # @FUNCTION: setup_fonts
513 # Generates needed files for fonts and fixes font permissions
515 if [[ ! -n "${FONT_DIR}" ]]; then
516 msg="FONT_DIR is empty. The ebuild should set it to at least one subdir of /usr/share/fonts."
526 # @FUNCTION: remove_font_metadata
529 # Don't let the package install generated font files that may overlap
530 # with other packages. Instead, they're generated in pkg_postinst().
531 remove_font_metadata() {
533 for DIR in ${FONT_DIR}; do
534 if [[ "${DIR}" != "Speedo" ]] && \
535 [[ "${DIR}" != "CID" ]] ; then
536 # Delete font metadata files
537 # fonts.scale, fonts.dir, fonts.cache-1
538 rm -f "${D}"/usr/share/fonts/${DIR}/fonts.{scale,dir,cache-1}
543 # @FUNCTION: install_driver_hwdata
546 # Installs device-to-driver mappings for system-config-display and
547 # anything else that uses hwdata.
548 install_driver_hwdata() {
549 insinto /usr/share/hwdata/videoaliases
550 for i in "${FILESDIR}"/*.xinf; do
551 # We need this for the case when none exist,
552 # so *.xinf doesn't expand
559 # @FUNCTION: discover_font_dirs
562 # Deprecated. Sets up the now-unused FONT_DIRS variable.
563 discover_font_dirs() {
564 FONT_DIRS="${FONT_DIR}"
567 # @FUNCTION: create_fonts_scale
570 # Create fonts.scale file, used by the old server-side fonts subsystem.
571 create_fonts_scale() {
572 ebegin "Creating fonts.scale files"
574 for DIR in ${FONT_DIR}; do
575 x=${ROOT}/usr/share/fonts/${DIR}
576 [[ -z "$(ls ${x}/)" ]] && continue
577 [[ "$(ls ${x}/)" = "fonts.cache-1" ]] && continue
579 # Only generate .scale files if truetype, opentype or type1
580 # fonts are present ...
582 # NOTE: There is no way to regenerate Speedo/CID fonts.scale
583 # <dberkholz@gentoo.org> 2 August 2004
584 if [[ "${x/encodings}" = "${x}" ]] \
585 && [[ -n "$(find ${x} -iname '*.[pot][ft][abcf]' -print)" ]]; then
587 -a "${ROOT}"/usr/share/fonts/encodings/encodings.dir \
594 # @FUNCTION: create_fonts_dir
597 # Create fonts.dir file, used by the old server-side fonts subsystem.
599 ebegin "Generating fonts.dir files"
600 for DIR in ${FONT_DIR}; do
601 x=${ROOT}/usr/share/fonts/${DIR}
602 [[ -z "$(ls ${x}/)" ]] && continue
603 [[ "$(ls ${x}/)" = "fonts.cache-1" ]] && continue
605 if [[ "${x/encodings}" = "${x}" ]]; then
607 -e "${ROOT}"/usr/share/fonts/encodings \
608 -e "${ROOT}"/usr/share/fonts/encodings/large \
615 # @FUNCTION: create_font_cache
618 # Create fonts.cache-1 files, used by the new client-side fonts
620 create_font_cache() {