pkgname=libvorbis
pkgver=1.3.7
pkgdesc='Reference implementation of the Ogg Vorbis audio format'
arch=(x86_64)
homepage=https://www.xiph.org/vorbis/
license=(BSD-3-Clause)
depends=(
  glibc
  libogg
)
_patches=("libvorbis-1.3.7-macro-wstrict-prototypes.patch"
  "libvorbis-1.3.7-mismatched-free.patch"
  "libvorbis-1.3.7-psy-bounds.patch"
  "libvorbis-1.3.7-ubsan-shift.patch"
)
_patch_sums=("a13d1c323b811ba62b96f10232d1332e3ef5d90e7f4e02ff28de74a264c00bc660475c712fd3f90e1234d60fe13bcf3879442b5bac26cde8ff31bc09854c1ff7"
  "ddf29b10a081ce13f3e430565437cc96b306c8d2231fa3996e27657e992ad302768044847beeb39d13a207b35d82abf8fb1fa13e38371fda8ded927c536e9920"
  "6238266c296c647df282c2767b09512a572e8e0a1a2bb001aeaea66617f742f867b91c930b202345e0a27c294f0b06fc345d2d360ef2bec7a12907414c264a03"
  "b008d3cf8509ea8fbb0a2bed306da6310ff58561c98d33633ccba28628e40f371b8e2e73f59ec6736af1ef5f4480e58157f8b6a8d303b86ff3f2b4dd67ca43c2"
)
sources=("${pkgname}-${pkgver}.tar.xz"
  ${_patches[@]}
)
urls=("https://downloads.xiph.org/releases/vorbis/${sources[0]}"
  ${_patches[@]}
)
sha512sums=("bbf5f11f623d959b3ba98d6b52806521b0b918b59b867f0658c153ea1013293364eead4987e9e71f8798021379310860a2e548fcf89d10caf23d45e41aba45cd"
  ${_patch_sums[@]}
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1

  for _patch in ${_patches[@]}; do
    patch -p1 -i ${filedir}/${_patch}
  done

  sed -i \
    -e '/CFLAGS/s:-O20::' \
    -e '/CFLAGS/s:-mcpu=750::' \
    -e '/CFLAGS/s:-mno-ieee-fp::' \
    configure.ac

  find -name 'Makefile.am' \
      -exec sed -i \
      -e 's:$(datadir)/doc/$(PACKAGE)-$(VERSION):@docdir@/html:' \
      {} +

  autoreconf -fi
}

src_build() {
  local config_args=(
    --prefix=/usr
    --docdir=/usr/share/doc/${pkgname}-${pkgver}
    --enable-shared
    --disable-static
    --enable-oggtest
  )
  ./configure "${config_args[@]}"
  make
}

src_check() {
  make -j1 check
}

src_install() {
  make DESTDIR="${pkgdir}" install
  install -Dm 644 COPYING -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim:ft=sh syn=sh et sw=2:
