dev-perl/IO-stringy: mark s390 stable
[gentoo.git] / eclass / xorg-2.eclass
1 # Copyright 1999-2017 Gentoo Foundation
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: 3 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 [[ ${PN} == font* \
32         && ${CATEGORY} = media-fonts \
33         && ${PN} != font-alias \
34         && ${PN} != font-util ]]; then
35         # Activate font code in the rest of the eclass
36         FONT="yes"
37         FONT_ECLASS="font"
38 fi
39
40 # @ECLASS-VARIABLE: XORG_MULTILIB
41 # @DESCRIPTION:
42 # If set to 'yes', the multilib support for package will be enabled. Set
43 # before inheriting this eclass.
44 : ${XORG_MULTILIB:="no"}
45
46 # we need to inherit autotools first to get the deps
47 inherit autotools autotools-utils eutils libtool multilib toolchain-funcs \
48         flag-o-matic ${FONT_ECLASS} ${GIT_ECLASS}
49
50 if [[ ${XORG_MULTILIB} == yes ]]; then
51         inherit autotools-multilib
52 fi
53
54 EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_postinst pkg_postrm"
55 case "${EAPI:-0}" in
56         3|4|5) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare src_configure" ;;
57         *) die "EAPI=${EAPI} is not supported" ;;
58 esac
59
60 # exports must be ALWAYS after inherit
61 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
62
63 IUSE=""
64 HOMEPAGE="https://www.x.org/wiki/ https://cgit.freedesktop.org/"
65
66 # @ECLASS-VARIABLE: XORG_EAUTORECONF
67 # @DESCRIPTION:
68 # If set to 'yes' and configure.ac exists, eautoreconf will run. Set
69 # before inheriting this eclass.
70 : ${XORG_EAUTORECONF:="no"}
71
72 # @ECLASS-VARIABLE: XORG_BASE_INDIVIDUAL_URI
73 # @DESCRIPTION:
74 # Set up SRC_URI for individual modular releases. If set to an empty
75 # string, no SRC_URI will be provided by the eclass.
76 : ${XORG_BASE_INDIVIDUAL_URI="https://www.x.org/releases/individual"}
77
78 # @ECLASS-VARIABLE: XORG_MODULE
79 # @DESCRIPTION:
80 # The subdirectory to download source from. Possible settings are app,
81 # doc, data, util, driver, font, lib, proto, xserver. Set above the
82 # inherit to override the default autoconfigured module.
83 if [[ -z ${XORG_MODULE} ]]; then
84         case ${CATEGORY} in
85                 app-doc)             XORG_MODULE=doc/     ;;
86                 media-fonts)         XORG_MODULE=font/    ;;
87                 x11-apps|x11-wm)     XORG_MODULE=app/     ;;
88                 x11-misc|x11-themes) XORG_MODULE=util/    ;;
89                 x11-base)            XORG_MODULE=xserver/ ;;
90                 x11-drivers)         XORG_MODULE=driver/  ;;
91                 x11-libs)            XORG_MODULE=lib/     ;;
92                 *)                   XORG_MODULE=         ;;
93         esac
94 fi
95
96 # @ECLASS-VARIABLE: XORG_PACKAGE_NAME
97 # @DESCRIPTION:
98 # For git checkout the git repository might differ from package name.
99 # This variable can be used for proper directory specification
100 : ${XORG_PACKAGE_NAME:=${PN}}
101
102 if [[ -n ${GIT_ECLASS} ]]; then
103         : ${EGIT_REPO_URI:="https://anongit.freedesktop.org/git/xorg/${XORG_MODULE}${XORG_PACKAGE_NAME}.git"}
104 elif [[ -n ${XORG_BASE_INDIVIDUAL_URI} ]]; then
105         SRC_URI="${XORG_BASE_INDIVIDUAL_URI}/${XORG_MODULE}${P}.tar.bz2"
106 fi
107
108 : ${SLOT:=0}
109
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)
113 : ${LICENSE:=MIT}
114
115 # Set up autotools shared dependencies
116 # Remember that all versions here MUST be stable
117 XORG_EAUTORECONF_ARCHES="ppc-aix x86-winnt"
118 EAUTORECONF_DEPEND+="
119         >=sys-devel/libtool-2.2.6a
120         sys-devel/m4"
121 if [[ ${PN} != util-macros ]] ; then
122         EAUTORECONF_DEPEND+=" >=x11-misc/util-macros-1.18"
123         # Required even by xorg-server
124         [[ ${PN} == "font-util" ]] || EAUTORECONF_DEPEND+=" >=media-fonts/font-util-1.2.0"
125 fi
126 WANT_AUTOCONF="latest"
127 WANT_AUTOMAKE="latest"
128 for arch in ${XORG_EAUTORECONF_ARCHES}; do
129         EAUTORECONF_DEPENDS+=" ${arch}? ( ${EAUTORECONF_DEPEND} )"
130 done
131 DEPEND+=" ${EAUTORECONF_DEPENDS}"
132 [[ ${XORG_EAUTORECONF} != no ]] && DEPEND+=" ${EAUTORECONF_DEPEND}"
133 unset EAUTORECONF_DEPENDS
134 unset EAUTORECONF_DEPEND
135
136 if [[ ${FONT} == yes ]]; then
137         RDEPEND+=" media-fonts/encodings
138                 x11-apps/mkfontscale
139                 x11-apps/mkfontdir"
140         PDEPEND+=" media-fonts/font-alias"
141         DEPEND+=" >=media-fonts/font-util-1.2.0"
142
143         # @ECLASS-VARIABLE: FONT_DIR
144         # @DESCRIPTION:
145         # If you're creating a font package and the suffix of PN is not equal to
146         # the subdirectory of /usr/share/fonts/ it should install into, set
147         # FONT_DIR to that directory or directories. Set before inheriting this
148         # eclass.
149         [[ -z ${FONT_DIR} ]] && FONT_DIR=${PN##*-}
150
151         # Fix case of font directories
152         FONT_DIR=${FONT_DIR/ttf/TTF}
153         FONT_DIR=${FONT_DIR/otf/OTF}
154         FONT_DIR=${FONT_DIR/type1/Type1}
155         FONT_DIR=${FONT_DIR/speedo/Speedo}
156
157         # Set up configure options, wrapped so ebuilds can override if need be
158         [[ -z ${FONT_OPTIONS} ]] && FONT_OPTIONS="--with-fontdir=\"${EPREFIX}/usr/share/fonts/${FONT_DIR}\""
159
160         [[ ${PN} = font-misc-misc || ${PN} = font-schumacher-misc || ${PN##*-} = 75dpi || ${PN##*-} = 100dpi || ${PN##*-} = cyrillic ]] && IUSE+=" nls"
161 fi
162
163 # If we're a driver package, then enable DRIVER case
164 [[ ${PN} == xf86-video-* || ${PN} == xf86-input-* ]] && DRIVER="yes"
165
166 # @ECLASS-VARIABLE: XORG_STATIC
167 # @DESCRIPTION:
168 # Enables static-libs useflag. Set to no, if your package gets:
169 #
170 # QA: configure: WARNING: unrecognized options: --disable-static
171 : ${XORG_STATIC:="yes"}
172
173 # Add static-libs useflag where usefull.
174 if [[ ${XORG_STATIC} == yes \
175                 && ${FONT} != yes \
176                 && ${CATEGORY} != app-doc \
177                 && ${CATEGORY} != x11-apps \
178                 && ${CATEGORY} != x11-drivers \
179                 && ${CATEGORY} != media-fonts \
180                 && ${PN} != util-macros \
181                 && ${PN} != xbitmaps \
182                 && ${PN} != xorg-cf-files \
183                 && ${PN/xcursor} = ${PN} ]]; then
184         IUSE+=" static-libs"
185 fi
186
187 DEPEND+=" virtual/pkgconfig"
188
189 # @ECLASS-VARIABLE: XORG_DRI
190 # @DESCRIPTION:
191 # Possible values are "always" or the value of the useflag DRI capabilities
192 # are required for. Default value is "no"
193 #
194 # Eg. XORG_DRI="opengl" will pull all dri dependant deps for opengl useflag
195 : ${XORG_DRI:="no"}
196
197 DRI_COMMON_DEPEND="
198         x11-base/xorg-server[-minimal]
199         x11-libs/libdrm
200 "
201 case ${XORG_DRI} in
202         no)
203                 ;;
204         always)
205                 COMMON_DEPEND+=" ${DRI_COMMON_DEPEND}"
206                 ;;
207         *)
208                 COMMON_DEPEND+=" ${XORG_DRI}? ( ${DRI_COMMON_DEPEND} )"
209                 IUSE+=" ${XORG_DRI}"
210                 ;;
211 esac
212 unset DRI_COMMON_DEPEND
213
214 if [[ -n "${DRIVER}" ]]; then
215         COMMON_DEPEND+="
216                 x11-base/xorg-server[xorg]
217         "
218 fi
219 if [[ -n "${DRIVER}" && ${PN} == xf86-input-* ]]; then
220         DEPEND+=" x11-base/xorg-proto"
221 fi
222 if [[ -n "${DRIVER}" && ${PN} == xf86-video-* ]]; then
223         COMMON_DEPEND+="
224                 x11-libs/libpciaccess
225         "
226         DEPEND+=" x11-base/xorg-proto"
227 fi
228
229 # @ECLASS-VARIABLE: XORG_DOC
230 # @DESCRIPTION:
231 # Possible values are "always" or the value of the useflag doc packages
232 # are required for. Default value is "no"
233 #
234 # Eg. XORG_DOC="manual" will pull all doc dependant deps for manual useflag
235 : ${XORG_DOC:="no"}
236
237 DOC_DEPEND="
238         doc? (
239                 app-text/asciidoc
240                 app-text/xmlto
241                 app-doc/doxygen
242                 app-text/docbook-xml-dtd:4.1.2
243                 app-text/docbook-xml-dtd:4.2
244                 app-text/docbook-xml-dtd:4.3
245         )
246 "
247 case ${XORG_DOC} in
248         no)
249                 ;;
250         always)
251                 DEPEND+=" ${DOC_DEPEND}"
252                 ;;
253         *)
254                 DEPEND+=" ${XORG_DOC}? ( ${DOC_DEPEND} )"
255                 IUSE+=" ${XORG_DOC}"
256                 ;;
257 esac
258 unset DOC_DEPEND
259
260 # @ECLASS-VARIABLE: XORG_MODULE_REBUILD
261 # @DESCRIPTION:
262 # Describes whether a package contains modules that need to be rebuilt on
263 # xorg-server upgrade. This has an effect only since EAPI=5.
264 # Possible values are "yes" or "no". Default value is "yes" for packages which
265 # are recognized as DRIVER by this eclass and "no" for all other packages.
266 if [[ "${DRIVER}" == yes ]]; then
267         : ${XORG_MODULE_REBUILD:="yes"}
268 else
269         : ${XORG_MODULE_REBUILD:="no"}
270 fi
271
272 if [[ ${XORG_MODULE_REBUILD} == yes ]]; then
273         case ${EAPI} in
274                 3|4)
275                         ;;
276                 *)
277                         RDEPEND+=" x11-base/xorg-server:="
278                         ;;
279         esac
280 fi
281
282 DEPEND+=" ${COMMON_DEPEND}"
283 RDEPEND+=" ${COMMON_DEPEND}"
284 unset COMMON_DEPEND
285
286 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: DEPEND=${DEPEND}"
287 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: RDEPEND=${RDEPEND}"
288 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: PDEPEND=${PDEPEND}"
289
290 # @FUNCTION: xorg-2_pkg_setup
291 # @DESCRIPTION:
292 # Setup prefix compat
293 xorg-2_pkg_setup() {
294         debug-print-function ${FUNCNAME} "$@"
295
296         [[ ${FONT} == yes ]] && font_pkg_setup "$@"
297 }
298
299 # @FUNCTION: xorg-2_src_unpack
300 # @DESCRIPTION:
301 # Simply unpack source code.
302 xorg-2_src_unpack() {
303         debug-print-function ${FUNCNAME} "$@"
304
305         if [[ -n ${GIT_ECLASS} ]]; then
306                 git-r3_src_unpack
307         else
308                 unpack ${A}
309         fi
310
311         [[ -n ${FONT_OPTIONS} ]] && einfo "Detected font directory: ${FONT_DIR}"
312 }
313
314 # @FUNCTION: xorg-2_patch_source
315 # @DESCRIPTION:
316 # Apply all patches
317 xorg-2_patch_source() {
318         debug-print-function ${FUNCNAME} "$@"
319
320         # Use standardized names and locations with bulk patching
321         # Patch directory is ${WORKDIR}/patch
322         # See epatch() in eutils.eclass for more documentation
323         EPATCH_SUFFIX=${EPATCH_SUFFIX:=patch}
324
325         [[ -d "${EPATCH_SOURCE}" ]] && epatch
326 }
327
328 # @FUNCTION: xorg-2_reconf_source
329 # @DESCRIPTION:
330 # Run eautoreconf if necessary, and run elibtoolize.
331 xorg-2_reconf_source() {
332         debug-print-function ${FUNCNAME} "$@"
333
334         case ${CHOST} in
335                 *-aix* | *-winnt*)
336                         # some hosts need full eautoreconf
337                         [[ -e "./configure.ac" || -e "./configure.in" ]] \
338                                 && AUTOTOOLS_AUTORECONF=1
339                         ;;
340                 *)
341                         # elibtoolize required for BSD
342                         [[ ${XORG_EAUTORECONF} != no && ( -e "./configure.ac" || -e "./configure.in" ) ]] \
343                                 && AUTOTOOLS_AUTORECONF=1
344                         ;;
345         esac
346 }
347
348 # @FUNCTION: xorg-2_src_prepare
349 # @DESCRIPTION:
350 # Prepare a package after unpacking, performing all X-related tasks.
351 xorg-2_src_prepare() {
352         debug-print-function ${FUNCNAME} "$@"
353
354         xorg-2_patch_source
355         xorg-2_reconf_source
356         autotools-utils_src_prepare "$@"
357 }
358
359 # @FUNCTION: xorg-2_font_configure
360 # @DESCRIPTION:
361 # If a font package, perform any necessary configuration steps
362 xorg-2_font_configure() {
363         debug-print-function ${FUNCNAME} "$@"
364
365         if has nls ${IUSE//+} && ! use nls; then
366                 if grep -q -s "disable-all-encodings" ${ECONF_SOURCE:-.}/configure; then
367                         FONT_OPTIONS+="
368                                 --disable-all-encodings
369                                 --enable-iso8859-1"
370                 else
371                         FONT_OPTIONS+="
372                                 --disable-iso8859-2
373                                 --disable-iso8859-3
374                                 --disable-iso8859-4
375                                 --disable-iso8859-5
376                                 --disable-iso8859-6
377                                 --disable-iso8859-7
378                                 --disable-iso8859-8
379                                 --disable-iso8859-9
380                                 --disable-iso8859-10
381                                 --disable-iso8859-11
382                                 --disable-iso8859-12
383                                 --disable-iso8859-13
384                                 --disable-iso8859-14
385                                 --disable-iso8859-15
386                                 --disable-iso8859-16
387                                 --disable-jisx0201
388                                 --disable-koi8-r"
389                 fi
390         fi
391 }
392
393 # @FUNCTION: xorg-2_flags_setup
394 # @DESCRIPTION:
395 # Set up CFLAGS for a debug build
396 xorg-2_flags_setup() {
397         debug-print-function ${FUNCNAME} "$@"
398
399         # Win32 require special define
400         [[ ${CHOST} == *-winnt* ]] && append-cppflags -DWIN32 -D__STDC__
401         # hardened ldflags
402         [[ ${PN} = xorg-server || -n ${DRIVER} ]] && append-ldflags -Wl,-z,lazy
403
404         # Quite few libraries fail on runtime without these:
405         if has static-libs ${IUSE//+}; then
406                 filter-flags -Wl,-Bdirect
407                 filter-ldflags -Bdirect
408                 filter-ldflags -Wl,-Bdirect
409         fi
410 }
411
412 # @FUNCTION: xorg-2_src_configure
413 # @DESCRIPTION:
414 # Perform any necessary pre-configuration steps, then run configure
415 xorg-2_src_configure() {
416         debug-print-function ${FUNCNAME} "$@"
417
418         xorg-2_flags_setup
419
420         # @VARIABLE: XORG_CONFIGURE_OPTIONS
421         # @DESCRIPTION:
422         # Array of an additional options to pass to configure.
423         # @DEFAULT_UNSET
424         if [[ $(declare -p XORG_CONFIGURE_OPTIONS 2>&-) != "declare -a"* ]]; then
425                 # fallback to CONFIGURE_OPTIONS, deprecated.
426                 if [[ -n "${CONFIGURE_OPTIONS}" ]]; then
427                         eqawarn "CONFIGURE_OPTIONS are deprecated. Please migrate to XORG_CONFIGURE_OPTIONS"
428                         eqawarn "to preserve namespace."
429                 fi
430
431                 local xorgconfadd=(${CONFIGURE_OPTIONS} ${XORG_CONFIGURE_OPTIONS})
432         else
433                 local xorgconfadd=("${XORG_CONFIGURE_OPTIONS[@]}")
434         fi
435
436         [[ -n "${FONT}" ]] && xorg-2_font_configure
437
438         # Check if package supports disabling of dep tracking
439         # Fixes warnings like:
440         #    WARNING: unrecognized options: --disable-dependency-tracking
441         if grep -q -s "disable-depencency-tracking" ${ECONF_SOURCE:-.}/configure; then
442                 local dep_track="--disable-dependency-tracking"
443         fi
444
445         # Check if package supports disabling of selective -Werror=...
446         if grep -q -s "disable-selective-werror" ${ECONF_SOURCE:-.}/configure; then
447                 local selective_werror="--disable-selective-werror"
448         fi
449
450         local myeconfargs=(
451                 ${dep_track}
452                 ${selective_werror}
453                 ${FONT_OPTIONS}
454                 "${xorgconfadd[@]}"
455         )
456
457         if [[ ${XORG_MULTILIB} == yes ]]; then
458                 autotools-multilib_src_configure "$@"
459         else
460                 autotools-utils_src_configure "$@"
461         fi
462 }
463
464 # @FUNCTION: xorg-2_src_compile
465 # @DESCRIPTION:
466 # Compile a package, performing all X-related tasks.
467 xorg-2_src_compile() {
468         debug-print-function ${FUNCNAME} "$@"
469
470         if [[ ${XORG_MULTILIB} == yes ]]; then
471                 autotools-multilib_src_compile "$@"
472         else
473                 autotools-utils_src_compile "$@"
474         fi
475 }
476
477 # @FUNCTION: xorg-2_src_install
478 # @DESCRIPTION:
479 # Install a built package to ${D}, performing any necessary steps.
480 # Creates a ChangeLog from git if using live ebuilds.
481 xorg-2_src_install() {
482         debug-print-function ${FUNCNAME} "$@"
483
484         local install_args=( docdir="${EPREFIX}/usr/share/doc/${PF}" )
485
486         if [[ ${XORG_MULTILIB} == yes ]]; then
487                 autotools-multilib_src_install "${install_args[@]}"
488         else
489                 autotools-utils_src_install "${install_args[@]}"
490         fi
491
492         if [[ -n ${GIT_ECLASS} ]]; then
493                 pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" > /dev/null || die
494                 git log ${EGIT_COMMIT} > "${S}"/ChangeLog
495                 popd > /dev/null || die
496         fi
497
498         if [[ -e "${S}"/ChangeLog ]]; then
499                 dodoc "${S}"/ChangeLog || die "dodoc failed"
500         fi
501
502         # Don't install libtool archives (even for modules)
503         prune_libtool_files --all
504
505         [[ -n ${FONT} ]] && remove_font_metadata
506 }
507
508 # @FUNCTION: xorg-2_pkg_postinst
509 # @DESCRIPTION:
510 # Run X-specific post-installation tasks on the live filesystem. The
511 # only task right now is some setup for font packages.
512 xorg-2_pkg_postinst() {
513         debug-print-function ${FUNCNAME} "$@"
514
515         if [[ -n ${FONT} ]]; then
516                 create_fonts_scale
517                 create_fonts_dir
518                 font_pkg_postinst "$@"
519
520                 ewarn "Installed fonts changed. Run 'xset fp rehash' if you are using non-fontconfig applications."
521         fi
522 }
523
524 # @FUNCTION: xorg-2_pkg_postrm
525 # @DESCRIPTION:
526 # Run X-specific post-removal tasks on the live filesystem. The only
527 # task right now is some cleanup for font packages.
528 xorg-2_pkg_postrm() {
529         debug-print-function ${FUNCNAME} "$@"
530
531         if [[ -n ${FONT} ]]; then
532                 # if we're doing an upgrade, postinst will do
533                 if [[ ${EAPI} -lt 4 || -z ${REPLACED_BY_VERSION} ]]; then
534                         create_fonts_scale
535                         create_fonts_dir
536                         font_pkg_postrm "$@"
537                 fi
538         fi
539 }
540
541 # @FUNCTION: remove_font_metadata
542 # @DESCRIPTION:
543 # Don't let the package install generated font files that may overlap
544 # with other packages. Instead, they're generated in pkg_postinst().
545 remove_font_metadata() {
546         debug-print-function ${FUNCNAME} "$@"
547
548         if [[ ${FONT_DIR} != Speedo && ${FONT_DIR} != CID ]]; then
549                 einfo "Removing font metadata"
550                 rm -rf "${ED}"/usr/share/fonts/${FONT_DIR}/fonts.{scale,dir,cache-1}
551         fi
552 }
553
554 # @FUNCTION: create_fonts_scale
555 # @DESCRIPTION:
556 # Create fonts.scale file, used by the old server-side fonts subsystem.
557 create_fonts_scale() {
558         debug-print-function ${FUNCNAME} "$@"
559
560         if [[ ${FONT_DIR} != Speedo && ${FONT_DIR} != CID ]]; then
561                 ebegin "Generating fonts.scale"
562                         mkfontscale \
563                                 -a "${EROOT}/usr/share/fonts/encodings/encodings.dir" \
564                                 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"
565                 eend $?
566         fi
567 }
568
569 # @FUNCTION: create_fonts_dir
570 # @DESCRIPTION:
571 # Create fonts.dir file, used by the old server-side fonts subsystem.
572 create_fonts_dir() {
573         debug-print-function ${FUNCNAME} "$@"
574
575         ebegin "Generating fonts.dir"
576                         mkfontdir \
577                                 -e "${EROOT}"/usr/share/fonts/encodings \
578                                 -e "${EROOT}"/usr/share/fonts/encodings/large \
579                                 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"
580         eend $?
581 }