dev-cpp/pangomm: stable 2.42.1 for hppa, bug #717144
[gentoo.git] / eclass / xorg-2.eclass
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: xorg-2.eclass
5 # @MAINTAINER:
6 # x11@gentoo.org
7 # @AUTHOR:
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.
12 # @DESCRIPTION:
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.
17 #
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.
22
23 GIT_ECLASS=""
24 if [[ ${PV} == *9999* ]]; then
25         GIT_ECLASS="git-r3"
26         XORG_EAUTORECONF="yes"
27 fi
28
29 # If we're a font package, but not the font.alias one
30 FONT_ECLASS=""
31 if [[ ${CATEGORY} = media-fonts ]]; then
32         case ${PN} in
33         font-alias|font-util)
34                 ;;
35         font*)
36                 # Activate font code in the rest of the eclass
37                 FONT="yes"
38                 FONT_ECLASS="font"
39                 ;;
40         esac
41 fi
42
43 # @ECLASS-VARIABLE: XORG_MULTILIB
44 # @DESCRIPTION:
45 # If set to 'yes', the multilib support for package will be enabled. Set
46 # before inheriting this eclass.
47 : ${XORG_MULTILIB:="no"}
48
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}
52
53 if [[ ${XORG_MULTILIB} == yes ]]; then
54         inherit autotools-multilib
55 fi
56
57 EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_postinst pkg_postrm"
58 case "${EAPI:-0}" in
59         4|5) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare src_configure" ;;
60         *) die "EAPI=${EAPI} is not supported" ;;
61 esac
62
63 # exports must be ALWAYS after inherit
64 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
65
66 IUSE=""
67
68 # @ECLASS-VARIABLE: XORG_EAUTORECONF
69 # @DESCRIPTION:
70 # If set to 'yes' and configure.ac exists, eautoreconf will run. Set
71 # before inheriting this eclass.
72 : ${XORG_EAUTORECONF:="no"}
73
74 # @ECLASS-VARIABLE: XORG_BASE_INDIVIDUAL_URI
75 # @DESCRIPTION:
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"}
79
80 # @ECLASS-VARIABLE: XORG_MODULE
81 # @DESCRIPTION:
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
87         case ${CATEGORY} in
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/     ;;
95                 *)                   XORG_MODULE=         ;;
96         esac
97 fi
98
99 # @ECLASS-VARIABLE: XORG_PACKAGE_NAME
100 # @DESCRIPTION:
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}}
104
105 HOMEPAGE="https://www.x.org/wiki/ https://gitlab.freedesktop.org/xorg/${XORG_MODULE}${XORG_PACKAGE_NAME}"
106
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"
111 fi
112
113 : ${SLOT:=0}
114
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)
118 : ${LICENSE:=MIT}
119
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
125         sys-devel/m4"
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"
130 fi
131 WANT_AUTOCONF="latest"
132 WANT_AUTOMAKE="latest"
133 for arch in ${XORG_EAUTORECONF_ARCHES}; do
134         EAUTORECONF_DEPENDS+=" ${arch}? ( ${EAUTORECONF_DEPEND} )"
135 done
136 DEPEND+=" ${EAUTORECONF_DEPENDS}"
137 [[ ${XORG_EAUTORECONF} != no ]] && DEPEND+=" ${EAUTORECONF_DEPEND}"
138 unset EAUTORECONF_DEPENDS
139 unset EAUTORECONF_DEPEND
140
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"
147
148         # @ECLASS-VARIABLE: FONT_DIR
149         # @DESCRIPTION:
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
153         # eclass.
154         [[ -z ${FONT_DIR} ]] && FONT_DIR=${PN##*-}
155
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}
161
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}\""
164
165         [[ ${PN} = font-misc-misc || ${PN} = font-schumacher-misc || ${PN##*-} = 75dpi || ${PN##*-} = 100dpi || ${PN##*-} = cyrillic ]] && IUSE+=" nls"
166 fi
167
168 # If we're a driver package, then enable DRIVER case
169 [[ ${PN} == xf86-video-* || ${PN} == xf86-input-* ]] && DRIVER="yes"
170
171 # @ECLASS-VARIABLE: XORG_STATIC
172 # @DESCRIPTION:
173 # Enables static-libs useflag. Set to no, if your package gets:
174 #
175 # QA: configure: WARNING: unrecognized options: --disable-static
176 : ${XORG_STATIC:="yes"}
177
178 # Add static-libs useflag where useful.
179 if [[ ${XORG_STATIC} == yes \
180                 && ${FONT} != 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
189         IUSE+=" static-libs"
190 fi
191
192 if [[ ${XORG_MULTILIB} == yes ]]; then
193         DEPEND+=" virtual/pkgconfig[${MULTILIB_USEDEP}]"
194 else
195         DEPEND+=" virtual/pkgconfig"
196 fi
197
198 # @ECLASS-VARIABLE: XORG_DRI
199 # @DESCRIPTION:
200 # Possible values are "always" or the value of the useflag DRI capabilities
201 # are required for. Default value is "no"
202 #
203 # Eg. XORG_DRI="opengl" will pull all dri dependant deps for opengl useflag
204 : ${XORG_DRI:="no"}
205
206 DRI_COMMON_DEPEND="
207         x11-base/xorg-server[-minimal]
208         x11-libs/libdrm
209 "
210 case ${XORG_DRI} in
211         no)
212                 ;;
213         always)
214                 COMMON_DEPEND+=" ${DRI_COMMON_DEPEND}"
215                 ;;
216         *)
217                 COMMON_DEPEND+=" ${XORG_DRI}? ( ${DRI_COMMON_DEPEND} )"
218                 IUSE+=" ${XORG_DRI}"
219                 ;;
220 esac
221 unset DRI_COMMON_DEPEND
222
223 if [[ -n "${DRIVER}" ]]; then
224         COMMON_DEPEND+="
225                 x11-base/xorg-server[xorg]
226         "
227 fi
228 if [[ -n "${DRIVER}" && ${PN} == xf86-input-* ]]; then
229         DEPEND+=" x11-base/xorg-proto"
230 fi
231 if [[ -n "${DRIVER}" && ${PN} == xf86-video-* ]]; then
232         COMMON_DEPEND+="
233                 x11-libs/libpciaccess
234         "
235         DEPEND+=" x11-base/xorg-proto"
236 fi
237
238 # @ECLASS-VARIABLE: XORG_DOC
239 # @DESCRIPTION:
240 # Possible values are "always" or the value of the useflag doc packages
241 # are required for. Default value is "no"
242 #
243 # Eg. XORG_DOC="manual" will pull all doc dependant deps for manual useflag
244 : ${XORG_DOC:="no"}
245
246 DOC_DEPEND="
247         doc? (
248                 || ( app-text/asciidoc dev-ruby/asciidoctor )
249                 app-text/xmlto
250                 app-doc/doxygen
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
254         )
255 "
256 case ${XORG_DOC} in
257         no)
258                 ;;
259         always)
260                 DEPEND+=" ${DOC_DEPEND}"
261                 ;;
262         *)
263                 DEPEND+=" ${XORG_DOC}? ( ${DOC_DEPEND} )"
264                 IUSE+=" ${XORG_DOC}"
265                 ;;
266 esac
267 unset DOC_DEPEND
268
269 if [[ ${DRIVER} == yes ]]; then
270         case ${EAPI} in
271                 4)
272                         ;;
273                 *)
274                         RDEPEND+=" x11-base/xorg-server:="
275                         ;;
276         esac
277 fi
278
279 DEPEND+=" ${COMMON_DEPEND}"
280 RDEPEND+=" ${COMMON_DEPEND}"
281 unset COMMON_DEPEND
282
283 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: DEPEND=${DEPEND}"
284 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: RDEPEND=${RDEPEND}"
285 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: PDEPEND=${PDEPEND}"
286
287 # @FUNCTION: xorg-2_pkg_setup
288 # @DESCRIPTION:
289 # Setup prefix compat
290 xorg-2_pkg_setup() {
291         debug-print-function ${FUNCNAME} "$@"
292
293         [[ ${FONT} == yes ]] && font_pkg_setup "$@"
294 }
295
296 # @FUNCTION: xorg-2_src_unpack
297 # @DESCRIPTION:
298 # Simply unpack source code.
299 xorg-2_src_unpack() {
300         debug-print-function ${FUNCNAME} "$@"
301
302         if [[ -n ${GIT_ECLASS} ]]; then
303                 git-r3_src_unpack
304         else
305                 unpack ${A}
306         fi
307
308         [[ -n ${FONT_OPTIONS} ]] && einfo "Detected font directory: ${FONT_DIR}"
309 }
310
311 # @FUNCTION: xorg-2_patch_source
312 # @DESCRIPTION:
313 # Apply all patches
314 xorg-2_patch_source() {
315         debug-print-function ${FUNCNAME} "$@"
316
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}
321
322         [[ -d "${EPATCH_SOURCE}" ]] && epatch
323 }
324
325 # @FUNCTION: xorg-2_reconf_source
326 # @DESCRIPTION:
327 # Run eautoreconf if necessary, and run elibtoolize.
328 xorg-2_reconf_source() {
329         debug-print-function ${FUNCNAME} "$@"
330
331         case ${CHOST} in
332                 *-aix* | *-winnt*)
333                         # some hosts need full eautoreconf
334                         [[ -e "./configure.ac" || -e "./configure.in" ]] \
335                                 && AUTOTOOLS_AUTORECONF=1
336                         ;;
337                 *)
338                         # elibtoolize required for BSD
339                         [[ ${XORG_EAUTORECONF} != no && ( -e "./configure.ac" || -e "./configure.in" ) ]] \
340                                 && AUTOTOOLS_AUTORECONF=1
341                         ;;
342         esac
343 }
344
345 # @FUNCTION: xorg-2_src_prepare
346 # @DESCRIPTION:
347 # Prepare a package after unpacking, performing all X-related tasks.
348 xorg-2_src_prepare() {
349         debug-print-function ${FUNCNAME} "$@"
350
351         xorg-2_patch_source
352         xorg-2_reconf_source
353         autotools-utils_src_prepare "$@"
354 }
355
356 # @FUNCTION: xorg-2_font_configure
357 # @DESCRIPTION:
358 # If a font package, perform any necessary configuration steps
359 xorg-2_font_configure() {
360         debug-print-function ${FUNCNAME} "$@"
361
362         if has nls ${IUSE//+} && ! use nls; then
363                 if grep -q -s "disable-all-encodings" ${ECONF_SOURCE:-.}/configure; then
364                         FONT_OPTIONS+="
365                                 --disable-all-encodings
366                                 --enable-iso8859-1"
367                 else
368                         FONT_OPTIONS+="
369                                 --disable-iso8859-2
370                                 --disable-iso8859-3
371                                 --disable-iso8859-4
372                                 --disable-iso8859-5
373                                 --disable-iso8859-6
374                                 --disable-iso8859-7
375                                 --disable-iso8859-8
376                                 --disable-iso8859-9
377                                 --disable-iso8859-10
378                                 --disable-iso8859-11
379                                 --disable-iso8859-12
380                                 --disable-iso8859-13
381                                 --disable-iso8859-14
382                                 --disable-iso8859-15
383                                 --disable-iso8859-16
384                                 --disable-jisx0201
385                                 --disable-koi8-r"
386                 fi
387         fi
388 }
389
390 # @FUNCTION: xorg-2_flags_setup
391 # @DESCRIPTION:
392 # Set up CFLAGS for a debug build
393 xorg-2_flags_setup() {
394         debug-print-function ${FUNCNAME} "$@"
395
396         # Win32 require special define
397         [[ ${CHOST} == *-winnt* ]] && append-cppflags -DWIN32 -D__STDC__
398         # hardened ldflags
399         [[ ${PN} = xorg-server || -n ${DRIVER} ]] && append-ldflags -Wl,-z,lazy
400
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
406         fi
407 }
408
409 # @FUNCTION: xorg-2_src_configure
410 # @DESCRIPTION:
411 # Perform any necessary pre-configuration steps, then run configure
412 xorg-2_src_configure() {
413         debug-print-function ${FUNCNAME} "$@"
414
415         xorg-2_flags_setup
416
417         # @VARIABLE: XORG_CONFIGURE_OPTIONS
418         # @DESCRIPTION:
419         # Array of an additional options to pass to configure.
420         # @DEFAULT_UNSET
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."
426                 fi
427
428                 local xorgconfadd=(${CONFIGURE_OPTIONS} ${XORG_CONFIGURE_OPTIONS})
429         else
430                 local xorgconfadd=("${XORG_CONFIGURE_OPTIONS[@]}")
431         fi
432
433         [[ -n "${FONT}" ]] && xorg-2_font_configure
434
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"
440         fi
441
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"
445         fi
446
447         local myeconfargs=(
448                 ${dep_track}
449                 ${selective_werror}
450                 ${FONT_OPTIONS}
451                 "${xorgconfadd[@]}"
452         )
453
454         if [[ ${XORG_MULTILIB} == yes ]]; then
455                 autotools-multilib_src_configure "$@"
456         else
457                 autotools-utils_src_configure "$@"
458         fi
459 }
460
461 # @FUNCTION: xorg-2_src_compile
462 # @DESCRIPTION:
463 # Compile a package, performing all X-related tasks.
464 xorg-2_src_compile() {
465         debug-print-function ${FUNCNAME} "$@"
466
467         if [[ ${XORG_MULTILIB} == yes ]]; then
468                 autotools-multilib_src_compile "$@"
469         else
470                 autotools-utils_src_compile "$@"
471         fi
472 }
473
474 # @FUNCTION: xorg-2_src_install
475 # @DESCRIPTION:
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} "$@"
480
481         local install_args=( docdir="${EPREFIX}/usr/share/doc/${PF}" )
482
483         if [[ ${XORG_MULTILIB} == yes ]]; then
484                 autotools-multilib_src_install "${install_args[@]}"
485         else
486                 autotools-utils_src_install "${install_args[@]}"
487         fi
488
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
493         fi
494
495         if [[ -e "${S}"/ChangeLog ]]; then
496                 dodoc "${S}"/ChangeLog || die "dodoc failed"
497         fi
498
499         # Don't install libtool archives (even for modules)
500         find "${D}" -type f -name '*.la' -delete || die
501
502         [[ -n ${FONT} ]] && remove_font_metadata
503 }
504
505 # @FUNCTION: xorg-2_pkg_postinst
506 # @DESCRIPTION:
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} "$@"
511
512         if [[ -n ${FONT} ]]; then
513                 create_fonts_scale
514                 create_fonts_dir
515                 font_pkg_postinst "$@"
516
517                 ewarn "Installed fonts changed. Run 'xset fp rehash' if you are using non-fontconfig applications."
518         fi
519 }
520
521 # @FUNCTION: xorg-2_pkg_postrm
522 # @DESCRIPTION:
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} "$@"
527
528         if [[ -n ${FONT} ]]; then
529                 # if we're doing an upgrade, postinst will do
530                 if [[ -z ${REPLACED_BY_VERSION} ]]; then
531                         create_fonts_scale
532                         create_fonts_dir
533                         font_pkg_postrm "$@"
534                 fi
535         fi
536 }
537
538 # @FUNCTION: remove_font_metadata
539 # @DESCRIPTION:
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} "$@"
544
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}
548         fi
549 }
550
551 # @FUNCTION: create_fonts_scale
552 # @DESCRIPTION:
553 # Create fonts.scale file, used by the old server-side fonts subsystem.
554 create_fonts_scale() {
555         debug-print-function ${FUNCNAME} "$@"
556
557         if [[ ${FONT_DIR} != Speedo && ${FONT_DIR} != CID ]]; then
558                 ebegin "Generating fonts.scale"
559                         mkfontscale \
560                                 -a "${EROOT}/usr/share/fonts/encodings/encodings.dir" \
561                                 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"
562                 eend $?
563         fi
564 }
565
566 # @FUNCTION: create_fonts_dir
567 # @DESCRIPTION:
568 # Create fonts.dir file, used by the old server-side fonts subsystem.
569 create_fonts_dir() {
570         debug-print-function ${FUNCNAME} "$@"
571
572         ebegin "Generating fonts.dir"
573                         mkfontdir \
574                                 -e "${EROOT}"/usr/share/fonts/encodings \
575                                 -e "${EROOT}"/usr/share/fonts/encodings/large \
576                                 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"
577         eend $?
578 }