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