# Maintainer: PktSurf <smlinux@pktsurf.in>
app=mupdf
version=1.17.0
build=1sml
homepage="https://mupdf.com/"
download="https://mupdf.com/downloads/archive/mupdf-$version-source.tar.xz"
desc="Lightweight PDF, CBZ, and XPS viewer and toolkit"
requires="desktop-file-utils openssl jbig2dec libjpeg-turbo freetype libxext glu freeglut mesa harfbuzz"

prepbuilddir() {
  mkandenterbuilddir
  rm -rf $app-$version-source

  tar xf $srcdir/$app-$version-source.tar.?z*
  cd $app-$version-source
  fixbuilddirpermissions

  applypatch $srcdir/shared-lib.patch
  applypatch $srcdir/fix-big-endian.patch
}

build() {
  # We use system libraries, not the ones that come with the mupdf source
  for library in curl freeglut freetype harfbuzz jbig2dec \
     libjpeg openjpeg zlib ; do
       rm -rf thirdparty/"$library"
  done

  make USE_SYSTEM_LIBS=yes prefix=/ CURL_LIBS="-lcurl -lpthread" \
    build=release libs apps
  make USE_SYSTEM_LIBS=yes prefix=/ DESTDIR="$pkg" install

  # .desktop taken from debian and modified:
  install -Dm 644 $srcdir/$app.desktop $pkg/share/applications/$app.desktop

  # Icon converted from platform/x11/mupdf.ico, with icotool
  install -Dm 644 $srcdir/$app.png $pkg/share/pixmaps/$app.png

  ( 
    cd $pkg/lib
    ln -s libmupdf.so.0 libmupdf.so 
    ln -s libmupdf-third.so.0 libmupdf-third.so
  )

  mv $pkg/share/doc/$app/COPYING $pkgdocs/
  
  mkfinalpkg
}

sha512sums="
bdca3a2b9e6b1991ba0e280b37456033c5669a9b1ac54b1f64591ef9e79931aedc04883d939b7ad5ea1967a9f3f2f6ed2a467e1e9aa65b443968456463903043  mupdf-1.17.0-source.tar.lz
486d09df319050ddb33dbd1e2e0638a7bc6a3e188032a35b81119c45b0de911629b827b21aa47cde6669b66d73fb22cff54d190a8449151fdc27eace71beefbd  fix-big-endian.patch
212ea566b6f1d60a1087054a8eb29d0d9ca08eef237219151fc4fe8880461cd86fcb03b0266a7347015af458b557dfd914e827f5ff8fee78e9e50c7f358fc8e0  shared-lib.patch
"
