# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=hwinfo
pkgver=23.3
pkgrel=1
pkgdesc='Hardware detection tool from openSUSE'
arch=(x86_64)
url='https://github.com/openSUSE/hwinfo'
license=(GPL-2.0-or-later)
depends=('libx86emu=3.5' perl-xml-parser perl-xml-writer)
makedepends=(flex git sysfsutils)
options=(!emptydirs)
source=("git+$url#tag=$pkgver"
        custom_ioctl.patch)
b2sums=('193caeda6232eb158ddb4fb9f2ea1f75d0595718a44df04a0d22e1d5f3a90b33910824bf4f57e8d161690f302cdd41e9d2c96f9f0eaff8287c6db09a89a09e0c'
        '2b1bd3b53bbfc1e545e1a70ffd6cca08f704639a104928b2c02ccca3e82000f07a470fbdf129566ece6dfb2b98fdad0e82f18cc5c2016ebfeed043b4edb295b4')

prepare() {
  cd $pkgname
  patch -p1 -i ../custom_ioctl.patch
  echo 'touch changelog' > git2log
  sed -i '/linux\/fs.h/d' src/hd/hd.c
}

build() {
  make -C $pkgname -j1 CFLAGS+=" -fPIC -I$srcdir/$pkgname/src/hd -w" HWINFO_VERSION="$pkgver" LIBDIR=/usr/lib
}

package() {
  cd $pkgname

  make DESTDIR="$pkgdir" LIBDIR=/usr/lib install
  mv "$pkgdir/usr/sbin" "$pkgdir/usr/bin"
  rmdir "$pkgdir/sbin"

  cd doc
  for f in *.1; do install -Dm644 $f "$pkgdir/usr/share/man/man1/$f"; done
  for f in *.8; do install -Dm644 $f "$pkgdir/usr/share/man/man8/$f"; done
}
