1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: xorg-2.eclass
8 # Author: Tomáš Chvátal <scarabeus@gentoo.org>
9 # Author: Donnie Berkholz <dberkholz@gentoo.org>
10 # @SUPPORTED_EAPIS: 4 5
11 # @BLURB: Reduces code duplication in the modularized X11 ebuilds.
13 # This eclass makes trivial X ebuilds possible for apps, fonts, drivers,
14 # and more. Many things that would normally be done in various functions
15 # can be accessed by setting variables instead, such as patching,
16 # running eautoreconf, passing options to configure and installing docs.
18 # All you need to do in a basic ebuild is inherit this eclass and set
19 # DESCRIPTION, KEYWORDS and RDEPEND/DEPEND. If your package is hosted
20 # with the other X packages, you don't need to set SRC_URI. Pretty much
21 # everything else should be automatic.
24 if [[ ${PV} == *9999* ]]; then
26 XORG_EAUTORECONF="yes"
29 # If we're a font package, but not the font.alias one
31 if [[ ${CATEGORY} = media-fonts ]]; then
36 # Activate font code in the rest of the eclass
43 # @ECLASS-VARIABLE: XORG_MULTILIB
45 # If set to 'yes', the multilib support for package will be enabled. Set
46 # before inheriting this eclass.
47 : ${XORG_MULTILIB:="no"}
49 # we need to inherit autotools first to get the deps
50 inherit autotools autotools-utils eutils libtool multilib toolchain-funcs \
51 flag-o-matic ${FONT_ECLASS} ${GIT_ECLASS}
53 if [[ ${XORG_MULTILIB} == yes ]]; then
54 inherit autotools-multilib
57 EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_postinst pkg_postrm"
59 4|5) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare src_configure" ;;
60 *) die "EAPI=${EAPI} is not supported" ;;
63 # exports must be ALWAYS after inherit
64 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
68 # @ECLASS-VARIABLE: XORG_EAUTORECONF
70 # If set to 'yes' and configure.ac exists, eautoreconf will run. Set
71 # before inheriting this eclass.
72 : ${XORG_EAUTORECONF:="no"}
74 # @ECLASS-VARIABLE: XORG_BASE_INDIVIDUAL_URI
76 # Set up SRC_URI for individual modular releases. If set to an empty
77 # string, no SRC_URI will be provided by the eclass.
78 : ${XORG_BASE_INDIVIDUAL_URI="https://www.x.org/releases/individual"}
80 # @ECLASS-VARIABLE: XORG_MODULE
82 # The subdirectory to download source from. Possible settings are app,
83 # doc, data, util, driver, font, lib, proto, xserver. Set above the
84 # inherit to override the default autoconfigured module.
85 : ${XORG_MODULE:="auto"}
86 if [[ ${XORG_MODULE} == auto ]]; then
88 app-doc) XORG_MODULE=doc/ ;;
89 media-fonts) XORG_MODULE=font/ ;;
90 x11-apps|x11-wm) XORG_MODULE=app/ ;;
91 x11-misc|x11-themes) XORG_MODULE=util/ ;;
92 x11-base) XORG_MODULE=xserver/ ;;
93 x11-drivers) XORG_MODULE=driver/ ;;
94 x11-libs) XORG_MODULE=lib/ ;;
99 # @ECLASS-VARIABLE: XORG_PACKAGE_NAME
101 # For git checkout the git repository might differ from package name.
102 # This variable can be used for proper directory specification
103 : ${XORG_PACKAGE_NAME:=${PN}}
105 HOMEPAGE="https://www.x.org/wiki/ https://gitlab.freedesktop.org/xorg/${XORG_MODULE}${XORG_PACKAGE_NAME}"
107 if [[ -n ${GIT_ECLASS} ]]; then
108 : ${EGIT_REPO_URI:="https://gitlab.freedesktop.org/xorg/${XORG_MODULE}${XORG_PACKAGE_NAME}.git"}
109 elif [[ -n ${XORG_BASE_INDIVIDUAL_URI} ]]; then
110 SRC_URI="${XORG_BASE_INDIVIDUAL_URI}/${XORG_MODULE}${P}.tar.bz2"
115 # Set the license for the package. This can be overridden by setting
116 # LICENSE after the inherit. Nearly all FreeDesktop-hosted X packages
117 # are under the MIT license. (This is what Red Hat does in their rpms)
120 # Set up autotools shared dependencies
121 # Remember that all versions here MUST be stable
122 XORG_EAUTORECONF_ARCHES="ppc-aix x86-winnt"
123 EAUTORECONF_DEPEND+="
124 >=sys-devel/libtool-2.2.6a
126 if [[ ${PN} != util-macros ]] ; then
127 EAUTORECONF_DEPEND+=" >=x11-misc/util-macros-1.18"
128 # Required even by xorg-server
129 [[ ${PN} == "font-util" ]] || EAUTORECONF_DEPEND+=" >=media-fonts/font-util-1.2.0"
131 WANT_AUTOCONF="latest"
132 WANT_AUTOMAKE="latest"
133 for arch in ${XORG_EAUTORECONF_ARCHES}; do
134 EAUTORECONF_DEPENDS+=" ${arch}? ( ${EAUTORECONF_DEPEND} )"
136 DEPEND+=" ${EAUTORECONF_DEPENDS}"
137 [[ ${XORG_EAUTORECONF} != no ]] && DEPEND+=" ${EAUTORECONF_DEPEND}"
138 unset EAUTORECONF_DEPENDS
139 unset EAUTORECONF_DEPEND
141 if [[ ${FONT} == yes ]]; then
142 RDEPEND+=" media-fonts/encodings
143 >=x11-apps/mkfontscale-1.2.0"
144 PDEPEND+=" media-fonts/font-alias"
145 DEPEND+=" >=media-fonts/font-util-1.2.0
146 >=x11-apps/mkfontscale-1.2.0"
148 # @ECLASS-VARIABLE: FONT_DIR
150 # If you're creating a font package and the suffix of PN is not equal to
151 # the subdirectory of /usr/share/fonts/ it should install into, set
152 # FONT_DIR to that directory or directories. Set before inheriting this
154 [[ -z ${FONT_DIR} ]] && FONT_DIR=${PN##*-}
156 # Fix case of font directories
157 FONT_DIR=${FONT_DIR/ttf/TTF}
158 FONT_DIR=${FONT_DIR/otf/OTF}
159 FONT_DIR=${FONT_DIR/type1/Type1}
160 FONT_DIR=${FONT_DIR/speedo/Speedo}
162 # Set up configure options, wrapped so ebuilds can override if need be
163 [[ -z ${FONT_OPTIONS} ]] && FONT_OPTIONS="--with-fontdir=\"${EPREFIX}/usr/share/fonts/${FONT_DIR}\""
165 [[ ${PN} = font-misc-misc || ${PN} = font-schumacher-misc || ${PN##*-} = 75dpi || ${PN##*-} = 100dpi || ${PN##*-} = cyrillic ]] && IUSE+=" nls"
168 # If we're a driver package, then enable DRIVER case
169 [[ ${PN} == xf86-video-* || ${PN} == xf86-input-* ]] && DRIVER="yes"
171 # @ECLASS-VARIABLE: XORG_STATIC
173 # Enables static-libs useflag. Set to no, if your package gets:
175 # QA: configure: WARNING: unrecognized options: --disable-static
176 : ${XORG_STATIC:="yes"}
178 # Add static-libs useflag where useful.
179 if [[ ${XORG_STATIC} == yes \
181 && ${CATEGORY} != app-doc \
182 && ${CATEGORY} != x11-apps \
183 && ${CATEGORY} != x11-drivers \
184 && ${CATEGORY} != media-fonts \
185 && ${PN} != util-macros \
186 && ${PN} != xbitmaps \
187 && ${PN} != xorg-cf-files \
188 && ${PN/xcursor} = ${PN} ]]; then
192 if [[ ${XORG_MULTILIB} == yes ]]; then
193 DEPEND+=" virtual/pkgconfig[${MULTILIB_USEDEP}]"
195 DEPEND+=" virtual/pkgconfig"
198 # @ECLASS-VARIABLE: XORG_DRI
200 # Possible values are "always" or the value of the useflag DRI capabilities
201 # are required for. Default value is "no"
203 # Eg. XORG_DRI="opengl" will pull all dri dependant deps for opengl useflag
207 x11-base/xorg-server[-minimal]
214 COMMON_DEPEND+=" ${DRI_COMMON_DEPEND}"
217 COMMON_DEPEND+=" ${XORG_DRI}? ( ${DRI_COMMON_DEPEND} )"
221 unset DRI_COMMON_DEPEND
223 if [[ -n "${DRIVER}" ]]; then
225 x11-base/xorg-server[xorg]
228 if [[ -n "${DRIVER}" && ${PN} == xf86-input-* ]]; then
229 DEPEND+=" x11-base/xorg-proto"
231 if [[ -n "${DRIVER}" && ${PN} == xf86-video-* ]]; then
233 x11-libs/libpciaccess
235 DEPEND+=" x11-base/xorg-proto"
238 # @ECLASS-VARIABLE: XORG_DOC
240 # Possible values are "always" or the value of the useflag doc packages
241 # are required for. Default value is "no"
243 # Eg. XORG_DOC="manual" will pull all doc dependant deps for manual useflag
248 || ( app-text/asciidoc dev-ruby/asciidoctor )
251 app-text/docbook-xml-dtd:4.1.2
252 app-text/docbook-xml-dtd:4.2
253 app-text/docbook-xml-dtd:4.3
260 DEPEND+=" ${DOC_DEPEND}"
263 DEPEND+=" ${XORG_DOC}? ( ${DOC_DEPEND} )"
269 if [[ ${DRIVER} == yes ]]; then
274 RDEPEND+=" x11-base/xorg-server:="
279 DEPEND+=" ${COMMON_DEPEND}"
280 RDEPEND+=" ${COMMON_DEPEND}"
283 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: DEPEND=${DEPEND}"
284 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: RDEPEND=${RDEPEND}"
285 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: PDEPEND=${PDEPEND}"
287 # @FUNCTION: xorg-2_pkg_setup
289 # Setup prefix compat
291 debug-print-function ${FUNCNAME} "$@"
293 [[ ${FONT} == yes ]] && font_pkg_setup "$@"
296 # @FUNCTION: xorg-2_src_unpack
298 # Simply unpack source code.
299 xorg-2_src_unpack() {
300 debug-print-function ${FUNCNAME} "$@"
302 if [[ -n ${GIT_ECLASS} ]]; then
308 [[ -n ${FONT_OPTIONS} ]] && einfo "Detected font directory: ${FONT_DIR}"
311 # @FUNCTION: xorg-2_patch_source
314 xorg-2_patch_source() {
315 debug-print-function ${FUNCNAME} "$@"
317 # Use standardized names and locations with bulk patching
318 # Patch directory is ${WORKDIR}/patch
319 # See epatch() in eutils.eclass for more documentation
320 EPATCH_SUFFIX=${EPATCH_SUFFIX:=patch}
322 [[ -d "${EPATCH_SOURCE}" ]] && epatch
325 # @FUNCTION: xorg-2_reconf_source
327 # Run eautoreconf if necessary, and run elibtoolize.
328 xorg-2_reconf_source() {
329 debug-print-function ${FUNCNAME} "$@"
333 # some hosts need full eautoreconf
334 [[ -e "./configure.ac" || -e "./configure.in" ]] \
335 && AUTOTOOLS_AUTORECONF=1
338 # elibtoolize required for BSD
339 [[ ${XORG_EAUTORECONF} != no && ( -e "./configure.ac" || -e "./configure.in" ) ]] \
340 && AUTOTOOLS_AUTORECONF=1
345 # @FUNCTION: xorg-2_src_prepare
347 # Prepare a package after unpacking, performing all X-related tasks.
348 xorg-2_src_prepare() {
349 debug-print-function ${FUNCNAME} "$@"
353 autotools-utils_src_prepare "$@"
356 # @FUNCTION: xorg-2_font_configure
358 # If a font package, perform any necessary configuration steps
359 xorg-2_font_configure() {
360 debug-print-function ${FUNCNAME} "$@"
362 if has nls ${IUSE//+} && ! use nls; then
363 if grep -q -s "disable-all-encodings" ${ECONF_SOURCE:-.}/configure; then
365 --disable-all-encodings
390 # @FUNCTION: xorg-2_flags_setup
392 # Set up CFLAGS for a debug build
393 xorg-2_flags_setup() {
394 debug-print-function ${FUNCNAME} "$@"
396 # Win32 require special define
397 [[ ${CHOST} == *-winnt* ]] && append-cppflags -DWIN32 -D__STDC__
399 [[ ${PN} = xorg-server || -n ${DRIVER} ]] && append-ldflags -Wl,-z,lazy
401 # Quite few libraries fail on runtime without these:
402 if has static-libs ${IUSE//+}; then
403 filter-flags -Wl,-Bdirect
404 filter-ldflags -Bdirect
405 filter-ldflags -Wl,-Bdirect
409 # @FUNCTION: xorg-2_src_configure
411 # Perform any necessary pre-configuration steps, then run configure
412 xorg-2_src_configure() {
413 debug-print-function ${FUNCNAME} "$@"
417 # @VARIABLE: XORG_CONFIGURE_OPTIONS
419 # Array of an additional options to pass to configure.
421 if [[ $(declare -p XORG_CONFIGURE_OPTIONS 2>&-) != "declare -a"* ]]; then
422 # fallback to CONFIGURE_OPTIONS, deprecated.
423 if [[ -n "${CONFIGURE_OPTIONS}" ]]; then
424 eqawarn "CONFIGURE_OPTIONS are deprecated. Please migrate to XORG_CONFIGURE_OPTIONS"
425 eqawarn "to preserve namespace."
428 local xorgconfadd=(${CONFIGURE_OPTIONS} ${XORG_CONFIGURE_OPTIONS})
430 local xorgconfadd=("${XORG_CONFIGURE_OPTIONS[@]}")
433 [[ -n "${FONT}" ]] && xorg-2_font_configure
435 # Check if package supports disabling of dep tracking
436 # Fixes warnings like:
437 # WARNING: unrecognized options: --disable-dependency-tracking
438 if grep -q -s "disable-depencency-tracking" ${ECONF_SOURCE:-.}/configure; then
439 local dep_track="--disable-dependency-tracking"
442 # Check if package supports disabling of selective -Werror=...
443 if grep -q -s "disable-selective-werror" ${ECONF_SOURCE:-.}/configure; then
444 local selective_werror="--disable-selective-werror"
454 if [[ ${XORG_MULTILIB} == yes ]]; then
455 autotools-multilib_src_configure "$@"
457 autotools-utils_src_configure "$@"
461 # @FUNCTION: xorg-2_src_compile
463 # Compile a package, performing all X-related tasks.
464 xorg-2_src_compile() {
465 debug-print-function ${FUNCNAME} "$@"
467 if [[ ${XORG_MULTILIB} == yes ]]; then
468 autotools-multilib_src_compile "$@"
470 autotools-utils_src_compile "$@"
474 # @FUNCTION: xorg-2_src_install
476 # Install a built package to ${D}, performing any necessary steps.
477 # Creates a ChangeLog from git if using live ebuilds.
478 xorg-2_src_install() {
479 debug-print-function ${FUNCNAME} "$@"
481 local install_args=( docdir="${EPREFIX}/usr/share/doc/${PF}" )
483 if [[ ${XORG_MULTILIB} == yes ]]; then
484 autotools-multilib_src_install "${install_args[@]}"
486 autotools-utils_src_install "${install_args[@]}"
489 if [[ -n ${GIT_ECLASS} ]]; then
490 pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" > /dev/null || die
491 git log ${EGIT_COMMIT} > "${S}"/ChangeLog
492 popd > /dev/null || die
495 if [[ -e "${S}"/ChangeLog ]]; then
496 dodoc "${S}"/ChangeLog || die "dodoc failed"
499 # Don't install libtool archives (even for modules)
500 find "${D}" -type f -name '*.la' -delete || die
502 [[ -n ${FONT} ]] && remove_font_metadata
505 # @FUNCTION: xorg-2_pkg_postinst
507 # Run X-specific post-installation tasks on the live filesystem. The
508 # only task right now is some setup for font packages.
509 xorg-2_pkg_postinst() {
510 debug-print-function ${FUNCNAME} "$@"
512 if [[ -n ${FONT} ]]; then
515 font_pkg_postinst "$@"
517 ewarn "Installed fonts changed. Run 'xset fp rehash' if you are using non-fontconfig applications."
521 # @FUNCTION: xorg-2_pkg_postrm
523 # Run X-specific post-removal tasks on the live filesystem. The only
524 # task right now is some cleanup for font packages.
525 xorg-2_pkg_postrm() {
526 debug-print-function ${FUNCNAME} "$@"
528 if [[ -n ${FONT} ]]; then
529 # if we're doing an upgrade, postinst will do
530 if [[ -z ${REPLACED_BY_VERSION} ]]; then
538 # @FUNCTION: remove_font_metadata
540 # Don't let the package install generated font files that may overlap
541 # with other packages. Instead, they're generated in pkg_postinst().
542 remove_font_metadata() {
543 debug-print-function ${FUNCNAME} "$@"
545 if [[ ${FONT_DIR} != Speedo && ${FONT_DIR} != CID ]]; then
546 einfo "Removing font metadata"
547 rm -rf "${ED}"/usr/share/fonts/${FONT_DIR}/fonts.{scale,dir,cache-1}
551 # @FUNCTION: create_fonts_scale
553 # Create fonts.scale file, used by the old server-side fonts subsystem.
554 create_fonts_scale() {
555 debug-print-function ${FUNCNAME} "$@"
557 if [[ ${FONT_DIR} != Speedo && ${FONT_DIR} != CID ]]; then
558 ebegin "Generating fonts.scale"
560 -a "${EROOT}/usr/share/fonts/encodings/encodings.dir" \
561 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"
566 # @FUNCTION: create_fonts_dir
568 # Create fonts.dir file, used by the old server-side fonts subsystem.
570 debug-print-function ${FUNCNAME} "$@"
572 ebegin "Generating fonts.dir"
574 -e "${EROOT}"/usr/share/fonts/encodings \
575 -e "${EROOT}"/usr/share/fonts/encodings/large \
576 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"