1 # Copyright 1999-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: x-modular-r2.eclass
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.
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.
24 if [[ ${PV} == *9999* ]]; then
30 # If we're a font package, but not the font.alias one
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
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
50 [[ ${EROOT} = */ ]] || EROOT+="/"
54 2|3) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare src_configure" ;;
55 *) DEPEND="EAPI-UNSUPPORTED" ;;
58 # exports must be ALWAYS after inherit
59 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
61 # @ECLASS-VARIABLE: XDIR
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.
71 HOMEPAGE="http://xorg.freedesktop.org/"
73 # @ECLASS-VARIABLE: SNAPSHOT
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
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
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" ;;
100 if [[ -n ${GIT_ECLASS} ]]; then
101 EGIT_REPO_URI="git://anongit.freedesktop.org/git/xorg/${MODULE}/${PN}"
103 SRC_URI="${SRC_URI} ${BASE_INDIVIDUAL_URI}/${MODULE}/${P}.tar.bz2"
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)
113 # Set up shared dependencies
114 if [[ -n ${SNAPSHOT} ]]; then
116 >=sys-devel/libtool-2.2.6a
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
130 PDEPEND+=" media-fonts/font-alias"
132 # @ECLASS-VARIABLE: FONT_DIR
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
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
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
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
176 # Simply unpack source code.
177 x-modular-r2_src_unpack() {
178 if [[ -n ${GIT_ECLASS} ]]; then
184 [[ -n ${FONT_OPTIONS} ]] && einfo "Detected font directory: ${FONT_DIR}"
187 # @FUNCTION: x-modular-r2_patch_source
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
202 # @FUNCTION: x-modular-r2_reconf_source
205 # Run eautoreconf if necessary, and run elibtoolize.
206 x-modular-r2_reconf_source() {
207 [[ "${SNAPSHOT}" = "yes" && -e "./configure.ac" ]] && eautoreconf
209 *-interix* | *-aix* | *-winnt*)
210 # some hosts need full eautoreconf
214 # Fix shared lib issues on MIPS, FBSD, etc etc
220 # @FUNCTION: x-modular-r2_src_prepare
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
233 # If a font package, perform any necessary configuration steps
234 x-modular-r2_font_configure() {
235 if has nls ${IUSE//+} && ! use nls; then
257 # @FUNCTION: x-modular_flags_setup
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
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
280 # @FUNCTION: x-modular-r2_src_configure
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
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 \
301 # @FUNCTION: x-modular-r2_src_compile
304 # Compile a package, performing all X-related tasks.
305 x-modular-r2_src_compile() {
309 # @FUNCTION: x-modular-r2_src_install
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
318 ${PN/proto/}docdir=${EPREFIX}/usr/share/doc/${PF} \
321 || die "emake install failed"
324 docdir=${EPREFIX}/usr/share/doc/${PF} \
327 || die "emake install failed"
330 if [[ -n ${GIT_ECLASS} ]]; then
331 pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" > /dev/null
332 git log ${GIT_TREE} > "${S}"/ChangeLog
336 if [[ -e ${S}/ChangeLog ]]; then
337 dodoc "${S}"/ChangeLog
341 # Any documentation to install
342 if [[ -n ${DOCS} ]]; then
343 dodoc ${DOCS} || die "dodoc failed"
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' \
352 [[ -n ${FONT} ]] && remove_font_metadata
355 # @FUNCTION: x-modular-r2_pkg_postinst
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
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
376 # @FUNCTION: cleanup_fonts
379 # Get rid of font directories that only contain generated files
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
387 einfo "Checking ${real_dir} for useless files"
388 pushd ${real_dir} &> /dev/null
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
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
402 # We don't need to check more files if we're already keeping it
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
413 # Generates needed files for fonts and fixes font permissions
420 # @FUNCTION: remove_font_metadata
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}
432 # @FUNCTION: create_fonts_scale
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"
440 -a "${EROOT}/usr/share/fonts/encodings/encodings.dir" \
441 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"
446 # @FUNCTION: create_fonts_dir
449 # Create fonts.dir file, used by the old server-side fonts subsystem.
451 ebegin "Generating fonts.dir"
453 -e "${EROOT}"/usr/share/fonts/encodings \
454 -e "${EROOT}"/usr/share/fonts/encodings/large \
455 -- "${EROOT}/usr/share/fonts/${FONT_DIR}"