pkgname=shared-mime-info
pkgver=2.4
pkgdesc="Freedesktop.org Shared MIME Info"
arch=('x86_64')
license=('GPL-2.0-or-later')
depends=('libxml2' 'glib2' 'glibc' 'gcc-libs')
makedepends=('gettext' 'xmlto' 'docbook-xsl' 'git' 'meson')
homepage="https://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/"
sources=("${pkgname}-${pkgver}.tar.gz"
  "xdgmime.tar.xz"
  "update-mime-database.HOOK"
)
urls=("https://gitlab.freedesktop.org/xdg/shared-mime-info/-/archive/${pkgver}/${sources[0]}"
  "https://anduin.linuxfromscratch.org/BLFS/xdgmime/xdgmime.tar.xz"
  "update-mime-database.HOOK"
)
md5sums=("aac56db912b7b12a04fb0018e28f2f36"
  "7dfb4446705d345d3acd672024049e86"
  "a42f6c190c03795f47a70e12ce1f8667"
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  tar -xf ${distdir}/${sources[1]}
  CFLAGS= make -C xdgmime
}

src_build() {
  meson setup build \
        --prefix=/usr \
        --buildtype=release \
        -D update-mimedb=false \
        -D xdgmime-path=${srcdir}/xdgmime
  meson configure --no-pager build
  ninja -C build
}

src_check() {
  meson test -C build --print-errorlogs
}

src_install() {
  DESTDIR="$pkgdir" meson install -C build
  leaf_install_hook "${filedir}/${sources[2]}"
}

src_postremove() {
  if [ -d /usr/share/mime ]; then
    rm -f /usr/share/mime/{globs,globs2,icons,treemagic,generic-icons,types,magic,XMLnamespaces,subclasses,aliases,mime.cache}
    rm -rf /usr/share/mime/{application,audio,image,inode,message,model,multipart,text,video,x-content,x-epoc}
    rmdir --ignore-fail-on-non-empty /usr/share/mime
  fi
}


# vim:ft=sh syn=sh et sw=2:
