pkgname=valgrind
pkgver=3.25.1
pkgdesc='Tool to help find memory-management problems in programs'
arch=('x86_64')
license=('GPL-2.0-or-later')
homepage='https://valgrind.org/'
sources=("${pkgname}-${pkgver}.tar.bz2")
urls=("https://sourceware.org/pub/${pkgname}/${sources[0]}")
md5sums=("2b424c9a43aa9bf2840d4989b01ea6e7")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  sed -i 's|/doc/valgrind||' docs/Makefile.in
}

src_build() {
  ./configure --prefix=/usr    \
              --enable-lto=yes \
              --datadir=/usr/share/doc/valgrind-${pkgver} &&
  make
}

src_check() {
  make check CPPFLAGS= CFLAGS= CXXFLAGS= LDFLAGS=
}

src_install() {
  make DESTDIR="${pkgdir}" install

  install -Dm644 docs/*.1 -t "$pkgdir/usr/share/man/man1"
}
