app-emulation/vagrant: drop ruby23 comepletely
[gentoo.git] / eclass / xorg-3.eclass
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: xorg-3.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 # Author: Matt Turner <mattst88@gentoo.org>
11 # @SUPPORTED_EAPIS: 7
12 # @BLURB: Reduces code duplication in the modularized X11 ebuilds.
13 # @DESCRIPTION:
14 # This eclass makes trivial X ebuilds possible for apps, drivers,
15 # and more. Many things that would normally be done in various functions
16 # can be accessed by setting variables instead, such as patching,
17 # running eautoreconf, passing options to configure and installing docs.
18 #
19 # All you need to do in a basic ebuild is inherit this eclass and set
20 # DESCRIPTION, KEYWORDS and RDEPEND/DEPEND. If your package is hosted
21 # with the other X packages, you don't need to set SRC_URI. Pretty much
22 # everything else should be automatic.
23
24 GIT_ECLASS=""
25 if [[ ${PV} == *9999* ]]; then
26         GIT_ECLASS="git-r3"
27         XORG_EAUTORECONF="yes"
28 fi
29
30 # @ECLASS-VARIABLE: XORG_MULTILIB
31 # @DESCRIPTION:
32 # If set to 'yes', the multilib support for package will be enabled. Set
33 # before inheriting this eclass.
34 : ${XORG_MULTILIB:="no"}
35
36 # we need to inherit autotools first to get the deps
37 inherit autotools libtool multilib toolchain-funcs flag-o-matic ${GIT_ECLASS}
38
39 if [[ ${XORG_MULTILIB} == yes ]]; then
40         inherit multilib-minimal
41 fi
42
43 EXPORTED_FUNCTIONS="src_prepare src_configure src_unpack src_compile src_install"
44 case "${EAPI:-0}" in
45         7) ;;
46         *) die "EAPI=${EAPI} is not supported" ;;
47 esac
48
49 # exports must be ALWAYS after inherit
50 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
51
52 IUSE=""
53
54 # @ECLASS-VARIABLE: XORG_EAUTORECONF
55 # @DESCRIPTION:
56 # If set to 'yes' and configure.ac exists, eautoreconf will run. Set
57 # before inheriting this eclass.
58 : ${XORG_EAUTORECONF:="no"}
59
60 # @ECLASS-VARIABLE: XORG_BASE_INDIVIDUAL_URI
61 # @DESCRIPTION:
62 # Set up SRC_URI for individual modular releases. If set to an empty
63 # string, no SRC_URI will be provided by the eclass.
64 : ${XORG_BASE_INDIVIDUAL_URI="https://www.x.org/releases/individual"}
65
66 # @ECLASS-VARIABLE: XORG_MODULE
67 # @DESCRIPTION:
68 # The subdirectory to download source from. Possible settings are app,
69 # doc, data, util, driver, lib, proto, xserver. Set above the
70 # inherit to override the default autoconfigured module.
71 : ${XORG_MODULE:="auto"}
72 if [[ ${XORG_MODULE} == auto ]]; then
73         case ${CATEGORY} in
74                 app-doc)             XORG_MODULE=doc/     ;;
75                 x11-apps|x11-wm)     XORG_MODULE=app/     ;;
76                 x11-misc|x11-themes) XORG_MODULE=util/    ;;
77                 x11-base)            XORG_MODULE=xserver/ ;;
78                 x11-drivers)         XORG_MODULE=driver/  ;;
79                 x11-libs)            XORG_MODULE=lib/     ;;
80                 *)                   XORG_MODULE=         ;;
81         esac
82 fi
83
84 # @ECLASS-VARIABLE: XORG_PACKAGE_NAME
85 # @DESCRIPTION:
86 # For git checkout the git repository might differ from package name.
87 # This variable can be used for proper directory specification
88 : ${XORG_PACKAGE_NAME:=${PN}}
89
90 HOMEPAGE="https://www.x.org/wiki/ https://gitlab.freedesktop.org/xorg/${XORG_MODULE}${XORG_PACKAGE_NAME}"
91
92 if [[ -n ${GIT_ECLASS} ]]; then
93         : ${EGIT_REPO_URI:="https://gitlab.freedesktop.org/xorg/${XORG_MODULE}${XORG_PACKAGE_NAME}.git"}
94 elif [[ -n ${XORG_BASE_INDIVIDUAL_URI} ]]; then
95         SRC_URI="${XORG_BASE_INDIVIDUAL_URI}/${XORG_MODULE}${P}.tar.bz2"
96 fi
97
98 : ${SLOT:=0}
99
100 # Set the license for the package. This can be overridden by setting
101 # LICENSE after the inherit. Nearly all FreeDesktop-hosted X packages
102 # are under the MIT license. (This is what Red Hat does in their rpms)
103 : ${LICENSE:=MIT}
104
105 # Set up autotools shared dependencies
106 # Remember that all versions here MUST be stable
107 XORG_EAUTORECONF_ARCHES="ppc-aix x86-winnt"
108 EAUTORECONF_DEPEND+="
109         >=sys-devel/libtool-2.2.6a
110         sys-devel/m4"
111 if [[ ${PN} != util-macros ]] ; then
112         EAUTORECONF_DEPEND+=" >=x11-misc/util-macros-1.18 >=media-fonts/font-util-1.2.0"
113 fi
114 WANT_AUTOCONF="latest"
115 WANT_AUTOMAKE="latest"
116 for arch in ${XORG_EAUTORECONF_ARCHES}; do
117         EAUTORECONF_DEPENDS+=" ${arch}? ( ${EAUTORECONF_DEPEND} )"
118 done
119 DEPEND+=" ${EAUTORECONF_DEPENDS}"
120 [[ ${XORG_EAUTORECONF} != no ]] && BDEPEND+=" ${EAUTORECONF_DEPEND}"
121 unset EAUTORECONF_DEPENDS
122 unset EAUTORECONF_DEPEND
123
124 # @ECLASS-VARIABLE: XORG_STATIC
125 # @DESCRIPTION:
126 # Enables static-libs useflag. Set to no, if your package gets:
127 #
128 # QA: configure: WARNING: unrecognized options: --disable-static
129 : ${XORG_STATIC:="yes"}
130
131 # Add static-libs useflag where useful.
132 if [[ ${XORG_STATIC} == yes \
133                 && ${CATEGORY} != app-doc \
134                 && ${CATEGORY} != x11-apps \
135                 && ${CATEGORY} != x11-drivers \
136                 && ${PN} != util-macros \
137                 && ${PN} != xbitmaps \
138                 && ${PN} != xorg-cf-files \
139                 && ${PN/xcursor} = ${PN} ]]; then
140         IUSE+=" static-libs"
141 fi
142
143 if [[ ${XORG_MULTILIB} == yes ]]; then
144         BDEPEND+=" virtual/pkgconfig[${MULTILIB_USEDEP}]"
145 else
146         BDEPEND+=" virtual/pkgconfig"
147 fi
148
149 # @ECLASS-VARIABLE: XORG_DRI
150 # @DESCRIPTION:
151 # Possible values are "always" or the value of the useflag DRI capabilities
152 # are required for. Default value is "no"
153 #
154 # Eg. XORG_DRI="opengl" will pull all dri dependent deps for opengl useflag
155 : ${XORG_DRI:="no"}
156
157 DRI_COMMON_DEPEND="
158         x11-base/xorg-server[-minimal]
159         x11-libs/libdrm
160 "
161 case ${XORG_DRI} in
162         no)
163                 ;;
164         always)
165                 COMMON_DEPEND+=" ${DRI_COMMON_DEPEND}"
166                 ;;
167         *)
168                 COMMON_DEPEND+=" ${XORG_DRI}? ( ${DRI_COMMON_DEPEND} )"
169                 IUSE+=" ${XORG_DRI}"
170                 ;;
171 esac
172 unset DRI_COMMON_DEPEND
173
174 if [[ ${PN} == xf86-video-* || ${PN} == xf86-input-* ]]; then
175         DEPEND+="  x11-base/xorg-proto"
176         RDEPEND+=" x11-base/xorg-server:="
177         COMMON_DEPEND+=" >=x11-base/xorg-server-1.20[xorg]"
178         [[ ${PN} == xf86-video-* ]] && COMMON_DEPEND+=" >=x11-libs/libpciaccess-0.14"
179 fi
180
181
182 # @ECLASS-VARIABLE: XORG_DOC
183 # @DESCRIPTION:
184 # Possible values are "always" or the value of the useflag doc packages
185 # are required for. Default value is "no"
186 #
187 # Eg. XORG_DOC="manual" will pull all doc dependent deps for manual useflag
188 : ${XORG_DOC:="no"}
189
190 DOC_DEPEND="
191         doc? (
192                 || ( app-text/asciidoc dev-ruby/asciidoctor )
193                 app-text/xmlto
194                 app-doc/doxygen
195                 app-text/docbook-xml-dtd:4.1.2
196                 app-text/docbook-xml-dtd:4.2
197                 app-text/docbook-xml-dtd:4.3
198         )
199 "
200 case ${XORG_DOC} in
201         no)
202                 ;;
203         always)
204                 BDEPEND+=" ${DOC_DEPEND}"
205                 ;;
206         *)
207                 BDEPEND+=" ${XORG_DOC}? ( ${DOC_DEPEND} )"
208                 IUSE+=" ${XORG_DOC}"
209                 ;;
210 esac
211 unset DOC_DEPEND
212
213 DEPEND+=" ${COMMON_DEPEND}"
214 RDEPEND+=" ${COMMON_DEPEND}"
215 unset COMMON_DEPEND
216
217 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: DEPEND=${DEPEND}"
218 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: RDEPEND=${RDEPEND}"
219 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: PDEPEND=${PDEPEND}"
220 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: BDEPEND=${BDEPEND}"
221
222 # @FUNCTION: xorg-3_src_unpack
223 # @DESCRIPTION:
224 # Simply unpack source code.
225 xorg-3_src_unpack() {
226         debug-print-function ${FUNCNAME} "$@"
227
228         if [[ -n ${GIT_ECLASS} ]]; then
229                 git-r3_src_unpack
230         else
231                 unpack ${A}
232         fi
233 }
234
235 # @FUNCTION: xorg-3_reconf_source
236 # @DESCRIPTION:
237 # Run eautoreconf if necessary, and run elibtoolize.
238 xorg-3_reconf_source() {
239         debug-print-function ${FUNCNAME} "$@"
240
241         case ${CHOST} in
242                 *-aix* | *-winnt*)
243                         # some hosts need full eautoreconf
244                         [[ -e "./configure.ac" || -e "./configure.in" ]] \
245                                 && XORG_EAUTORECONF=yes
246                         ;;
247                 *)
248                         # elibtoolize required for BSD
249                         [[ ${XORG_EAUTORECONF} != no && ( -e "./configure.ac" || -e "./configure.in" ) ]] \
250                                 && XORG_EAUTORECONF=yes
251                         ;;
252         esac
253
254         [[ ${XORG_EAUTORECONF} != no ]] && eautoreconf
255         elibtoolize --patch-only
256 }
257
258 # @FUNCTION: xorg-3_src_prepare
259 # @DESCRIPTION:
260 # Prepare a package after unpacking, performing all X-related tasks.
261 xorg-3_src_prepare() {
262         debug-print-function ${FUNCNAME} "$@"
263
264         default
265         xorg-3_reconf_source
266 }
267
268 # @FUNCTION: xorg-3_flags_setup
269 # @DESCRIPTION:
270 # Set up CFLAGS for a debug build
271 xorg-3_flags_setup() {
272         debug-print-function ${FUNCNAME} "$@"
273
274         # Win32 require special define
275         [[ ${CHOST} == *-winnt* ]] && append-cppflags -DWIN32 -D__STDC__
276         # hardened ldflags
277         [[ ${PN} == xorg-server || ${PN} == xf86-video-* || ${PN} == xf86-input-* ]] \
278                 && append-ldflags -Wl,-z,lazy
279
280         # Quite few libraries fail on runtime without these:
281         if has static-libs ${IUSE//+}; then
282                 filter-flags -Wl,-Bdirect
283                 filter-ldflags -Bdirect
284                 filter-ldflags -Wl,-Bdirect
285         fi
286 }
287
288 multilib_src_configure() {
289         ECONF_SOURCE="${S}" econf "${econfargs[@]}"
290 }
291
292 # @FUNCTION: xorg-3_src_configure
293 # @DESCRIPTION:
294 # Perform any necessary pre-configuration steps, then run configure
295 xorg-3_src_configure() {
296         debug-print-function ${FUNCNAME} "$@"
297
298         xorg-3_flags_setup
299
300         # @VARIABLE: XORG_CONFIGURE_OPTIONS
301         # @DESCRIPTION:
302         # Array of an additional options to pass to configure.
303         # @DEFAULT_UNSET
304         local xorgconfadd=("${XORG_CONFIGURE_OPTIONS[@]}")
305
306         # Check if package supports disabling of dep tracking
307         # Fixes warnings like:
308         #    WARNING: unrecognized options: --disable-dependency-tracking
309         if grep -q -s "disable-depencency-tracking" ${ECONF_SOURCE:-.}/configure; then
310                 local dep_track="--disable-dependency-tracking"
311         fi
312
313         # Check if package supports disabling of selective -Werror=...
314         if grep -q -s "disable-selective-werror" ${ECONF_SOURCE:-.}/configure; then
315                 local selective_werror="--disable-selective-werror"
316         fi
317
318         local econfargs=(
319                 ${dep_track}
320                 ${selective_werror}
321                 "${xorgconfadd[@]}"
322         )
323
324         # Handle static-libs found in IUSE, disable them by default
325         if in_iuse static-libs; then
326                 econfargs+=(
327                         --enable-shared
328                         $(use_enable static-libs static)
329                 )
330         fi
331
332         if [[ ${XORG_MULTILIB} == yes ]]; then
333                 multilib-minimal_src_configure "$@"
334         else
335                 econf "${econfargs[@]}" "$@"
336         fi
337 }
338
339 multilib_src_compile() {
340         emake "$@" || die 'emake failed'
341 }
342
343 # @FUNCTION: xorg-3_src_compile
344 # @DESCRIPTION:
345 # Compile a package, performing all X-related tasks.
346 xorg-3_src_compile() {
347         debug-print-function ${FUNCNAME} "$@"
348
349         if [[ ${XORG_MULTILIB} == yes ]]; then
350                 multilib-minimal_src_compile "$@"
351         else
352                 emake "$@" || die 'emake failed'
353         fi
354 }
355
356 multilib_src_install() {
357         emake DESTDIR="${D}" "${install_args[@]}" "$@" install || die "emake install failed"
358 }
359
360 # @FUNCTION: xorg-3_src_install
361 # @DESCRIPTION:
362 # Install a built package to ${D}, performing any necessary steps.
363 xorg-3_src_install() {
364         debug-print-function ${FUNCNAME} "$@"
365
366         local install_args=( docdir="${EPREFIX}/usr/share/doc/${PF}" )
367
368         if [[ ${XORG_MULTILIB} == yes ]]; then
369                 multilib-minimal_src_install "$@"
370         else
371                 emake DESTDIR="${D}" "${install_args[@]}" "$@" install || die "emake install failed"
372         fi
373
374         # Many X11 libraries unconditionally install developer documentation
375         if [[ -d "${D}"/usr/share/man/man3 ]]; then
376                 ! in_iuse doc && eqawarn "ebuild should set XORG_DOC=doc since package installs library documentation"
377         fi
378
379         if in_iuse doc && ! use doc; then
380                 rm -rf "${D}"/usr/share/man/man3
381                 rmdir "${D}"/usr{/share{/man,},} 2>/dev/null
382         fi
383
384         # Don't install libtool archives (even for modules)
385         find "${D}" -type f -name '*.la' -delete || die
386 }