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

43.9. ccache-4.14

Compiler cache

Version 4.14, release 2
Shelf buildtools — Build systems and build helpers
Phase 30_foundation (Build Foundation), 94 of 127 in build order
Licence GPL-3.0-or-later
Homepage https://ccache.dev/
Build time 1.8 SBU
Installed size 2.5 MiB in 8 files
Recipe ports/core/buildtools/ccache/kpkgbuild

About

ccache is a compiler cache: it hashes a compile’s source, its options and the compiler, and when it has seen the same compile before it hands back the stored object instead of running the compiler. For KDOS it is a build tool first. Once 30_foundation has installed it, script/env/chroot.env sends every CMake project of every later chroot step through it, and the cache in build/ccache survives make cleanbuild. The settings that keep a cached object byte-identical to a fresh compile are in The compiler cache.

The package also ships the masquerade directory /usr/lib/ccache, whose gcc, g++, cc, c++, clang and clang++ are symlinks to ccache: a user who puts that directory first on PATH gets every compile cached. The build itself never puts it on PATH, because CMake would record /usr/lib/ccache/gcc as the compiler in the files a package ships. The manual page is a separate port, ccache-manual, built once asciidoctor is installed.

Sources

Dependencies

Depends on: cmake, ninja, zlib, zstd, xxhash.

Required by (2): ccache-manual, verilator.

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/30_foundation/phase.env && kpkg install ccache'

What kpkg does

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

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/buildtools/ccache
echo 'b093ac5d38204cb4d9f29b0bbd570675aa5a592a78e6675b2c506dbe045234e7  ccache-4.14.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/ccache
SRC=$SRC_ROOT/ccache-4.14
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf ccache-4.14.tar.xz -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:

cmake -S . -B build -G Ninja \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_INSTALL_LIBDIR=lib \
	-DCMAKE_INSTALL_LIBEXECDIR=lib \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG" \
	-DCMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS -DNDEBUG" \
	-DDEPS=LOCAL \
	-DDEP_FMT=BUNDLED \
	-DDEP_BLAKE3=BUNDLED \
	-DDEP_CPPHTTPLIB=BUNDLED \
	-DDEP_TLEXPECTED=BUNDLED \
	-DCCACHE_DEV_MODE=OFF \
	-DHTTP_STORAGE_BACKEND=ON \
	-DREDIS_STORAGE_BACKEND=OFF \
	-DENABLE_TESTING=OFF \
	-DENABLE_DOCUMENTATION=OFF \
	-Wno-dev
cmake --build build
DESTDIR=$PKG cmake --install build

install -d $PKG/usr/lib/ccache
for c in gcc g++ cc c++ clang clang++; do
	ln -s /usr/bin/ccache $PKG/usr/lib/ccache/$c
done

The switches, and why each is set:

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/ccache, 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 ccache-4.14-2.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/ccache, and runs the triggers its paths call for.

Contents

Installed programs: ccache.

Installed directories: /usr/lib/ccache, /usr/share/licenses/ccache.

Notes

The masquerade directory names clang and clang++ although neither compiler is installed in 30_foundation. A link to a compiler that is not installed does nothing until it is; a compiler with no link in the directory is one that a compile through it runs uncached, with no warning.