# Maintainer: David Runge <dave@sleepmap.de>
# Contributor: Rob Til Freedmen <rob.til.freedman@gmail.com>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: tobias <tobias@archlinux.org>

pkgname=hydrogen
pkgver=1.0.0beta1
_beta=beta1
pkgrel=1
pkgdesc="An advanced drum machine"
arch=('x86_64')
license=('GPL2')
groups=('pro-audio')
url="http://www.hydrogen-music.org/"
depends=('desktop-file-utils' 'hicolor-icon-theme' 'libarchive' 'liblrdf'
'liblo' 'portaudio' 'portmidi' 'libpulse' 'qt5-xmlpatterns')
makedepends=('cmake' 'cppunit' 'ladspa' 'python2' 'qt5-tools')
optdepends=('rubberband: Time stretch samples')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/${pkgname}-music/${pkgname}/archive/${pkgver/${_beta}/-${_beta}}.tar.gz")
sha512sums=('73963a9f400a4d9f6faca41f5f9af2c4b00ebefb16f394a78fe81f7aacb23acee49633803a484e91705da01cb59b4699133f618fac34f6caa7734bcc67bf4518')

prepare() {
  mv -v "${pkgname}-${pkgver/${_beta}/-${_beta}}" "${pkgname}-${pkgver}"
  cd "${pkgname}-${pkgver}"
  # fix python2 shebang (only required for building)
  sed -e 's/python/python2/' -i data/i18n/stats.py
  # fix desktop file icon name
  # https://github.com/hydrogen-music/hydrogen/issues/558
  sed -e "s/h2-icon/${pkgname}/" -i "linux/${pkgname}.desktop"
  # fix man page location (seemingly fixed on HEAD)
  sed -e 's|/man/|/share/man/|' -i CMakeLists.txt
  # out-of-tree build
  mkdir -v build
}

build() {
  cd "${pkgname}-${pkgver}/build"
  cmake -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DWANT_DEBUG=OFF \
        -DWANT_CPPUNIT=ON \
        -DWANT_LRDF=ON \
        -DWANT_PORTAUDIO=ON \
        -DWANT_PORTMIDI=ON \
        -DWANT_PULSEAUDIO=ON \
        ..
  make
  # update translations
  (
    cd ../data/i18n
    ./updateTranslations.sh
  )
}

package() {
  cd "${pkgname}-${pkgver}/build"
  make DESTDIR="$pkgdir" install

  # install desktop file icon to correct location
  # https://github.com/hydrogen-music/hydrogen/issues/558
  install -vDm 644 "${pkgdir}/usr/share/${pkgname}/data/img/gray/h2-icon.svg" \
    "${pkgdir}/usr/share/icons/hicolor/scalable/apps/${pkgname}.svg"
  rm -rv "${pkgdir}/usr/share/pixmaps"
  rm -rv "${pkgdir}/usr/share/${pkgname}/data/doc"

  # docs
  install -vDm 644 ../{ChangeLog,DEVELOPERS,INSTALL.txt,README.txt} \
    -t "${pkgdir}/usr/share/doc/${pkgname}"

#  # clean up data dir
#  # https://github.com/hydrogen-music/hydrogen/issues/559
  rm -v "$pkgdir/usr/share/${pkgname}/data/i18n/"*.{ts,py,sh}
}

# vim:set ts=2 sw=2 et:
