Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

37.1. zlib-1.3.2

Compression library implementing the deflate compression method

Version 1.3.2, release 1
Shelf archiver — Compression libraries and archive tools
Phase 20_selfhost (Self-Hosting Bootstrap), 4 of 15 in build order
Licence Zlib
Homepage https://zlib.net/
Build time 0.1 SBU
Installed size 378.3 KiB in 9 files
Recipe ports/core/archiver/zlib/kpkgbuild

About

zlib is the reference implementation of the deflate compression method and of the zlib and gzip stream formats built on it, packaged as one library, libz, with the header zlib.h. PNG images, .gz files and HTTP compression are all deflate, so programs that handle any of them link it.

binutils and gcc each carry a copy of zlib in their own source trees, and both are configured --with-system-zlib to link this port instead, so 20_selfhost builds zlib before either of them. The assembler and the linker read and write zlib-compressed debug sections through it, and the compiler compresses its link-time-optimisation bytecode with it, because it is built without zstd. Several hundred other ports name it in depends.

zlib’s configure is a shell script of its own, not one autoconf generated. It takes --prefix and reads CC, CFLAGS and LDFLAGS from the environment, so the exported release flags reach it with nothing passed on the command line. It builds the shared and the static library together, and the package carries both, as every package does with the static archives its build installs (see Size and language policy).

Sources

Dependencies

Depends on: nothing a recipe names.

Required by (382): abiword, afflib, aircrack-ng, amiberry, aria2, ark, assimp, audacious-plugins, audacity, avidemux, baresip, bat, bcc, bcftools, binutils, binutils-arm-none-eabi, binutils-avr, binutils-riscv64-unknown-elf, blender, boost, botan, bpftool, bpftrace, btrfs-progs, c-blosc, cabal-install, cairo, calligra, cargo-c, cataclysm-dda, ccache, ccid, cfitsio, chromium, clamav, coin, cracklib, crawl-tiles, crispy-doom, cups, curaengine, curl, darktable, dcmtk, ddcutil, ddnet, delta, devilutionx, diamond, digikam, dosbox-x, dsda-doom, dwarves, elfutils, endless-sky, erofs-utils, exempi, exiv2, eza, fastfetch, fcitx5, ffmpeg, fheroes2, fig2dev, file, firefox-esr, fltk, fontforge, freecad, freeciv, freerdp, freetype2, furnace, fuse-emulator, fwupd, gcc, gcc-arm-none-eabi, gcc-avr, gcc-riscv64-unknown-elf, gdal, gdb, ghostscript, gimp, git, gl2ps, glaxnimate, glib, glib-introspection, gmime, gmsh, gnuastro, gnucash, gnumeric, gnupg, gnuplot, gnutls, goldendict-ng, gpxsee, grafx2, graphicsmagick, graphviz, groff, gst-plugins-base, gthumb, gtk-vnc, handbrake, harfbuzz, hatari, hdf5, highs, hplip, htslib, id3lib, ifcopenshell, imagemagick, imhex, inkscape, ioquake3, ispc, isync, itinerary, iverilog, jbig2dec, john, karchive, kbd, keepassxc, khealthcertificate, kicad, kitinerary, kmod, kodi, konqueror, kosmindoormap, kpublictransport, krita, labplot, lagrange, lcms2, leptonica, lib3mf, libarchive, libavif, libbpf, libcdr, libdab, libetonyek, libetpan, libewf, libfido2, libfontenc, libgd, libgeotiff, libgit2, libgme, libgpod, libgsf, libharu, libheif, libid3tag, libisoburn, libisofs, libjpeg-turbo, libkiwix, libksysguard, libmed, libmediainfo, libmysofa, libopenmpt, liborcus, libpciaccess, libpng, libppd, libpst, libraw, libre, libreoffice, librepcb, libretro-mupen64plus-next, librevenge, librewolf, libsoup3, libspatialite, libspectrum, libspng, libssh, libssh2, libstdcxx-arm-none-eabi, libstdcxx-riscv64-unknown-elf, libstrophe, libtiff, libunwind-nongnu, libvips, libvmdk, libvncserver, libwebsockets, libXfont2, libxlsxwriter, libxml2, libzip, lld, lld21, lldb, llvm, llvm21, lmms, lnav, love, luanti, lynx, lyx, mandoc, marble, matio, mednafen, mesa, mesa-opencl, mgba, milkytracker, minidlna, minimap2, minizip, minizip-ng, mkfontscale, mkvtoolnix, mlt, mosh, mpd, mpv, mupdf, mupen64plus, nano, nasm, nbdkit, nco, neon, netcdf-c, netgen, nethack, netpbm, netsurf, ngircd, nheko, nmap, nodejs, notmuch, nss, obs-studio, octave, okular, onnxruntime, openbabel, opencolorio, openconnect, opencpn, opencv, openfpgaloader, openimageio, openjdk, openjpeg, openmsx, openrct2, opensc, openscad, openssh, openssl, openssl3, openttd, openvdb, optipng, orcaslicer, organicmaps, pandoc, partclone, pciutils, pcre2, pdal, pdf4qt, pdfio, pdfium, perf, perl, perl-net-ssleay, plasma-workspace, pngquant, poco, podofo, poppler, postgresql, potrace, powder-toy, ppsspp, protobuf, prusaslicer, python3, python3-lxml, python3-pillow, qbittorrent, qdirstat, qemu, qgis, qpdf, qt5-qtbase, qt5-qtsvg, qt6-qt3d, qt6-qtbase, qt6-qtquick3d, qt6-qtsvg, qt6-qtwebengine, quassel, quazip, R, rawtherapee, recoll, remmina, retroarch, rizin, routino, rsync, ruby, samba, samtools, sauerbraten, schismtracker, scummvm, sdcc, sdcv, sdl2-image, sdl3-image, sdrangel, slang, sleuthkit, smplayer, solvespace, sox, spice, spice-gtk, splat, sqlite, squashfs-tools, srb2, stella, stellarium, sudo, supertux, supertuxkart, taglib, tcl, tenacity, testdisk, texlive, texstudio, thrift, thunderbird, timg, tk, tuxpaint, typst, unshield, util-linux, verilator, vice, viking, vlc, vtk, w3m, webkitgtk, webkitgtk6, weechat, widelands, wireshark, wlvncc, wv, wxwidgets, xapian-core, xonotic, yosys, zeal, zig, zint, zstd, zziplib.

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/20_selfhost/phase.env && kpkg install zlib'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/archiver/zlib.

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/archiver/zlib
echo 'bb329a0a2cd0274d05519d61c667c062e06990d72e125ee2dfa8de64f0119d16  zlib-1.3.2.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/zlib
SRC=$SRC_ROOT/zlib-1.3.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf zlib-1.3.2.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:

./configure --prefix=/usr
make
make DESTDIR=$PKG install

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/zlib, 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 zlib-1.3.2-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/zlib, and runs the triggers its paths call for.

Contents

Installed libraries: libz.a, libz.so.

Installed directories: /usr/share/licenses/zlib.

Short descriptions

zlib.pc zlib compression library

Notes

zlib is the only package that installs libz.so and zlib.h. The zlib-ng port is built without its zlib-compatible mode, which would install both names over this port’s.