# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Chris Kitching <chriskitching@linux.com>

pkgname=lib32-gstreamer
_pkgbasename=gstreamer
pkgver=1.14.4
pkgrel=1
pkgdesc="GStreamer open-source multimedia framework core library (32-bit)"
url="https://gstreamer.freedesktop.org/"
arch=(x86_64)
license=(LGPL)
depends=(lib32-libxml2 lib32-glib2 lib32-libunwind lib32-libelf gstreamer)
makedepends=(gtk-doc gobject-introspection autoconf-archive git)
_commit=3c586dec930c5c253da0cf49e3f3846243f0ecf5 # tags/1.14.4^0
source=("git+https://anongit.freedesktop.org/git/gstreamer/gstreamer#commit=$_commit"
        "gst-common::git+https://anongit.freedesktop.org/git/gstreamer/common")
sha512sums=('SKIP'
            'SKIP')

pkgver() {
  cd $_pkgbasename
  git describe --tags | sed 's/-/+/g'
}

prepare() {
  cd $_pkgbasename

  git submodule init
  git config --local submodule.common.url "$srcdir/gst-common"
  git submodule update

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  cd $_pkgbasename

  export CC='gcc -m32'
  export CXX='g++ -m32'
  export PKG_CONFIG_PATH='/usr/lib32/pkgconfig'

  ./configure\
    --build=i686-pc-linux-gnu\
    --prefix=/usr\
    --sysconfdir=/etc\
    --localstatedir=/var\
    --libexecdir=/usr/lib32\
    --libdir=/usr/lib32\
    --disable-maintainer-mode\
    --disable-examples\
    --disable-tests\
    --with-package-name="GStreamer (Arch Linux)" \
    --with-package-origin="https://www.archlinux.org/" \
    --disable-static\
    --disable-gtk-doc-html\
    --disable-gtk-doc-pdf\
    --disable-gtk-doc\
    --disable-valgrind\
    --disable-benchmarks
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  cd $_pkgbasename
  make DESTDIR="${pkgdir}" install

  rm -R "${pkgdir}"/usr/{share,include}

  for _i in "${pkgdir}"/usr/bin/*; do
    mv "${_i}" "${_i}-32"
  done
}
