x11-libs/xcb-util: Work around a bug in x11 overlay
[phenriksson.git] / local-misc / eclass / x-modular-r2.eclass
blobab1a5ef27c35dc4af14c01b52243c385dbfd255b
1 # Copyright 1999-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
5 # @ECLASS: x-modular-r2.eclass
6 # @MAINTAINER:
7 # x11@gentoo.org
9 # Author: Tomáš Chvátal <scarabeus@gentoo.org>
10 # Author: Donnie Berkholz <dberkholz@gentoo.org>
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.
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.
23 GIT_ECLASS=""
24 if [[ ${PV} == *9999* ]]; then
25         GIT_ECLASS="git"
26         SNAPSHOT="yes"
27         SRC_URI=""
30 # If we're a font package, but not the font.alias one
31 FONT_ECLASS=""
32 if [[ ${PN} == font* \
33         && ${CATEGORY} = media-fonts \
34         && ${PN} != font-alias \
35         && ${PN} != font-util ]]; then
36         # Activate font code in the rest of the eclass
37         FONT="yes"
38         FONT_ECLASS="font"
41 inherit eutils base libtool multilib toolchain-funcs flag-o-matic autotools \
42         ${FONT_ECLASS} ${GIT_ECLASS}
44 EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_postinst pkg_postrm"
46 if [[ ${EAPI:-0} == 2 ]] && ! use prefix; then
47         EPREFIX=
48         ED=${D}
49         EROOT=${ROOT}
50         [[ ${EROOT} = */ ]] || EROOT+="/"
53 case "${EAPI:-0}" in
54         2|3) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare src_configure" ;;
55         *) DEPEND="EAPI-UNSUPPORTED" ;;
56 esac
58 # exports must be ALWAYS after inherit
59 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
61 # @ECLASS-VARIABLE: XDIR
62 # @DESCRIPTION:
63 # Directory prefix to use for everything. If you want to install to a
64 # non-default prefix (e.g., /opt/xorg), change XDIR. This has not been
65 # recently tested. You may need to uncomment the setting of datadir and
66 # mandir in x-modular-r2_src_install() or add it back in if it's no longer
67 # there. You may also want to change the SLOT.
68 XDIR="${EPREFIX}/usr"
70 IUSE=""
71 HOMEPAGE="http://xorg.freedesktop.org/"
73 # @ECLASS-VARIABLE: SNAPSHOT
74 # @DESCRIPTION:
75 # If set to 'yes' and configure.ac exists, eautoreconf will run. Set
76 # before inheriting this eclass.
77 SNAPSHOT=${SNAPSHOT:="no"}
79 # Set up SRC_URI for individual modular releases
80 BASE_INDIVIDUAL_URI="http://xorg.freedesktop.org/releases/individual"
81 # @ECLASS-VARIABLE: MODULE
82 # @DESCRIPTION:
83 # The subdirectory to download source from. Possible settings are app,
84 # doc, data, util, driver, font, lib, proto, xserver. Set above the
85 # inherit to override the default autoconfigured module.
86 if [[ -z ${MODULE} ]]; then
87         MODULE=""
88         case ${CATEGORY} in
89                 app-doc)             MODULE="doc"     ;;
90                 media-fonts)         MODULE="font"    ;;
91                 x11-apps|x11-wm)     MODULE="app"     ;;
92                 x11-misc|x11-themes) MODULE="util"    ;;
93                 x11-drivers)         MODULE="driver"  ;;
94                 x11-base)            MODULE="xserver" ;;
95                 x11-proto)           MODULE="proto"   ;;
96                 x11-libs)            MODULE="lib"     ;;
97         esac
100 if [[ -n ${GIT_ECLASS} ]]; then
101         EGIT_REPO_URI="git://anongit.freedesktop.org/git/xorg/${MODULE}/${PN}"
102 else
103         SRC_URI="${SRC_URI} ${BASE_INDIVIDUAL_URI}/${MODULE}/${P}.tar.bz2"
106 SLOT="0"
108 # Set the license for the package. This can be overridden by setting
109 # LICENSE after the inherit. Nearly all FreeDesktop-hosted X packages
110 # are under the MIT license. (This is what Red Hat does in their rpms)
111 LICENSE="MIT"
113 # Set up shared dependencies
114 if [[ -n ${SNAPSHOT} ]]; then
115         DEPEND+="
116                 >=sys-devel/libtool-2.2.6a
117                 sys-devel/m4"
118         # These 2 versions MUST BE STABLE
119         [[ ${PN} = "util-macros" ]] && DEPEND+=" >=x11-misc/util-macros-1.3.0"
120         [[ ${PN} = "font-util" ]] && DEPEND+=" >=media-fonts/font-util-1.1.1-r1"
121         WANT_AUTOCONF="latest"
122         WANT_AUTOMAKE="latest"
125 if [[ -n "${FONT}" ]]; then
126         DEPEND+=" >=media-fonts/font-util-1.1.1-r1"
127         RDEPEND+=" media-fonts/encodings
128                 x11-apps/mkfontscale
129                 x11-apps/mkfontdir"
130         PDEPEND+=" media-fonts/font-alias"
132         # @ECLASS-VARIABLE: FONT_DIR
133         # @DESCRIPTION:
134         # If you're creating a font package and the suffix of PN is not equal to
135         # the subdirectory of /usr/share/fonts/ it should install into, set
136         # FONT_DIR to that directory or directories. Set before inheriting this
137         # eclass.
138         FONT_DIR=${FONTDIR:=${PN##*-}}
140         # Fix case of font directories
141         FONT_DIR=${FONT_DIR/ttf/TTF}
142         FONT_DIR=${FONT_DIR/otf/OTF}
143         FONT_DIR=${FONT_DIR/type1/Type1}
144         FONT_DIR=${FONT_DIR/speedo/Speedo}
146         # Set up configure options, wrapped so ebuilds can override if need be
147         [[ -z ${FONT_OPTIONS} ]] && FONT_OPTIONS="--with-fontdir=\"${EPREFIX}/usr/share/fonts/${FONT_DIR}\""
149         [[ ${PN##*-} = misc || ${PN##*-} = 75dpi || ${PN##*-} = 100dpi || ${PN##*-} = cyrillic ]] && IUSE+=" nls"
152 # If we're a driver package, then enable DRIVER case
153 [[ ${PN} == xf86-video-* || ${PN} == xf86-input-* ]] && DRIVER="yes"
155 # Debugging -- ignore packages that can't be built with debugging
156 if [[ -z ${FONT} \
157                 && ${CATEGORY} != app-doc \
158                 && ${CATEGORY} != x11-proto \
159                 && ${PN} != util-macros \
160                 && ${PN} != xbitmaps \
161                 && ${PN} != xorg-cf-files \
162                 && ${PN/xcursor} = ${PN} ]]; then
163         DEBUGGABLE="yes"
164         IUSE+=" debug"
167 DEPEND+=" >=dev-util/pkgconfig-0.23"
169 # Check deps on xorg-server
170 has dri ${IUSE//+} && DEPEND+=" dri? ( >=x11-base/xorg-server-1.6.3.901-r2[-minimal] )"
171 [[ -n "${DRIVER}" ]] && DEPEND+=" x11-base/xorg-server[xorg]"
173 # @FUNCTION: x-modular-r2_src_unpack
174 # @USAGE:
175 # @DESCRIPTION:
176 # Simply unpack source code.
177 x-modular-r2_src_unpack() {
178         if [[ -n ${GIT_ECLASS} ]]; then
179                 git_src_unpack
180         else
181                 unpack ${A}
182         fi
184         [[ -n ${FONT_OPTIONS} ]] && einfo "Detected font directory: ${FONT_DIR}"
187 # @FUNCTION: x-modular-r2_patch_source
188 # @USAGE:
189 # @DESCRIPTION:
190 # Apply all patches
191 x-modular-r2_patch_source() {
192         # Use standardized names and locations with bulk patching
193         # Patch directory is ${WORKDIR}/patch
194         # See epatch() in eutils.eclass for more documentation
195         EPATCH_SUFFIX=${EPATCH_SUFFIX:=patch}
197         [[ -d "${EPATCH_SOURCE}" ]] && epatch
198         base_src_prepare
199         epatch_user
202 # @FUNCTION: x-modular-r2_reconf_source
203 # @USAGE:
204 # @DESCRIPTION:
205 # Run eautoreconf if necessary, and run elibtoolize.
206 x-modular-r2_reconf_source() {
207         [[ "${SNAPSHOT}" = "yes" && -e "./configure.ac" ]] && eautoreconf
208         case ${CHOST} in
209                 *-interix* | *-aix* | *-winnt*)
210                         # some hosts need full eautoreconf
211                         eautoreconf
212                         ;;
213                 *)
214                         # Fix shared lib issues on MIPS, FBSD, etc etc
215                         elibtoolize
216                         ;;
217         esac
220 # @FUNCTION: x-modular-r2_src_prepare
221 # @USAGE:
222 # @DESCRIPTION:
223 # Prepare a package after unpacking, performing all X-related tasks.
224 x-modular-r2_src_prepare() {
225         [[ -n ${GIT_ECLASS} ]] && git_src_prepare
226         x-modular-r2_patch_source
227         x-modular-r2_reconf_source
230 # @FUNCTION: x-modular-r2_font_configure
231 # @USAGE:
232 # @DESCRIPTION:
233 # If a font package, perform any necessary configuration steps
234 x-modular-r2_font_configure() {
235         if has nls ${IUSE//+} && ! use nls; then
236                 FONT_OPTIONS+="
237                         --disable-iso8859-2
238                         --disable-iso8859-3
239                         --disable-iso8859-4
240                         --disable-iso8859-5
241                         --disable-iso8859-6
242                         --disable-iso8859-7
243                         --disable-iso8859-8
244                         --disable-iso8859-9
245                         --disable-iso8859-10
246                         --disable-iso8859-11
247                         --disable-iso8859-12
248                         --disable-iso8859-13
249                         --disable-iso8859-14
250                         --disable-iso8859-15
251                         --disable-iso8859-16
252                         --disable-jisx0201
253                         --disable-koi8-r"
254         fi
257 # @FUNCTION: x-modular_flags_setup
258 # @USAGE:
259 # @DESCRIPTION:
260 # Set up CFLAGS for a debug build
261 x-modular-r2_flags_setup() {
262         if [[ -n ${DEBUGGABLE} ]]; then
263                 if has debug ${IUSE//+} && use debug; then
264                         strip-flags
265                         append-flags -g
266                 fi
267         fi
269         # Win32 require special define
270         [[ ${CHOST} == *-winnt* ]] && append-flags -DWIN32 -D__STDC__
272         # hardened dependant ldflags
273         if [[ ${PN} = xorg-server || -n ${DRIVER} ]]; then
274                 append-ldflags -Wl,-z,lazy
275                 # (#116698) breaks loading
276                 filter-ldflags -Wl,-z,now
277         fi
280 # @FUNCTION: x-modular-r2_src_configure
281 # @USAGE:
282 # @DESCRIPTION:
283 # Perform any necessary pre-configuration steps, then run configure
284 x-modular-r2_src_configure() {
285         x-modular-r2_flags_setup
286         [[ -n "${FONT}" ]] && x-modular-r2_font_configure
288 # @VARIABLE: CONFIGURE_OPTIONS
289 # @DESCRIPTION:
290 # Any options to pass to configure
291 CONFIGURE_OPTIONS=${CONFIGURE_OPTIONS:=""}
292         if [[ -x ${ECONF_SOURCE:-.}/configure ]]; then
293                 econf --prefix=${XDIR} \
294                         --datadir=${XDIR}/share \
295                         ${FONT_OPTIONS} \
296                         ${DRIVER_OPTIONS} \
297                         ${CONFIGURE_OPTIONS}
298         fi
301 # @FUNCTION: x-modular-r2_src_compile
302 # @USAGE:
303 # @DESCRIPTION:
304 # Compile a package, performing all X-related tasks.
305 x-modular-r2_src_compile() {
306         base_src_compile
309 # @FUNCTION: x-modular-r2_src_install
310 # @USAGE:
311 # @DESCRIPTION:
312 # Install a built package to ${ED}, performing any necessary steps.
313 # Creates a ChangeLog from git if using live ebuilds.
314 x-modular-r2_src_install() {
315         # Install everything to ${XDIR}
316         if [[ ${CATEGORY} = x11-proto ]]; then
317                 emake \
318                         ${PN/proto/}docdir=${EPREFIX}/usr/share/doc/${PF} \
319                         DESTDIR="${ED}" \
320                         install \
321                         || die "emake install failed"
322         else
323                 emake \
324                         docdir=${EPREFIX}/usr/share/doc/${PF} \
325                         DESTDIR="${ED}" \
326                         install \
327                         || die "emake install failed"
328         fi
330         if [[ -n ${GIT_ECLASS} ]]; then
331                 pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" > /dev/null
332                 git log ${GIT_TREE} > "${S}"/ChangeLog
333                 popd > /dev/null
334         fi
336         if [[ -e ${S}/ChangeLog ]]; then
337                 dodoc "${S}"/ChangeLog
338         fi
339 # @VARIABLE: DOCS
340 # @DESCRIPTION:
341 # Any documentation to install
342         if [[ -n ${DOCS} ]]; then
343                 dodoc ${DOCS} || die "dodoc failed"
344         fi
346         # Don't install libtool archives for server modules
347         if [[ -e "${ED}/usr/$(get_libdir)/xorg/modules" ]]; then
348                 find "${ED}"/usr/$(get_libdir)/xorg/modules -name '*.la' \
349                         | xargs rm -f
350         fi
352         [[ -n ${FONT} ]] && remove_font_metadata
355 # @FUNCTION: x-modular-r2_pkg_postinst
356 # @USAGE:
357 # @DESCRIPTION:
358 # Run X-specific post-installation tasks on the live filesystem. The
359 # only task right now is some setup for font packages.
360 x-modular-r2_pkg_postinst() {
361         [[ -n "${FONT}" ]] && setup_fonts
364 # @FUNCTION: x-modular-r2_pkg_postrm
365 # @USAGE:
366 # @DESCRIPTION:
367 # Run X-specific post-removal tasks on the live filesystem. The only
368 # task right now is some cleanup for font packages.
369 x-modular-r2_pkg_postrm() {
370         if [[ -n "${FONT}" ]]; then
371                 cleanup_fonts
372                 font_pkg_postrm
373         fi
376 # @FUNCTION: cleanup_fonts
377 # @USAGE:
378 # @DESCRIPTION:
379 # Get rid of font directories that only contain generated files
380 cleanup_fonts() {
381         local allowed_files="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
382         local real_dir=${EROOT}usr/share/fonts/${FONT_DIR}
383         local fle allowed_file
385         unset KEEP_FONTDIR
387         einfo "Checking ${real_dir} for useless files"
388         pushd ${real_dir} &> /dev/null
389         for fle in *; do
390                 unset MATCH
391                 for allowed_file in ${allowed_files}; do
392                         if [[ ${fle} = ${allowed_file} ]]; then
393                                 # If it's allowed, then move on to the next file
394                                 MATCH="yes"
395                                 break
396                         fi
397                 done
398                 # If we found a match in allowed files, move on to the next file
399                 [[ -n ${MATCH} ]] && continue
400                 # If we get this far, there wasn't a match in the allowed files
401                 KEEP_FONTDIR="yes"
402                 # We don't need to check more files if we're already keeping it
403                 break
404         done
405         popd &> /dev/null
406         # If there are no files worth keeping, then get rid of the dir
407         [[ -z "${KEEP_FONTDIR}" ]] && rm -rf ${real_dir}
410 # @FUNCTION: setup_fonts
411 # @USAGE:
412 # @DESCRIPTION:
413 # Generates needed files for fonts and fixes font permissions
414 setup_fonts() {
415         create_fonts_scale
416         create_fonts_dir
417         font_pkg_postinst
420 # @FUNCTION: remove_font_metadata
421 # @USAGE:
422 # @DESCRIPTION:
423 # Don't let the package install generated font files that may overlap
424 # with other packages. Instead, they're generated in pkg_postinst().
425 remove_font_metadata() {
426         if [[ ${FONT_DIR} != Speedo && ${FONT_DIR} != CID ]]; then
427                 einfo "Removing font metadata"
428                 rm -rf "${ED}"/usr/share/fonts/${FONT_DIR}/fonts.{scale,dir,cache-1}
429         fi
432 # @FUNCTION: create_fonts_scale
433 # @USAGE:
434 # @DESCRIPTION:
435 # Create fonts.scale file, used by the old server-side fonts subsystem.
436 create_fonts_scale() {
437         if [[ ${DIR} != Speedo && ${DIR} != CID ]]; then
438                 ebegin "Generating font.scale"
439                         mkfontscale \
440                                 -a "${EROOT}/usr/share/fonts/encodings/encodings.dir" \
441                                 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"
442                 eend $?
443         fi
446 # @FUNCTION: create_fonts_dir
447 # @USAGE:
448 # @DESCRIPTION:
449 # Create fonts.dir file, used by the old server-side fonts subsystem.
450 create_fonts_dir() {
451         ebegin "Generating fonts.dir"
452                         mkfontdir \
453                                 -e "${EROOT}"/usr/share/fonts/encodings \
454                                 -e "${EROOT}"/usr/share/fonts/encodings/large \
455                                 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"
456         eend $?