APP=mupdf
VERSION=1.17.0
BUILD=1sml
HOMEPAGE="https://mupdf.com/"
DOWNLOAD="https://mupdf.com/downloads/archive/mupdf-1.17.0-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"

build() {
  mkandenterbuilddir
  rm -rf $APP-$VERSION-source

  tar xf $SRCDIR/$APP-$VERSION-source.tar.?z*
  cd $APP-$VERSION-source
  fixbuilddirpermissions

  patch -p1 < $SRCDIR/shared-lib.patch
  patch -p1 < $SRCDIR/fix-big-endian.patch

  # 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="
39188e6ce3eaefb525b2c32767c4bf52ed881b41889edef086aa64bfe1c38e6f3cb853450c8284d175ef8854f32e9bc67415a692048ead26cf31c35645f9e0e5  mupdf-1.17.0-source.tar.xz
486d09df319050ddb33dbd1e2e0638a7bc6a3e188032a35b81119c45b0de911629b827b21aa47cde6669b66d73fb22cff54d190a8449151fdc27eace71beefbd  fix-big-endian.patch
212ea566b6f1d60a1087054a8eb29d0d9ca08eef237219151fc4fe8880461cd86fcb03b0266a7347015af458b557dfd914e827f5ff8fee78e9e50c7f358fc8e0  shared-lib.patch
"
