logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

gstreamer-meson.eclass (11529B)


  1. # Copyright 1999-2020 Gentoo Authors
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: gstreamer-meson.eclass
  4. # @MAINTAINER:
  5. # gstreamer@gentoo.org
  6. # @AUTHOR:
  7. # Michał Górny <mgorny@gentoo.org>
  8. # Gilles Dartiguelongue <eva@gentoo.org>
  9. # Saleem Abdulrasool <compnerd@gentoo.org>
  10. # foser <foser@gentoo.org>
  11. # zaheerm <zaheerm@gentoo.org>
  12. # Steven Newbury
  13. # Haelwenn (lanodan) Monnier <contact@hacktivis.me>
  14. # @SUPPORTED_EAPIS: 7
  15. # @BLURB: Helps building core & split gstreamer plugins.
  16. # @DESCRIPTION:
  17. # Eclass to make external gst-plugins emergable on a per-plugin basis
  18. # and to solve the problem with gst-plugins generating far too much
  19. # unneeded dependencies.
  20. #
  21. # GStreamer consuming applications should depend on the specific plugins
  22. # they need as defined in their source code. Usually you can find that
  23. # out by grepping the source tree for 'factory_make'. If it uses playbin
  24. # plugin, consider adding media-plugins/gst-plugins-meta dependency, but
  25. # also list any packages that provide explicitly requested plugins.
  26. inherit multilib meson toolchain-funcs xdg-utils multilib-minimal
  27. case "${EAPI:-0}" in
  28. 7)
  29. ;;
  30. *)
  31. die "EAPI=\"${EAPI}\" is not supported"
  32. ;;
  33. esac
  34. # @ECLASS-VARIABLE: GST_PLUGINS_ENABLED
  35. # @DESCRIPTION:
  36. # Defines the plugins to be built.
  37. # May be set by an ebuild and contain more than one indentifier, space
  38. # seperated (only src_configure can handle mutiple plugins at this time).
  39. : ${GST_PLUGINS_ENABLED:=${PN/gst-plugins-/}}
  40. # @ECLASS-VARIABLE: GST_PLUGINS_DISABLED
  41. # @DESCRIPTION:
  42. # Defines the plugins to not be built, GST_PLUGINS_ENABLED overrides it.
  43. # May be set by an ebuild and contain more than one indentifier, space
  44. # seperated (only src_configure can handle mutiple plugins at this time).
  45. case "${GST_ORG_MODULE}" in
  46. # copied GST_PLUGINS_DISABLED from media-libs/${GST_ORG_MODULE} then added GST_PLUGINS_ENABLED
  47. gst-plugins-bad)
  48. # removed from list: shm ipcpipeline gl
  49. GST_PLUGINS_DISABLED="aom avtp androidmedia applemedia assrender bluez bs2b bz2 chromaprint closedcaption colormanagement curl curl-ssh2 d3dvideosink d3d11 dash dc1394 decklink directfb directsound dtls dts dvb faac faad fbdev fdkaac flite fluidsynth gme gsm iqa kate kms ladspa libde265 libmms lv2 mediafoundation microdns modplug mpeg2enc mplex msdk musepack neon nvcodec ofa openal openexr openh264 openjpeg openmpt openni2 opensles opus resindvd rsvg rtmp sbc sctp smoothstreaming sndfile soundtouch spandsp srt srtp svthevcenc teletext tinyalsa transcode ttml uvch264 va voaacenc voamrwbenc vulkan wasapi wasapi2 webp webrtc webrtcdsp wildmidi winks winscreencap x265 zbar zxing wpe magicleap v4l2codecs hls opencv"
  50. GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} accurip adpcmdec adpcmenc aiff asfmux audiobuffersplit audiofxbad audiolatency audiomixmatrix audiovisualizers autoconvert bayer camerabin2 coloreffects deb ugutils dvbsubenc dvbsuboverlay dvdspu faceoverlay festival fieldanalysis freeverb frei0r gaudieffects gdp geometrictransform id3tag inter interlace ivfpars e ivtc jp2kdecimator jpegformat librfb midi mpegdemux mpegpsmux mpegtsdemux mpegtsmux mxf netsim onvif pcapparse pnm proxy rawparse removesilence rist rtmp2 rtp sdp segmentclip siren smooth speed subenc switchbin timecode videofilters videoframe_audiolevel videoparsers videosignal vmnc y4m"
  51. ;;
  52. gst-plugins-base)
  53. GST_PLUGINS_DISABLED="cdparanoia libvisual opus tremor"
  54. GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} adder app audioconvert audiomixer audiorate audioresample audiotestsrc compositor encoding gio gio-typefinder overlaycomposition pbtypes playback rawparse subparse tcp typefind videoconvert videorate videoscale videotestsrc volume"
  55. ;;
  56. gst-plugins-good)
  57. GST_PLUGINS_DISABLED="aalib cairo directsound dv dv1394 flac gdk-pixbuf gtk3 jack jpeg lame libcaca mpg123 oss oss4 osxaudio osxvideo png pulse qt5 shout2 soup speex taglib twolame vpx waveform wavpack rpicamsrc ximagesrc v4l2"
  58. GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} alpha apetag audiofx audioparsers auparse autodetect avi cutter debugutils deinterlace dtmf effectv equalizer flv flx goom goom2k1 icydemux id3demux imagefreeze interleave isomp4 law level matroska monoscope multifile multipart replaygain rtp rtpmanager rtsp shapewipe smpte spectrum udp videobox videocrop videofilter videomixer wavenc wavparse y4m"
  59. ;;
  60. gst-plugins-ugly)
  61. GST_PLUGINS_DISABLED="a52dec amrnb amrwbdec cdio dvdread mpeg2dec sidplay x264"
  62. GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} asfdemux dvdlpcmdec dvdsub realmedia xingmux"
  63. ;;
  64. esac
  65. # @ECLASS-VARIABLE: GST_PLUGINS_BUILD_DIR
  66. # @DESCRIPTION:
  67. # Actual build directories of the plugins.
  68. # Most often the same as the configure switch name.
  69. # FIXME: Change into a bash array
  70. : ${GST_PLUGINS_BUILD_DIR:=${PN/gst-plugins-/}}
  71. # @ECLASS-VARIABLE: GST_TARBALL_SUFFIX
  72. # @DESCRIPTION:
  73. # Most projects hosted on gstreamer.freedesktop.org mirrors provide
  74. # tarballs as tar.bz2 or tar.xz. This eclass defaults to xz. This is
  75. # because the gstreamer mirrors are moving to only have xz tarballs for
  76. # new releases.
  77. : ${GST_TARBALL_SUFFIX:="xz"}
  78. # Even though xz-utils are in @system, they must still be added to BDEPEND; see
  79. # https://archives.gentoo.org/gentoo-dev/msg_a0d4833eb314d1be5d5802a3b710e0a4.xml
  80. if [[ ${GST_TARBALL_SUFFIX} == "xz" ]]; then
  81. BDEPEND="${BDEPEND} app-arch/xz-utils"
  82. fi
  83. # @ECLASS-VARIABLE: GST_ORG_MODULE
  84. # @DESCRIPTION:
  85. # Name of the module as hosted on gstreamer.freedesktop.org mirrors.
  86. # Leave unset if package name matches module name.
  87. : ${GST_ORG_MODULE:=$PN}
  88. # @ECLASS-VARIABLE: GST_ORG_PVP
  89. # @INTERNAL
  90. # @DESCRIPTION:
  91. # Major and minor numbers of the version number.
  92. : ${GST_ORG_PVP:=$(ver_cut 1-2)}
  93. DESCRIPTION="${BUILD_GST_PLUGINS} plugin for gstreamer"
  94. HOMEPAGE="https://gstreamer.freedesktop.org/"
  95. SRC_URI="https://gstreamer.freedesktop.org/src/${GST_ORG_MODULE}/${GST_ORG_MODULE}-${PV}.tar.${GST_TARBALL_SUFFIX}"
  96. LICENSE="GPL-2"
  97. case ${GST_ORG_PVP} in
  98. 1.*) SLOT="1.0"; GST_MIN_PV="1.2.4-r1" ;;
  99. *) die "Unkown gstreamer release."
  100. esac
  101. S="${WORKDIR}/${GST_ORG_MODULE}-${PV}"
  102. RDEPEND="
  103. >=dev-libs/glib-2.40.0:2[${MULTILIB_USEDEP}]
  104. >=media-libs/gstreamer-${GST_MIN_PV}:${SLOT}[${MULTILIB_USEDEP}]
  105. "
  106. BDEPEND="
  107. >=sys-apps/sed-4
  108. virtual/pkgconfig
  109. virtual/perl-JSON-PP
  110. "
  111. # Export common multilib phases.
  112. multilib_src_configure() { gstreamer_multilib_src_configure; }
  113. if [[ ${PN} != ${GST_ORG_MODULE} ]]; then
  114. # Do not run test phase for invididual plugin ebuilds.
  115. RESTRICT="test"
  116. RDEPEND="${RDEPEND}
  117. >=media-libs/${GST_ORG_MODULE}-${PV}:${SLOT}[${MULTILIB_USEDEP}]"
  118. # Export multilib phases used for split builds.
  119. multilib_src_compile() { gstreamer_multilib_src_compile; }
  120. multilib_src_install() { gstreamer_multilib_src_install; }
  121. multilib_src_install_all() { gstreamer_multilib_src_install_all; }
  122. else
  123. IUSE="nls test"
  124. RESTRICT="!test? ( test )"
  125. BDEPEND="${DEPEND}
  126. nls? ( >=sys-devel/gettext-0.17 )
  127. test? ( media-libs/gstreamer[test] )
  128. "
  129. multilib_src_compile() { eninja; }
  130. multilib_src_test() { eninja test; }
  131. multilib_src_install() { DESTDIR="${D}" eninja install; }
  132. fi
  133. DEPEND="${DEPEND} ${RDEPEND}"
  134. # @FUNCTION: gstreamer_environment_reset
  135. # @INTERNAL
  136. # @DESCRIPTION:
  137. # Clean up environment for clean builds.
  138. # >=dev-lang/orc-0.4.23 rely on environment variables to find a place to
  139. # allocate files to mmap.
  140. gstreamer_environment_reset() {
  141. xdg_environment_reset
  142. }
  143. # @FUNCTION: gstreamer_get_plugin_dir
  144. # @USAGE: gstreamer_get_plugin_dir [<build_dir>]
  145. # @INTERNAL
  146. # @DESCRIPTION:
  147. # Finds plugin build directory and output it.
  148. # Defaults to ${GST_PLUGINS_BUILD_DIR} if argument is not provided
  149. gstreamer_get_plugin_dir() {
  150. local build_dir=${1:-${GST_PLUGINS_BUILD_DIR}}
  151. if [[ ! -d ${S}/ext/${build_dir} ]]; then
  152. if [[ ! -d ${S}/sys/${build_dir} ]]; then
  153. ewarn "No such plugin directory"
  154. die
  155. fi
  156. einfo "Got system plugin in ${build_dir}..." >&2
  157. echo sys/${build_dir}
  158. else
  159. einfo "Got external plugin in ${build_dir}..." >&2
  160. echo ext/${build_dir}
  161. fi
  162. }
  163. # @FUNCTION: gstreamer_multilib_src_configure
  164. # @DESCRIPTION:
  165. # Handles logic common to configuring gstreamer plugins
  166. gstreamer_multilib_src_configure() {
  167. local plugin gst_conf=( ) EMESON_SOURCE=${EMESON_SOURCE:-${S}}
  168. gstreamer_environment_reset
  169. # app-editor/vis regex for meson_options.txt: :x/option\('([^']*)'.*/ c/\1/
  170. for plugin in ${GST_PLUGINS_DISABLED} ; do
  171. gst_conf+=( -D${plugin}=disabled )
  172. done
  173. for plugin in ${GST_PLUGINS_ENABLED} ; do
  174. gst_conf+=( -D${plugin}=enabled )
  175. done
  176. if grep -q "option('orc'" "${EMESON_SOURCE}"/meson_options.txt ; then
  177. if in_iuse orc ; then
  178. gst_conf+=( -Dorc=$(usex orc enabled disabled) )
  179. else
  180. gst_conf+=( -Dorc=disabled )
  181. eqawarn "QA: IUSE=orc is missing while plugin supports it"
  182. fi
  183. fi
  184. if grep -q "option(\'maintainer-mode\'" "${EMESON_SOURCE}"/meson_options.txt ; then
  185. gst_conf+=( -Dmaintainer-mode=disabled )
  186. fi
  187. if grep -q "option(\'schemas-compile\'" "${EMESON_SOURCE}"/meson_options.txt ; then
  188. gst_conf+=( -Dschemas-compile=disabled )
  189. fi
  190. if [[ ${PN} == ${GST_ORG_MODULE} ]]; then
  191. gst_conf+=(
  192. $(meson_feature nls)
  193. $(meson_feature test tests)
  194. )
  195. fi
  196. einfo "Configuring to build ${GST_PLUGINS_ENABLED} plugin(s) ..."
  197. gst_conf+=(
  198. -Dexamples=disabled
  199. -Dpackage-name="Gentoo GStreamer ebuild"
  200. -Dpackage-origin="https://www.gentoo.org"
  201. -Dgst_debug=false
  202. "${@}"
  203. )
  204. meson_src_configure "${gst_conf[@]}"
  205. }
  206. # @FUNCTION: _gstreamer_get_target_filename
  207. # @INTERNAL
  208. # @DESCRIPTION:
  209. # Looks for first argument being present as a substring in install targets
  210. # Got ported from python to perl for greater language-stability
  211. _gstreamer_get_target_filename() {
  212. cat >"${WORKDIR}/_gstreamer_get_target_filename.pl" <<"EOF"
  213. #!/usr/bin/env perl
  214. use strict;
  215. use utf8;
  216. use JSON::PP;
  217. open(my $targets_file, '<:encoding(UTF-8)', 'meson-info/intro-targets.json') || die $!;
  218. my $data = decode_json <$targets_file>;
  219. close($targets_file) || die $!;
  220. if(!$ARGV[0]) {
  221. die "Requires a target as argument";
  222. }
  223. foreach my $target (@{$data}) {
  224. if($target->{'installed'}
  225. and (index($target->{'filename'}[0], $ARGV[0]) != -1)
  226. ) {
  227. printf "%s:%s\n", $target->{'filename'}[0], $target->{'install_filename'}[0];
  228. }
  229. }
  230. EOF
  231. chmod +x "${WORKDIR}/_gstreamer_get_target_filename.pl" || die
  232. perl "${WORKDIR}/_gstreamer_get_target_filename.pl" $@ \
  233. || die "Failed to extract target filenames from meson-info"
  234. }
  235. # @FUNCTION: gstreamer_multilib_src_compile
  236. # @DESCRIPTION:
  237. # Compiles requested gstreamer plugin.
  238. gstreamer_multilib_src_compile() {
  239. local plugin_dir plugin
  240. for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
  241. plugin=$(_gstreamer_get_target_filename $(gstreamer_get_plugin_dir ${plugin_dir}))
  242. plugin_path="${plugin%%:*}"
  243. eninja "${plugin_path/"${BUILD_DIR}/"}"
  244. done
  245. }
  246. # @FUNCTION: gstreamer_multilib_src_install
  247. # @DESCRIPTION:
  248. # Installs requested gstreamer plugin.
  249. gstreamer_multilib_src_install() {
  250. local plugin_dir plugin
  251. for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
  252. for plugin in $(_gstreamer_get_target_filename $(gstreamer_get_plugin_dir ${plugin_dir})); do
  253. local install_filename="${plugin##*:}"
  254. insinto "${install_filename%/*}"
  255. doins "${plugin%%:*}"
  256. done
  257. done
  258. }
  259. # @FUNCTION: gstreamer_multilib_src_install_all
  260. # @DESCRIPTION:
  261. # Installs documentation for requested gstreamer plugin
  262. gstreamer_multilib_src_install_all() {
  263. local plugin_dir
  264. for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
  265. local dir=$(gstreamer_get_plugin_dir ${plugin_dir})
  266. [[ -e ${dir}/README ]] && dodoc "${dir}"/README
  267. done
  268. }