x11-themes/gentoo10-backgrounds: Cleanup per bug #85210
[gentoo.git] / eclass / gstreamer.eclass
1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: gstreamer.eclass
6 # @MAINTAINER:
7 # gstreamer@gentoo.org
8 # @AUTHOR:
9 # Michał Górny <mgorny@gentoo.org>
10 # Gilles Dartiguelongue <eva@gentoo.org>
11 # Saleem Abdulrasool <compnerd@gentoo.org>
12 # foser <foser@gentoo.org>
13 # zaheerm <zaheerm@gentoo.org>
14 # @BLURB: Helps building core & split gstreamer plugins.
15 # @DESCRIPTION:
16 # Eclass to make external gst-plugins emergable on a per-plugin basis
17 # and to solve the problem with gst-plugins generating far too much
18 # unneeded dependencies.
19 #
20 # GStreamer consuming applications should depend on the specific plugins
21 # they need as defined in their source code. Usually you can find that
22 # out by grepping the source tree for 'factory_make'. If it uses playbin
23 # plugin, consider adding media-plugins/gst-plugins-meta dependency, but
24 # also list any packages that provide explicitly requested plugins.
25
26 inherit eutils multilib multilib-minimal toolchain-funcs versionator xdg-utils
27
28 case "${EAPI:-0}" in
29         5|6)
30                 ;;
31         0|1|2|3|4)
32                 die "EAPI=\"${EAPI:-0}\" is not supported anymore"
33                 ;;
34         *)
35                 die "EAPI=\"${EAPI}\" is not supported yet"
36                 ;;
37 esac
38
39 # @ECLASS-VARIABLE: GST_PLUGINS_BUILD
40 # @DESCRIPTION:
41 # Defines the plugins to be built.
42 # May be set by an ebuild and contain more than one indentifier, space
43 # seperated (only src_configure can handle mutiple plugins at this time).
44 : ${GST_PLUGINS_BUILD:=${PN/gst-plugins-/}}
45
46 # @ECLASS-VARIABLE: GST_PLUGINS_BUILD_DIR
47 # @DESCRIPTION:
48 # Actual build directory of the plugin.
49 # Most often the same as the configure switch name.
50 : ${GST_PLUGINS_BUILD_DIR:=${PN/gst-plugins-/}}
51
52 # @ECLASS-VARIABLE: GST_TARBALL_SUFFIX
53 # @DESCRIPTION:
54 # Most projects hosted on gstreamer.freedesktop.org mirrors provide
55 # tarballs as tar.bz2 or tar.xz. This eclass defaults to xz. This is
56 # because the gstreamer mirrors are moving to only have xz tarballs for
57 # new releases.
58 : ${GST_TARBALL_SUFFIX:="xz"}
59
60 # Even though xz-utils are in @system, they must still be added to DEPEND; see
61 # https://archives.gentoo.org/gentoo-dev/msg_a0d4833eb314d1be5d5802a3b710e0a4.xml
62 if [[ ${GST_TARBALL_SUFFIX} == "xz" ]]; then
63         DEPEND="${DEPEND} app-arch/xz-utils"
64 fi
65
66 # @ECLASS-VARIABLE: GST_ORG_MODULE
67 # @DESCRIPTION:
68 # Name of the module as hosted on gstreamer.freedesktop.org mirrors.
69 # Leave unset if package name matches module name.
70 : ${GST_ORG_MODULE:=$PN}
71
72 # @ECLASS-VARIABLE: GST_ORG_PVP
73 # @INTERNAL
74 # @DESCRIPTION:
75 # Major and minor numbers of the version number.
76 : ${GST_ORG_PVP:=$(get_version_component_range 1-2)}
77
78
79 DESCRIPTION="${BUILD_GST_PLUGINS} plugin for gstreamer"
80 HOMEPAGE="https://gstreamer.freedesktop.org/"
81 SRC_URI="https://gstreamer.freedesktop.org/src/${GST_ORG_MODULE}/${GST_ORG_MODULE}-${PV}.tar.${GST_TARBALL_SUFFIX}"
82
83 LICENSE="GPL-2"
84 case ${GST_ORG_PVP} in
85         0.10) SLOT="0.10"; GST_MIN_PV="0.10.36-r2" ;;
86         1.*) SLOT="1.0"; GST_MIN_PV="1.2.4-r1" ;;
87         *) die "Unkown gstreamer release."
88 esac
89
90 S="${WORKDIR}/${GST_ORG_MODULE}-${PV}"
91
92 RDEPEND="
93         >=dev-libs/glib-2.38.2-r1:2[${MULTILIB_USEDEP}]
94         >=media-libs/gstreamer-${GST_MIN_PV}:${SLOT}[${MULTILIB_USEDEP}]
95 "
96 DEPEND="
97         >=sys-apps/sed-4
98         >=virtual/pkgconfig-0-r1[${MULTILIB_USEDEP}]
99 "
100
101 # Export common multilib phases.
102 multilib_src_configure() { gstreamer_multilib_src_configure; }
103
104 if [[ ${PN} != ${GST_ORG_MODULE} ]]; then
105         # Do not run test phase for invididual plugin ebuilds.
106         RESTRICT="test"
107         RDEPEND="${RDEPEND}
108                 >=media-libs/${GST_ORG_MODULE}-${PV}:${SLOT}[${MULTILIB_USEDEP}]"
109
110         # Export multilib phases used for split builds.
111         multilib_src_compile() { gstreamer_multilib_src_compile; }
112         multilib_src_install() { gstreamer_multilib_src_install; }
113         multilib_src_install_all() { gstreamer_multilib_src_install_all; }
114 else
115         IUSE="nls"
116         DEPEND="${DEPEND} nls? ( >=sys-devel/gettext-0.17 )"
117 fi
118
119 if [[ ${SLOT} == "0.10" ]]; then
120         RDEPEND="${RDEPEND}
121                 abi_x86_32? (
122                         !app-emulation/emul-linux-x86-gstplugins[-abi_x86_32(-)]
123                 )"
124 fi
125
126 DEPEND="${DEPEND} ${RDEPEND}"
127
128 # @FUNCTION: gstreamer_environment_reset
129 # @INTERNAL
130 # @DESCRIPTION:
131 # Clean up environment for clean builds.
132 # >=dev-lang/orc-0.4.23 rely on environment variables to find a place to
133 # allocate files to mmap.
134 gstreamer_environment_reset() {
135         xdg_environment_reset
136 }
137
138 # @FUNCTION: gstreamer_get_plugins
139 # @INTERNAL
140 # @DESCRIPTION:
141 # Get the list of plugins requiring external dependencies.
142 gstreamer_get_plugins() {
143         # Must be called from src_prepare/src_configure
144         GST_PLUGINS_LIST=$(sed -rn 's/^AG_GST_CHECK_FEATURE\((\w+),.*/ \1 /p' \
145                 "${ECONF_SOURCE:-${S}}"/configure.* | LC_ALL='C' tr '[:upper:]' '[:lower:]')
146 }
147
148 # @FUNCTION: gstreamer_get_plugin_dir
149 # @USAGE: gstreamer_get_plugin_dir [<build_dir>]
150 # @INTERNAL
151 # @DESCRIPTION:
152 # Finds plugin build directory and output it.
153 # Defaults to ${GST_PLUGINS_BUILD_DIR} if argument is not provided
154 gstreamer_get_plugin_dir() {
155         local build_dir=${1:-${GST_PLUGINS_BUILD_DIR}}
156
157         if [[ ! -d ${S}/ext/${build_dir} ]]; then
158                 if [[ ! -d ${S}/sys/${build_dir} ]]; then
159                         ewarn "No such plugin directory"
160                         die
161                 fi
162                 einfo "Building system plugin in ${build_dir}..." >&2
163                 echo sys/${build_dir}
164         else
165                 einfo "Building external plugin in ${build_dir}..." >&2
166                 echo ext/${build_dir}
167         fi
168 }
169
170 # @FUNCTION: gstreamer_system_link
171 # @USAGE: gstreamer_system_link gst-libs/gst/audio:gstreamer-audio [...]
172 # @DESCRIPTION:
173 # Walks through makefiles in order to make sure build will link against system
174 # librairies.
175 # Takes a list of path fragments and corresponding pkgconfig libraries
176 # separated by colon (:). Will replace the path fragment by the output of
177 # pkgconfig.
178 gstreamer_system_link() {
179         local pdir directory libs pkgconfig pc tuple
180         pkgconfig=$(tc-getPKG_CONFIG)
181
182         for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
183                 pdir=$(gstreamer_get_plugin_dir ${plugin_dir})
184
185                 for tuple in $@ ; do
186                         directory=${tuple%:*}
187                         pc=${tuple#*:}-${SLOT}
188                         libs="$(${pkgconfig} --libs-only-l ${pc} || die)"
189                         sed -e "s:\$(top_builddir)/${directory}/.*\.la:${libs}:" \
190                                 -i "${pdir}"/Makefile.{am,in} || die
191                 done
192         done
193 }
194
195 # @FUNCTION: gstreamer_multilib_src_configure
196 # @DESCRIPTION:
197 # Handles logic common to configuring gstreamer plugins
198 gstreamer_multilib_src_configure() {
199         local plugin gst_conf=() ECONF_SOURCE=${ECONF_SOURCE:-${S}}
200
201         gstreamer_get_plugins
202         gstreamer_environment_reset
203
204         for plugin in ${GST_PLUGINS_LIST} ; do
205                 if has ${plugin} ${GST_PLUGINS_BUILD} ; then
206                         gst_conf+=( --enable-${plugin} )
207                 else
208                         gst_conf+=( --disable-${plugin} )
209                 fi
210         done
211
212         if grep -q "ORC_CHECK" "${ECONF_SOURCE}"/configure.* ; then
213                 if in_iuse orc ; then
214                         gst_conf+=( $(use_enable orc) )
215                 else
216                         gst_conf+=( --disable-orc )
217                 fi
218         fi
219
220         if grep -q "AM_MAINTAINER_MODE" "${ECONF_SOURCE}"/configure.* ; then
221                 gst_conf+=( --disable-maintainer-mode )
222         fi
223
224         if grep -q "disable-schemas-compile" "${ECONF_SOURCE}"/configure ; then
225                 gst_conf+=( --disable-schemas-compile )
226         fi
227
228         if [[ ${PN} == ${GST_ORG_MODULE} ]]; then
229                 gst_conf+=( $(use_enable nls) )
230         fi
231
232         einfo "Configuring to build ${GST_PLUGINS_BUILD} plugin(s) ..."
233         econf \
234                 --with-package-name="Gentoo GStreamer ebuild" \
235                 --with-package-origin="https://www.gentoo.org" \
236                 "${gst_conf[@]}" "${@}"
237 }
238
239 # @FUNCTION: gstreamer_multilib_src_compile
240 # @DESCRIPTION:
241 # Compiles requested gstreamer plugin.
242 gstreamer_multilib_src_compile() {
243         local plugin_dir
244
245         for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
246                 emake -C "$(gstreamer_get_plugin_dir ${plugin_dir})"
247         done
248 }
249
250 # @FUNCTION: gstreamer_multilib_src_install
251 # @DESCRIPTION:
252 # Installs requested gstreamer plugin.
253 gstreamer_multilib_src_install() {
254         local plugin_dir
255
256         for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
257                 emake -C "$(gstreamer_get_plugin_dir ${plugin_dir})" \
258                         DESTDIR="${D}" install
259         done
260 }
261
262 # @FUNCTION: gstreamer_multilib_src_install_all
263 # @DESCRIPTION:
264 # Installs documentation for requested gstreamer plugin, and removes .la
265 # files.
266 gstreamer_multilib_src_install_all() {
267         local plugin_dir
268
269         for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
270                 local dir=$(gstreamer_get_plugin_dir ${plugin_dir})
271                 [[ -e ${dir}/README ]] && dodoc "${dir}"/README
272         done
273
274         prune_libtool_files --modules
275 }