# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: Dan McGee <dan@archlinux.org>
# Contributor: Tom Newsom <Jeepster@gmx.co.uk>
# Contributor: Jason Chu <jason@archlinux.org>

pkgname=cscope-git
pkgver=15.9.0.18.g978e2c3
pkgrel=8
pkgdesc="A developers tool for browsing program code"
arch=(x86_64 armv7h aarch64)
url="http://cscope.sourceforge.net/"
license=('BSD')
makedepends=('git')
depends=('ncurses' 'sh')
provides=('cscope')
conflicts=('cscope')
source=('git+https://git.code.sf.net/p/cscope/cscope'
        'symlink-file.patch'
        'search-cscope-buffer.patch')
sha512sums=('SKIP'
            'f308cf550a7de77290fb92f861cb6e00d00b555ae194dc5b9a856b2999fbb7f4757e42aa9c72a8e91ebf381d8699ed00b5b5a4f1af0f67c92fd09776f4ab3c54'
            '4b402f7c1492a8d5b4ab137d16df6f5a99f05ad7fd48d33ec10b63cbb2d0dfe3aad4fb15d51356e3b52cefdbb525b0f673cdb2584d5b659fe91293604add8b95')

pkgver() {
  cd cscope

  git describe --tag | sed -e 's/^[^0-9]*//' -e 's/-/.0./' -e 's/-/./g'
}

prepare() {
  cd cscope

  sed -i 's|/usr/local/lib/cs|/usr/lib/cs|' contrib/ocs
  patch -Np1 < ../symlink-file.patch
  patch -Np1 < ../search-cscope-buffer.patch
}

build() {
  cd cscope

  autoreconf -fi
  ./configure --prefix=/usr
  make
}

package() {
  cd cscope

  make DESTDIR="${pkgdir}" install

  install -d "${pkgdir}"/usr/lib/cs
  install -Dm644 COPYING "${pkgdir}"/usr/share/licenses/"${pkgname}"/LICENSE

  cd contrib/xcscope
  install -Dm644 xcscope.el "${pkgdir}"/usr/share/emacs/site-lisp/xcscope.el
  install -m755 cscope-indexer "${pkgdir}"/usr/bin
}
