212.2. mupdf-1.28.4
mutool — the PDF the command line can take apart — and the mupdf-gl and mupdf-x11 viewers
| Version | 1.28.4, release 1 |
| Shelf | documents — PDF, PostScript, DjVu, EPUB, CHM and DOCX viewers, libraries and tools, and ebook managers |
| Phase | 42_graphics (Graphics Stack), 83 of 189 in build order |
| Licence | AGPL-3.0-or-later |
| Homepage | https://mupdf.com/ |
| Build time | 1.8 SBU |
| Installed size | 54.9 MiB in 127 files |
| Recipe | ports/core/documents/mupdf/kpkgbuild |
About
MuPDF is a library and set of programs for PDF, XPS, EPUB, FictionBook, comic book archives and images. The port installs libmupdf, mutool (split, merge, draw, extract, clean, sign, run scripts, and dump text a grep can reach), and two viewers: mupdf-gl, the full one with search, annotations, forms and a file dialog, and mupdf-x11, a plain Xlib viewer. Both viewers are X11 programs and run under Xwayland. aerc names the port in depends.
Why it is in KDOS
The comment above it in script/phases/42_graphics/packages.d/documents.txt:
mutool splits, merges, draws and extracts, and dumps text a grep can reach; mupdf-gl is the light PDF and EPUB viewer, under Xwayland.
Sources
mupdf-1.28.4.tar.gz(65.7 MiB)
sha2562d97e043a616f96b148657c9c3d81ad71c4bd2052c59a2a3315ad842599340f9
upstream: https://mupdf.com/downloads/archive/mupdf-1.28.4-source.tar.gz
archive copy: sources-1/documents--mupdf-1.28.4.tar.gz
Dependencies
Depends on: freetype2, libjpeg-turbo, openjpeg, harfbuzz, zlib, jbig2dec, curl, brotli, leptonica, tesseract, libarchive, zxing-cpp, openssl, python3, freeglut, glu, libglvnd, mesa, libX11, libXext, libXrandr.
Required by (1): aerc.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/42_graphics/phase.env && kpkg install mupdf'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/documents/mupdf.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/documents/mupdf
echo '2d97e043a616f96b148657c9c3d81ad71c4bd2052c59a2a3315ad842599340f9 mupdf-1.28.4.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/mupdf
SRC=$SRC_ROOT/mupdf-1.28.4
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf mupdf-1.28.4.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
MUPDF_SYS="USE_SYSTEM_LIBS=yes USE_SYSTEM_GUMBO=no USE_SYSTEM_MUJS=no \
USE_SYSTEM_ZXINGCPP=yes USE_SYSTEM_LCMS2=no USE_SYSTEM_GLUT=yes"
MUPDF_OPT="tesseract=yes archive=yes barcode=yes HAVE_LIBCRYPTO=yes \
HAVE_X11=yes HAVE_GLUT=yes HAVE_OBJCOPY=yes"
rm -f resources/hyphen/hyph-std.zip resources/hyphen/hyph-all.zip \
generated/resources/hyphen/*.zip.c
python3 - <<'PY'
import glob, zipfile
for out, dirs in (("hyph-std.zip", ("core",)), ("hyph-all.zip", ("core", "extra"))):
files = sorted(f for d in dirs for f in glob.glob(f"resources/hyphen/{d}/*"))
with zipfile.ZipFile(f"resources/hyphen/{out}", "w") as z:
for f in files:
info = zipfile.ZipInfo(f.rsplit("/", 1)[1], (1997, 8, 29, 2, 14, 0))
info.compress_type = zipfile.ZIP_DEFLATED
with open(f, "rb") as src:
z.writestr(info, src.read(), compresslevel=9)
PY
export CC="gcc -std=gnu11" CFLAGS="${CFLAGS/-std=gnu11/}"
make $MUPDF_SYS $MUPDF_OPT build=release prefix=/usr shared=yes
make $MUPDF_SYS $MUPDF_OPT build=release prefix=/usr shared=yes \
DESTDIR=$PKG install
for s in 16 24 32 48 72 128 256 512; do
install -Dm644 docs/logo/mupdf-icon-$s.png \
"$PKG/usr/share/icons/hicolor/${s}x$s/apps/mupdf.png"
done
install -d "$PKG/usr/share/applications"
cat > "$PKG/usr/share/applications/mupdf-gl.desktop" <<'DESKTOP'
[Desktop Entry]
Type=Application
Name=PDF Viewer (MuPDF)
GenericName=Document Viewer
Comment=Read, search and annotate PDF, EPUB, XPS and comic book files
Exec=mupdf-gl %f
Icon=mupdf
Terminal=false
Categories=Office;Viewer;Graphics;
Keywords=pdf;epub;xps;cbz;document;reader;annotate;mupdf;
DESKTOP
chmod 644 "$PKG/usr/share/applications/mupdf-gl.desktop"
The switches, and why each is set:
USE_SYSTEM_LIBS=yes— Turn on theUSE_SYSTEM_*default of most libraries MuPDF keeps a copy of inthirdparty/, so they are linked from the system: freetype, harfbuzz, jbig2dec, libjpeg, openjpeg, zlib, curl, brotli, leptonica, tesseract, zxing-cpp (with thezintit links), freeglut, all ports, and gumbo-parser, which the next line turns back off. A library that is not installed is a build that stops on a missing header a few files in. The defaults it leaves off are lcms2, MuJS, JPEG XR and cmark-gfm; Artifex’s ownextractlibrary has no system switch. libarchive has no bundled copy and is always the system’s.USE_SYSTEM_GUMBO=no,USE_SYSTEM_MUJS=no,USE_SYSTEM_LCMS2=no— Keep three bundled copies: gumbo-parser (the HTML5 parser of the EPUB and HTML reader), MuJS (the JavaScript interpreter of PDF forms andmutool run) and lcms2mt (MuPDF’s thread-safe variant of Little CMS). Only the first changes the build:Makethirdalready leaves MuJS off (“not available”) and lcms2 off (“lcms2mt is strongly preferred”), and the other two lines state it. MuJS is not a port; gumbo-parser and lcms2 are, for other programs.USE_SYSTEM_ZXINGCPP=yes,USE_SYSTEM_GLUT=yes— Two defaults ofUSE_SYSTEM_LIBS, stated. The system GLUT is freeglut, which declaresGLUT_API_VERSION4; MuPDF’s own freeglut fork declares 6.mupdf-gl’s clipboard and its Unicode keyboard input are compiled only for version 6, so this build has no clipboard and reads keys as Latin-1.barcode=yes— Buildmutool barcode, which decodes QR codes and barcodes from a page or an image and draws new ones, through zxing-cpp.tesseract=yes— Build OCR output,mutool drawwith an.ocr.pdf,.ocr.txtor other.ocr.*output file, on tesseract and leptonica.archive=yes— Open CBR, CB7 and tar comic archives through libarchive. Likebarcodeandtesseract, it stops the build when its library is missing.HAVE_LIBCRYPTO=yes— Build PDF signing and signature checking on OpenSSL’s libcrypto. Left unset, it is a pkg-config probe that drops both without a word when libcrypto is not found.HAVE_X11=yes,HAVE_GLUT=yes— Build both viewers. Left unset, each is a pkg-config probe (x11 xextformupdf-x11;gl x11 xrandrformupdf-gl) that skips its viewer when a library is missing; set, a missing one is a link error.HAVE_OBJCOPY=yes— Embed the fonts and other resources intolibmupdfby turning each file into an object withld -r -b binary, instead of compiling the hex dumps undergenerated/. It is the default on Linux, stated; the hyphenation step below depends on it.build=release,prefix=/usr,shared=yes— MuPDF has no configure; its makefile takes the build type, the prefix and a sharedlibmupdf.so(static by default) on the command line, on both the build and the installmake.export CC="gcc -std=gnu11" CFLAGS="${CFLAGS/-std=gnu11/}"— Move the tree’s-std=gnu11out ofCFLAGSand into the C compiler’s name. MuPDF’s makefile compiles its C++ sources (the tesseract and zxing-cpp glue) with$(CXX) $(CFLAGS), where a C standard flag does not belong; see C flags handed to the C++ compiler.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/mupdf, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf mupdf-1.28.4-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/mupdf, and runs the triggers its paths call for.
Contents
Installed programs: mupdf-gl, mupdf-x11, mutool.
Installed libraries: libmupdf.so.
Installed directories: /usr/include/mupdf, /usr/share/doc/mupdf, /usr/share/licenses/mupdf.
Short descriptions
mutool |
all purpose tool for dealing with PDF files |
Notes
- The hyphenation archives are rebuilt from source. The tarball carries
resources/hyphen/hyph-std.zipandhyph-all.zip, prebuilt, and a hex dump of one undergenerated/.build.shdeletes all three and writes the two archives again from the text patterns beside them:hyph-std.zipfromcore/,hyph-all.zipfromcore/andextra/, entries in path order under the fixed timestamp of upstream’sscripts/zip.py, deflated, so the result is the same from build to build. WithHAVE_OBJCOPYthe build links the archives themselves, and nothing prebuilt is left to be picked up instead. - The fonts are upstream’s. The faces MuPDF compiles into the library are font data, one of the payloads What is built from source exempts.
- The menu entry.
build.shwritesmupdf-gl.desktopand installs upstream’s PNG icons intohicolor. The entry names noMimeType, so it is never offered as the opener of a file type andkde-mimeapps.listnever has to rank it. freeglut sets noWM_CLASSon its window, so the entry has noStartupWMClasseither.