kde5.eclass: Cleanup obsolete blocker
[gentoo.git] / eclass / x-modular.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @DEAD
5 # Removal on 2018-02-01.
6 #
7 # DEPRECATED
8 # This eclass has been superseded by xorg-2
9 # Please modify your ebuilds to use that instead
10 #
11 # @ECLASS: x-modular.eclass
12 # @MAINTAINER:
13 # x11@gentoo.org
14 # @BLURB: Reduces code duplication in the modularized X11 ebuilds.
15 # @DESCRIPTION:
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.
20 #
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.
25
26 if [[ ${PV} = 9999* ]]; then
27         GIT_ECLASS="git"
28         SNAPSHOT="yes"
29         SRC_URI=""
30 fi
31
32 # If we're a font package, but not the font.alias one
33 FONT_ECLASS=""
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
39         FONT="yes"
40
41         # Whether to inherit the font eclass
42         FONT_ECLASS="font"
43 fi
44
45 inherit eutils libtool multilib toolchain-funcs flag-o-matic autotools \
46         ${FONT_ECLASS} ${GIT_ECLASS}
47
48 EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_preinst pkg_postinst pkg_postrm"
49
50 case "${EAPI:-0}" in
51         0|1)
52                 ;;
53         2)
54                 EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare src_configure"
55                 ;;
56         *)
57                 die "Unknown EAPI ${EAPI}"
58                 ;;
59 esac
60
61 # exports must be ALWAYS after inherit
62 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
63
64 # @ECLASS-VARIABLE: XDIR
65 # @DESCRIPTION:
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.
71 XDIR="/usr"
72
73 IUSE=""
74 HOMEPAGE="https://www.x.org/wiki/"
75
76 # @ECLASS-VARIABLE: SNAPSHOT
77 # @DESCRIPTION:
78 # If set to 'yes' and configure.ac exists, eautoreconf will run. Set
79 # before inheriting this eclass.
80 : ${SNAPSHOT:=no}
81
82 # Set up SRC_URI for individual modular releases
83 BASE_INDIVIDUAL_URI="https://www.x.org/releases/individual"
84 # @ECLASS-VARIABLE: MODULE
85 # @DESCRIPTION:
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
90         case ${CATEGORY} in
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"     ;;
99         esac
100 fi
101
102 if [[ -n ${GIT_ECLASS} ]]; then
103         EGIT_REPO_URI="https://anongit.freedesktop.org/git/xorg/${MODULE}/${PN}.git"
104 else
105         SRC_URI="${SRC_URI} ${BASE_INDIVIDUAL_URI}/${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 shared dependencies
116 if [[ -n "${SNAPSHOT}" ]]; then
117 # FIXME: What's the minimal libtool version supporting arbitrary versioning?
118         DEPEND="${DEPEND}
119                 >=sys-devel/libtool-1.5
120                 >=sys-devel/m4-1.4"
121         WANT_AUTOCONF="latest"
122         WANT_AUTOMAKE="latest"
123 fi
124
125 if [[ -n "${FONT}" ]]; then
126         RDEPEND="${RDEPEND}
127                 media-fonts/encodings
128                 x11-apps/mkfontscale
129                 x11-apps/mkfontdir"
130         PDEPEND="${PDEPEND}
131                 media-fonts/font-alias"
132
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
135
136 # @ECLASS-VARIABLE: FONT_DIR
137 # @DESCRIPTION:
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
141 # eclass.
142         : ${FONT_DIR:=${PN##*-}}
143
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}
149
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}\""
153         fi
154
155         if [[ -n "${FONT}" ]]; then
156                 if [[ ${PN##*-} = misc ]] || [[ ${PN##*-} = 75dpi ]] || [[ ${PN##*-} = 100dpi ]] || [[ ${PN##*-} = cyrillic ]]; then
157                         IUSE="${IUSE} nls"
158                 fi
159         fi
160 fi
161
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
165         DRIVER="yes"
166 fi
167
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}" ]] \
177         ; then
178         DEBUGGABLE="yes"
179         IUSE="${IUSE} debug"
180 fi
181
182 DEPEND="${DEPEND}
183         virtual/pkgconfig"
184
185 if [[ "${PN/util-macros}" = "${PN}" ]]; then
186         DEPEND="${DEPEND}
187                 >=x11-misc/util-macros-1.3.0"
188 fi
189
190 RDEPEND="${RDEPEND}
191         !<=x11-base/xorg-x11-6.9"
192 # Provides virtual/x11 for temporary use until packages are ported
193 #       x11-base/x11-env"
194
195 # @FUNCTION: x-modular_specs_check
196 # @USAGE:
197 # @DESCRIPTION:
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
204         fi
205 }
206
207 # @FUNCTION: x-modular_dri_check
208 # @USAGE:
209 # @DESCRIPTION:
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
213         # support for it
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."
222                                 fi
223                         else
224                                 if ! built_with_use x11-base/xorg-server dri; then
225                                         die "You must build x11-base/xorg-server with USE=dri."
226                                 fi
227                         fi
228                 fi
229         fi
230 }
231
232 # @FUNCTION: x-modular_server_supports_drivers_check
233 # @USAGE:
234 # @DESCRIPTION:
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."
244                         fi
245                 fi
246         fi
247 }
248
249 # @FUNCTION: x-modular_unpack_source
250 # @USAGE:
251 # @DESCRIPTION:
252 # Simply unpack source code. Nothing else.
253 x-modular_unpack_source() {
254         if [[ -n ${GIT_ECLASS} ]]; then
255                 git_src_unpack
256         else
257                 unpack ${A}
258         fi
259         cd "${S}"
260
261         if [[ -n ${FONT_OPTIONS} ]]; then
262                 einfo "Detected font directory: ${FONT_DIR}"
263         fi
264 }
265
266 # @FUNCTION: x-modular_patch_source
267 # @USAGE:
268 # @DESCRIPTION:
269 # Apply all patches
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"
276         fi
277
278 # @VARIABLE: PATCHES
279 # @DESCRIPTION:
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
285                         epatch "${x}"
286                 done
287         elif [[ -n "${PATCHES}" ]]; then
288                 for x in ${PATCHES}; do
289                         epatch "${x}"
290                 done
291         # For non-default directory bulk patching
292         elif [[ -n "${PATCH_LOC}" ]] ; then
293                 epatch ${PATCH_LOC}
294         # For standard bulk patching
295         elif [[ -d "${EPATCH_SOURCE}" ]] ; then
296                 epatch
297         fi
298 }
299
300 # @FUNCTION: x-modular_reconf_source
301 # @USAGE:
302 # @DESCRIPTION:
303 # Run eautoreconf if necessary, and run elibtoolize.
304 x-modular_reconf_source() {
305         if [[ "${SNAPSHOT}" = "yes" ]]
306         then
307                 # If possible, generate configure if it doesn't exist
308                 if [ -f "./configure.ac" ]
309                 then
310                         eautoreconf
311                 fi
312         fi
313
314         # Joshua Baergen - October 23, 2005
315         # Fix shared lib issues on MIPS, FBSD, etc etc
316         elibtoolize
317 }
318
319 # @FUNCTION: x-modular_src_prepare
320 # @USAGE:
321 # @DESCRIPTION:
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} \
325                 && git_src_prepare
326         x-modular_patch_source
327         x-modular_reconf_source
328 }
329
330 # @FUNCTION: x-modular_src_unpack
331 # @USAGE:
332 # @DESCRIPTION:
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
337         x-modular_dri_check
338         x-modular_unpack_source
339         has src_prepare ${EXPORTED_FUNCTIONS} || x-modular_src_prepare
340 }
341
342 # @FUNCTION: x-modular_font_configure
343 # @USAGE:
344 # @DESCRIPTION:
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}
352                                 --disable-iso8859-2
353                                 --disable-iso8859-3
354                                 --disable-iso8859-4
355                                 --disable-iso8859-5
356                                 --disable-iso8859-6
357                                 --disable-iso8859-7
358                                 --disable-iso8859-8
359                                 --disable-iso8859-9
360                                 --disable-iso8859-10
361                                 --disable-iso8859-11
362                                 --disable-iso8859-12
363                                 --disable-iso8859-13
364                                 --disable-iso8859-14
365                                 --disable-iso8859-15
366                                 --disable-iso8859-16
367                                 --disable-jisx0201
368                                 --disable-koi8-r"
369                 fi
370         fi
371 }
372
373 # @FUNCTION: x-modular_debug_setup
374 # @USAGE:
375 # @DESCRIPTION:
376 # Set up CFLAGS for a debug build
377 x-modular_debug_setup() {
378         if [[ -n "${DEBUGGABLE}" ]]; then
379                 if use debug; then
380                         strip-flags
381                         append-flags -g
382                 fi
383         fi
384 }
385
386 # @FUNCTION: x-modular_src_configure
387 # @USAGE:
388 # @DESCRIPTION:
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
393
394 # @VARIABLE: CONFIGURE_OPTIONS
395 # @DESCRIPTION:
396 # Any extra options to pass to configure
397
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 \
402                         ${FONT_OPTIONS} \
403                         ${DRIVER_OPTIONS} \
404                         ${CONFIGURE_OPTIONS}
405         fi
406 }
407
408 # @FUNCTION: x-modular_src_make
409 # @USAGE:
410 # @DESCRIPTION:
411 # Run make.
412 x-modular_src_make() {
413         emake || die "emake failed"
414 }
415
416 # @FUNCTION: x-modular_src_compile
417 # @USAGE:
418 # @DESCRIPTION:
419 # Compile a package, performing all X-related tasks.
420 x-modular_src_compile() {
421         has src_configure ${EXPORTED_FUNCTIONS} || x-modular_src_configure
422         x-modular_src_make
423 }
424
425 # @FUNCTION: x-modular_src_install
426 # @USAGE:
427 # @DESCRIPTION:
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
433                 make \
434                         ${PN/proto/}docdir=/usr/share/doc/${PF} \
435                         DESTDIR="${D}" \
436                         install \
437                         || die
438         else
439                 make \
440                         docdir=/usr/share/doc/${PF} \
441                         DESTDIR="${D}" \
442                         install \
443                         || die
444         fi
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 \
449
450         if [[ -n ${GIT_ECLASS} ]]; then
451                 pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
452                 git log ${GIT_TREE} > "${S}"/ChangeLog
453                 popd
454         fi
455
456         if [[ -e ${S}/ChangeLog ]]; then
457                 dodoc "${S}"/ChangeLog
458         fi
459 # @VARIABLE: DOCS
460 # @DESCRIPTION:
461 # Any documentation to install via dodoc
462         [[ -n ${DOCS} ]] && dodoc ${DOCS}
463
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' \
467                         | xargs rm -f
468         fi
469
470         if [[ -n "${FONT}" ]]; then
471                 remove_font_metadata
472         fi
473
474         if [[ -n "${DRIVER}" ]]; then
475                 install_driver_hwdata
476         fi
477 }
478
479 # @FUNCTION: x-modular_pkg_preinst
480 # @USAGE:
481 # @DESCRIPTION:
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
485         :
486 }
487
488 # @FUNCTION: x-modular_pkg_postinst
489 # @USAGE:
490 # @DESCRIPTION:
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
495                 setup_fonts
496         fi
497 }
498
499 # @FUNCTION: x-modular_pkg_postrm
500 # @USAGE:
501 # @DESCRIPTION:
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
506                 font_pkg_postrm
507         fi
508 }
509
510 # @FUNCTION: setup_fonts
511 # @USAGE:
512 # @DESCRIPTION:
513 # Generates needed files for fonts and fixes font permissions
514 setup_fonts() {
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."
517                 eerror "${msg}"
518                 die "${msg}"
519         fi
520
521         create_fonts_scale
522         create_fonts_dir
523         create_font_cache
524 }
525
526 # @FUNCTION: remove_font_metadata
527 # @USAGE:
528 # @DESCRIPTION:
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() {
532         local DIR
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}
539                 fi
540         done
541 }
542
543 # @FUNCTION: install_driver_hwdata
544 # @USAGE:
545 # @DESCRIPTION:
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
553                 if [[ -e $i ]]; then
554                         doins $i
555                 fi
556         done
557 }
558
559 # @FUNCTION: discover_font_dirs
560 # @USAGE:
561 # @DESCRIPTION:
562 # Deprecated. Sets up the now-unused FONT_DIRS variable.
563 discover_font_dirs() {
564         FONT_DIRS="${FONT_DIR}"
565 }
566
567 # @FUNCTION: create_fonts_scale
568 # @USAGE:
569 # @DESCRIPTION:
570 # Create fonts.scale file, used by the old server-side fonts subsystem.
571 create_fonts_scale() {
572         ebegin "Creating fonts.scale files"
573                 local x
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
578
579                         # Only generate .scale files if truetype, opentype or type1
580                         # fonts are present ...
581
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
586                                 mkfontscale \
587                                         -a "${ROOT}"/usr/share/fonts/encodings/encodings.dir \
588                                         -- ${x}
589                         fi
590                 done
591         eend 0
592 }
593
594 # @FUNCTION: create_fonts_dir
595 # @USAGE:
596 # @DESCRIPTION:
597 # Create fonts.dir file, used by the old server-side fonts subsystem.
598 create_fonts_dir() {
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
604
605                         if [[ "${x/encodings}" = "${x}" ]]; then
606                                 mkfontdir \
607                                         -e "${ROOT}"/usr/share/fonts/encodings \
608                                         -e "${ROOT}"/usr/share/fonts/encodings/large \
609                                         -- ${x}
610                         fi
611                 done
612         eend 0
613 }
614
615 # @FUNCTION: create_font_cache
616 # @USAGE:
617 # @DESCRIPTION:
618 # Create fonts.cache-1 files, used by the new client-side fonts
619 # subsystem.
620 create_font_cache() {
621         font_pkg_postinst
622 }