# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=hwinfo
pkgver=%version%
pkgrel=%release%
pkgdesc='Hardware detection tool from openSUSE'
arch=(x86_64)
url='https://github.com/openSUSE/hwinfo'
license=(GPL2)
depends=('libx86emu=3.5' perl-xml-parser perl-xml-writer)
makedepends=(flex git sysfsutils)
options=(!emptydirs)
source=(custom_ioctl.patch
        "git+$url#commit=c87f449f1d4882c71b0a1e6dc80638224a5baeed") # tag: 23.2
b2sums=('2b1bd3b53bbfc1e545e1a70ffd6cca08f704639a104928b2c02ccca3e82000f07a470fbdf129566ece6dfb2b98fdad0e82f18cc5c2016ebfeed043b4edb295b4'
        'SKIP')

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
}
