332.2. calibre-9.15.0
E-book library manager, converter, viewer and editor
The build-state snapshot was taken from 9.15.0-2; this recipe is 9.15.0-3, so the size, time and contents below describe the earlier build.
| Version | 9.15.0, release 3 |
| Shelf | documents — PDF, PostScript, DjVu, EPUB, CHM and DOCX viewers, libraries and tools, and ebook managers |
| Phase | 44_apps (Applications), 66 of 422 in build order |
| Licence | GPL-3.0-only |
| Homepage | https://calibre-ebook.com/ |
| Build time | 10.9 SBU |
| Installed size | 152.2 MiB in 6415 files |
| Recipe | ports/core/documents/calibre/kpkgbuild |
About
calibre manages a library of e-books: it catalogues them, converts between formats such as EPUB, AZW3, MOBI and PDF, fetches news and metadata, and sends books to readers. The port installs its three windows, the library (calibre), the ebook-viewer and the ebook-edit editor, and its command-line tools (ebook-convert, calibredb and the rest). It is Python on PyQt6 with C and C++ extensions, and the Python modules it needs that the tree carries as no port of their own come from a vendor bundle.
Sources
calibre-9.15.0.tar.xz(46.9 MiB)
sha2569f02d36decaf46b176a1bef74349232508bcc2b4b06d1662bbd1fd426c57d559
upstream: https://download.calibre-ebook.com/9.15.0/calibre-9.15.0.tar.xz
archive copy: sources-1/documents--calibre-9.15.0.tar.xzhtml5-parser-0.4.12.tar.gz(264.5 KiB)
sha2563d7f89841aa48b976311f43863178c34c141abcf1dd45b67a7339e61cffe5306
upstream: https://files.pythonhosted.org/packages/source/h/html5-parser/html5-parser-0.4.12.tar.gz
archive copy: sources-1/documents--html5-parser-0.4.12.tar.gzcalibre-vendor-9.15.0.tar.xz(54.8 MiB)
sha256607097f931b078e2b5f338f893bc676a0072a708a65c016b4c342cc9295eb92a
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-1/documents--calibre-vendor-9.15.0.tar.xz
Dependencies
Depends on: python3, python3-pip, python3-setuptools, python3-wheel, python3-hatchling, python3-flit-core, python3-poetry-core, python3-cython, python3-setuptools-scm, python3-sip, python3-pyqt-builder, python3-pyqt6, python3-pyqt6-sip, python3-pyqt6-webengine, python3-lxml, python3-pillow, python3-psutil, python3-pygments, python3-dateutil, python3-six, python3-html5lib, python3-webencodings, python3-typing-extensions, fonttools, pkgconf, cmake, qt6-qtbase, qt6-qtsvg, qt6-qtimageformats, qt6-qtwebengine, qt6-qtspeech, qt6-qtwayland, hunspell, hyphen, icu, sqlite, snowball, uchardet, openssl, freetype2, fontconfig, libmtp, libusb, podofo, ffmpeg, libxml2, poppler, libjpeg-turbo, xxhash, udisks2, xdg-utils, chmlib, optipng, brotli.
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
0001-calibre-no-update.patch— empties the loop of the background thread insrc/calibre/gui2/update.pythat checks for a new calibre release and for plugin updates, so neither check is ever made; the thread still runs and only waits.0002-calibre-use-make.patch— insetup/build.py, adds-GUnix Makefilesto the CMake command that configures calibre’s headless Qt platform plugin. The step runsmakestraight after it, and without the switch the generator would followCMAKE_GENERATORfrom the environment.0003-calibre-disable-piper.patch— removes thepiperextension, calibre’s built-in neural text-to-speech, fromsetup/extensions.jsonand from the list of required extensions insrc/calibre/constants.py, and leaves its module out of the import test whenSKIP_SPEECH_TESTSis set. It callsespeak_TextToPhonemesWithTerminator(), which the release of espeak-ng the tree builds does not declare, and its voices are downloaded on first use; with it gone, reading aloud goes through Qt Speech and speech-dispatcher.netifaces-msghdr.patch— applied to the bundlednetifacesmodule, not to calibre: initialises astruct msghdrinnetifaces.cby field name instead of by position. musl’smsghdrhas padding members glibc’s has not, so the positional form puts the values in the wrong fields and does not compile.
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/44_apps/phase.env && kpkg install calibre'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/documents/calibre.
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/calibre
echo '9f02d36decaf46b176a1bef74349232508bcc2b4b06d1662bbd1fd426c57d559 calibre-9.15.0.tar.xz' | sha256sum -c -
echo '3d7f89841aa48b976311f43863178c34c141abcf1dd45b67a7339e61cffe5306 html5-parser-0.4.12.tar.gz' | sha256sum -c -
echo '607097f931b078e2b5f338f893bc676a0072a708a65c016b4c342cc9295eb92a calibre-vendor-9.15.0.tar.xz' | 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/calibre
SRC=$SRC_ROOT/calibre-9.15.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf calibre-9.15.0.tar.xz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf html5-parser-0.4.12.tar.gz -C "$SRC_ROOT"
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 recipe’s helpers _html5parser, pyrequirements, pyruntime and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/0001-calibre-no-update.patch"
patch -p1 -i "$PORT_SRC/0002-calibre-use-make.patch"
patch -p1 -i "$PORT_SRC/0003-calibre-disable-piper.patch"
mkdir -p vendor
tar -xf "$PORT_SRC/$name-vendor-$version.tar.xz" --strip-components=1 -C vendor
tar -xf vendor/apsw-*.tar.gz -C "$SRC_ROOT"
_apsw=$(echo "$SRC_ROOT"/apsw-*/)
rm "$_apsw/setup.apsw"
tar -xf vendor/netifaces-*.tar.gz -C "$SRC_ROOT"
_netifaces=$(echo "$SRC_ROOT"/netifaces-*/)
patch -d "$_netifaces" -p1 -i "$PORT_SRC/netifaces-msghdr.patch"
export XXHASH_LINK_SO=1
pip3 install --no-deps --no-index --find-links=vendor --no-build-isolation \
--no-compile --target="$SRC_ROOT/calibre-modules" \
css-parser jeepney dnspython mechanize feedparser-sgmllib feedparser \
markdown html2text soupsieve beautifulsoup4 regex chardet msgpack \
pycryptodome "$_apsw" "$_netifaces" ifaddr zeroconf lxml-html-clean xxhash \
tzlocal pystache pychm py7zr texttable pycryptodomex pyppmd \
pybcj multivolumefile inflate64 pykakasi jaconv deprecated wrapt \
"$SRC_ROOT/html5-parser-$_html5parser"
rm -rf "$SRC_ROOT/calibre-modules/bin"
export CALIBRE_CONFIG_DIRECTORY="$SRC_ROOT/calibre-config"
export QT_QPA_PLATFORM=offscreen
CFLAGS="${CFLAGS/-std=gnu11/}" PYTHONPATH="$SRC_ROOT/calibre-modules" python3 setup.py install \
--prefix=/usr \
--staging-root="$PKG/usr" \
--no-postinstall
cp -a "$SRC_ROOT/calibre-modules/." "$PKG/usr/lib/calibre/"
python3 -m compileall -q -j1 -s "$PKG" -p / "$PKG/usr/lib/calibre"
install -Dm644 -t "$PKG/usr/share/man/man1" man-pages/man1/*.1
install -Dm644 resources/calibre-mimetypes.xml \
"$PKG/usr/share/mime/packages/calibre-mimetypes.xml"
install -Dm644 resources/images/lt.png \
"$PKG/usr/share/icons/hicolor/256x256/apps/calibre-gui.png"
install -Dm644 resources/images/viewer.png \
"$PKG/usr/share/icons/hicolor/256x256/apps/calibre-viewer.png"
install -Dm644 resources/images/tweak.png \
"$PKG/usr/share/icons/hicolor/256x256/apps/calibre-ebook-edit.png"
install -d "$PKG/usr/share/applications"
cat > "$PKG/usr/share/applications/calibre-gui.desktop" <<'DESKTOP'
[Desktop Entry]
Type=Application
Name=calibre
GenericName=E-book Library
Comment=Organise, convert and send e-books
TryExec=calibre
Exec=calibre --detach %U
Icon=calibre-gui
Terminal=false
StartupWMClass=calibre-gui
MimeType=x-scheme-handler/calibre;
Categories=Qt;Office;
Keywords=epub;ebook;library;convert;manager;kindle;
DESKTOP
cat > "$PKG/usr/share/applications/calibre-ebook-viewer.desktop" <<'DESKTOP'
[Desktop Entry]
Type=Application
Name=E-book Viewer
GenericName=E-book Reader
Comment=Read EPUB, MOBI, AZW3, FB2 and comic books
TryExec=ebook-viewer
Exec=ebook-viewer --detach %f
Icon=calibre-viewer
Terminal=false
StartupWMClass=calibre-ebook-viewer
MimeType=application/epub+zip;application/x-mobipocket-ebook;application/x-mobi8-ebook;application/vnd.amazon.mobi8-ebook;application/x-fictionbook+xml;application/x-zip-compressed-fb2;application/vnd.comicbook+zip;application/x-sony-bbeb;
Categories=Qt;Office;Viewer;
Keywords=epub;ebook;reader;viewer;mobi;azw3;fb2;
DESKTOP
cat > "$PKG/usr/share/applications/calibre-ebook-edit.desktop" <<'DESKTOP'
[Desktop Entry]
Type=Application
Name=E-book Editor
GenericName=E-book Editor
Comment=Edit the text and styles inside EPUB and AZW3 books
TryExec=ebook-edit
Exec=ebook-edit --detach %f
Icon=calibre-ebook-edit
Terminal=false
StartupWMClass=calibre-ebook-edit
Categories=Qt;Office;WordProcessor;
Keywords=epub;ebook;editor;azw3;
DESKTOP
chmod 644 "$PKG"/usr/share/applications/calibre-*.desktop
The switches, and why each is set:
XXHASH_LINK_SO=1— read by the bundledxxhashmodule’ssetup.py: link the system xxhash library instead of compiling the copy of its C source the module carries.CALIBRE_CONFIG_DIRECTORY="$SRC_ROOT/calibre-config"— the build imports calibre, which creates its configuration directory on import; this keeps that directory inside the work tree rather than at/tmp/calibre-install-config, wheresetup/install.pyputs it when the variable is unset.QT_QPA_PLATFORM=offscreen— run Qt with no display during the build.CFLAGS="${CFLAGS/-std=gnu11/}"— remove the tree’s C standard fromCFLAGSforsetup.py install. calibre’ssetup/build.pyadds the environment’sCFLAGSto the flags of every extension it compiles, the C++ ones included, where-std=gnu11is not a valid standard; see C flags handed to the C++ compiler.--staging-root="$PKG/usr"— write the files under the package, laid out for--prefix=/usr. Without itsetup/install.pytakes the prefix itself as the staging root and writes into/usrof the build root.--no-postinstall— skip upstream’s post-install step, which writes shell completions, installs desktop entries, icons and MIME types through xdg-utils, and writes an uninstaller script;build.shinstalls the entries, icons and MIME types into the package itself.
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/calibre, 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 calibre-9.15.0-3.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/calibre, and runs the triggers its paths call for.
Contents
Installed programs: calibre, calibre-complete, calibre-customize, calibre-debug, calibre-parallel, calibre-server, calibre-smtp, calibredb, ebook-convert, ebook-device, ebook-edit, ebook-meta, ebook-polish, ebook-viewer, fetch-ebook-metadata, lrf2lrs, lrfviewer, lrs2lrf, markdown-calibre, web2disk.
Installed directories: /usr/lib/calibre, /usr/share/calibre, /usr/share/licenses/calibre.
Short descriptions
calibre |
calibre calibre [options] [path_to_ebook or calibre url ...] Launch the main calibre Graphical User Interface and optionally add the e-book at |
calibre-customize |
calibre-customize calibre-customize options Customize calibre by loading external plugins. |
calibre-debug |
calibre-debug calibre-debug [options] Various command line interfaces useful for debugging calibre. With no options, |
calibre-server |
calibre-server calibre-server [options] [path to library folder...] Start the calibre Content server. The calibre Content server exposes your |
calibre-smtp |
calibre-smtp calibre-smtp [options] [from to text] Send mail using the SMTP protocol. calibre-smtp has two modes of operation. In the |
calibredb |
calibredb calibredb command [options] [arguments] calibredb is the command line interface to the calibre database. It has |
ebook-convert |
ebook-convert ebook-convert input_file output_file [options] Convert an e-book from one format to another. |
ebook-edit |
ebook-edit ebook-edit [opts] [path_to_ebook] [name_of_file_inside_book ...] Launch the calibre Edit book tool. You can optionally also specify the names of |
ebook-meta |
ebook-meta ebook-meta ebook_file [options] Read/Write metadata from/to e-book files. |
ebook-polish |
ebook-polish ebook-polish [options] input_file [output_file] Polishing books is all about putting the shine of perfection onto |
ebook-viewer |
ebook-viewer ebook-viewer [options] file View an e-book. |
fetch-ebook-metadata |
fetch-ebook-metadata fetch-ebook-metadata [options] Fetch book metadata from online sources. You must specify at least one |
lrf2lrs |
lrf2lrs lrf2lrs book.lrf Convert an LRF file into an LRS (XML UTF-8 encoded) file |
lrfviewer |
lrfviewer lrfviewer [options] book.lrf Read the LRF e-book book.lrf |
lrs2lrf |
lrs2lrf lrs2lrf [options] file.lrs Compile an LRS file into an LRF file. |
web2disk |
web2disk web2disk URL Where URL is for example: <https://google.com> |
Notes
The bundle, calibre-vendor-<version>.tar.xz, holds source distributions only. The recipe sets vendoring = python with pyrequirements = no, pyruntime = no and an explicit pypackages list, so ports/fetch downloads the modules named there without resolving their runtime dependencies (see The three Python keys); it also adds the build backends those source distributions declare. The modules more than one program uses (lxml, Pillow, psutil, Pygments, dateutil, six, html5lib, fontTools, PyQt6 and the rest in depends) are ports instead, and so are the build backends: pip runs with --no-build-isolation and builds with the installed ones, not the copies in the bundle. html5-parser is a source of its own, pinned in the recipe’s _html5parser.
Two modules are unpacked and changed before they are installed. apsw’s setup.apsw is deleted: it tells apsw’s build to download the matching SQLite source and compile it in, and without it apsw links the sqlite port. netifaces gets the patch above.
The bundled modules are installed with --target into a directory of the build’s own, then put on PYTHONPATH for setup.py install, because its gui step imports calibre and calibre imports them. That install empties calibre’s library directory, /usr/lib/calibre, before filling it, so the modules are copied into it afterwards. calibre’s launchers put that directory first on sys.path, so none of these modules is a path in site-packages that another package could also own. Bytecode is compiled once at the end, with compileall -s "$PKG" -p /, so each .pyc records the path it is installed at.
The release tarball already carries the generated resources the install needs (the compiled viewer and editor scripts, MathJax, the hyphenation dictionaries, the iso-codes tables and fonts), and setup.py install runs only its build and gui steps, so nothing reaches the network.
build.sh writes the three desktop entries. Each program sets its Wayland app id from its entry’s name, which the entries’ StartupWMClass lines match. Only the viewer claims the e-book MIME types, so a book opens in the viewer and PDF stays with the document viewer.
runtime = fonttools: calibre subsets the fonts it embeds in a converted book (calibre/utils/fonts/subset.py and metadata.py import fontTools), inside functions the run-time needs record does not read. fonttools is a build-only port, so without the word a prebuilt install would leave it out and a conversion that embeds fonts would fail.