# shellcheck shell=bash disable=SC2034,SC2154
# Packager: Didier Spaier didieratslintdotfr

pkgname=iucode_tool
pkgver=2.3.1
pkgrel=1slint
arch=x86_64
source=("https://gitlab.com/iucode-tool/releases/raw/master/iucode-tool_$pkgver.tar.xz")
url="https://gitlab.com/iucode-tool"

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"iucode_tool (Intel Processor Microcode Tool)"
"iucode_tool manipulates Intel i686 and x86-64 processor"
"microcode update collections and can use kernel facilities"
"to apply microcode updates on Intel system processors."
""
"It can load microcode files in text and binary formats,"
"sort/list/filter updates, and write selected updates"
"to a new binary file."
""
"It can also upload selected updates to the kernel."
)

build() {
  cd "$startdir/src"/iucode?tool?"$pkgver" || return 1
  chown -R root:root .
  find -L . \
    \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
       -o -perm 511 \) -exec chmod 755 {} \; -o \
    \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
       -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

  CFLAGS="$SLKCFLAGS" \
  CXXFLAGS="$SLKCFLAGS" \
  ./configure \
    --prefix=/usr \
    --mandir=/usr/man \
    --build="$arch-slackware-linux"
  make -j "$numjobs" || return 1
  make install DESTDIR="$PKG" || return 1

  find "$PKG" -print0 | xargs -0 file | \
    grep -e "executable" -e "shared object" | grep ELF | \
    cut -f 1 -d : | xargs -r strip --strip-unneeded 2>/dev/null || true

  find "$PKG/usr/man" -type f -exec gzip -9 {} \;
  find "$PKG/usr/man" -type l -print0 | while IFS= read -r -d '' i; do
    ln -s "$(readlink "$i").gz" "$i.gz"
    rm "$i"
  done

  mkdir -p "$PKG/usr/doc/$pkgname-$pkgver"
  cp -a AUTHORS CONTRIBUTING COPYING README NEWS TODO ChangeLog \
    "$PKG/usr/doc/$pkgname-$pkgver"
}
