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

Part VI. The build foundation

This part covers 30_foundation, the phase that installs the tools and libraries every later recipe builds with. Read it if you are following the build phase by phase, or if a port fails because a build tool or base library it expected is missing or behaves differently than you assumed.

The phase installs:

It also rebuilds, as full packages, the rest of the userland the bootstrap installed by hand.

The sections below explain the pinned run that opens the phase’s list and why its order matters, the points at which the build environment changes during the phase, and what the phase provides, grouped by what a later recipe gets from it. The package pages follow, in chapters by shelf (a shelf is the category directory a port lives in, ports/core/<shelf>/<name>/), in the shelves’ own order, and within a shelf in the order kpkgdepends builds them.

One question decides the phase

30_foundation and Part VII’s 31_compilers together install everything needed to rebuild KDOS from KDOS. They are split by one question: does a port need one of the large compilers? A port goes here when nothing in its dependency closure does. The list’s own header says so:

#
# The build systems, interpreters and base libraries every later recipe builds
# with: make, pkgconf, the autotools, cmake, meson and ninja, perl and python3,
# and the archive, TLS and documentation tooling. Nothing here needs a compiler
# from 31_compilers.
#
# This list names every port the phase installs and nothing it does not;
# testing/phaseclosure.py fails when a dependency pulls a port in from outside
# it, or when a shelf section names a port an earlier phase installs.

script/phases/30_foundation/packages.txt, lines 12–20

The check is testing/phaseclosure.py, which preflight runs. It fails when a dependency pulls a port into the phase that the list does not name, and when a shelf heading names a port an earlier phase installs (see Every phase installs exactly its list).

The environment

The phase’s environment is chroot.env with one line added before it, in script/phases/30_foundation/phase.env, after the CHROOT=1 every chroot phase sets:

export CHROOT=1

export LD_LIBRARY_PATH="/usr/lib:/usr/local/lib:/usr/lib64:/usr/local/lib64"${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

source "${BASH_SOURCE[0]%/*}/../../env/chroot.env"

script/phases/30_foundation/phase.env, lines 23–27

The LD_LIBRARY_PATH line gives the dynamic loader /usr/lib, /usr/local/lib, /usr/lib64 and /usr/local/lib64 to search, followed by whatever the variable already held.

Unlike 20_selfhost, this phase keeps chroot.env’s CC=gcc and CXX=g++. From here on every port is compiled by the gcc package that Part V installed. How the environment reaches each step is in The phase environment.

The pinned run

The list opens with names written ahead of the first shelf heading. They are the phase’s pinned run: ports that must be installed, in this order, before anything else in the phase is built.

# FIRST, AND IN THIS ORDER. These are the build tools recipes reach for without
# naming them in `depends`: a configure script calls pkg-config through
# PKG_CHECK_MODULES, a build.sh runs autoreconf, meson or cmake, and libtool's
# configure runs `file` on a test object to learn its ABI. muon is the
# meson that builds pkgconf: it bootstraps with a C compiler alone, so it is
# installed before any pkg-config exists. Listed ahead
# of every shelf section, they are installed before anything else in the phase,
# in the order kpkgdepends gives this run; bash and GNU coreutils, grep, which
# and musl-utils (getconf, getent, iconv) are the shell and the userland every
# build.sh runs in. fortify-headers, musl, gcc, binutils and m4 are
# 20_selfhost's; naming them here rebuilds one whose recipe changed before
# anything uses it. Under `kdosbuild --port-jobs` this run is the phase's
# serial prefix: it builds one port at a time, and nothing after it starts
# until its last port is installed.
fortify-headers
musl
gcc
binutils
make
file
muon
pkgconf
libtool
autoconf
automake
m4
bison
flex
cmake
meson
ninja
python3
perl
bash
coreutils
grep
which
musl-utils

# 20_selfhost's other ports, so one whose recipe changed rebuilds before the
# shelf sections use it. zlib, ncurses and readline are gcc's and python3's
# dependencies and rebuild ahead of them whatever this list says.
tar
diffutils
gawk
ncurses
readline
zlib

script/phases/30_foundation/packages.txt, lines 22–69

They come first because recipes use them without naming them in depends. A configure script calls pkg-config through PKG_CHECK_MODULES; a build.sh runs autoreconf, meson or cmake; libtool’s configure runs file on a test object to learn its ABI; and every build.sh runs in bash with the GNU userland. A port further down the list that needs one of them finds it installed, whatever its depends line says.

Three properties of the run matter when it is read:

It is serial. Under kdosbuild --port-jobs, the run is the phase’s serial prefix: it builds one port at a time, and nothing after it starts until its last port is installed (see Building a package phase by level).

It brings its dependencies with it. kpkgdepends puts each port’s dependencies ahead of it, so the run’s names install far more than themselves. file depends on zlib, bzip2, xz, zstd and libseccomp; python3 on, among others, libffi, mpdecimal, SQLite, Expat, OpenSSL, gdbm and util-linux; CMake on OpenSSL, nghttp2, libarchive, libuv and python3-sphinx, because its configure is given --sphinx-man and builds its manual pages with Sphinx.

Most of the compression and TLS libraries, the whole Python packaging chain under Sphinx, util-linux and utmps are therefore built inside the run, before any shelf section starts. The package pages follow this order: each page sits where its port is actually built in the resolved order, not where the list names it.

It re-lists earlier ports. fortify-headers, musl, gcc, binutils, m4, tar, diffutils, gawk, ncurses, readline and zlib were installed by 20_selfhost. A name an earlier phase installed from the same recipe is skipped, so on an unchanged tree they cost nothing. When one of their recipes has changed, the port rebuilds at this point, before anything in the phase uses it. A re-list (naming a port an earlier phase already installs) is allowed only in a pinned run; under a shelf heading it fails the closure check.

Two ports of the run need a word of their own:

When the environment changes

Two blocks of script/env/chroot.env check whether a program is installed. Every step sources chroot.env afresh, so the phase’s environment changes part-way through, at the first step after each program is installed:

What the phase provides

After the pinned run, the list is written in sections, one per shelf, each under a heading of the form # <shelf> — <description>. The groups below cut across those shelves by what a later recipe gets from them.

Build systems and build helpers

make, file, muon, pkgconf, libtool, autoconf, automake, m4, bison, flex, CMake, Meson and Ninja, from the pinned run; ccache, intltool and itstool from the buildtools shelf; and from toolchain, the assemblers yasm and nasm, the generators swig and gperf, and the ELF tools elfutils and patchelf.

Perl, Python and Lua

perl and python3 come from the pinned run. The other shelves add:

The documentation toolchain

The doctools shelf: texinfo for info manuals, mandoc, which reads the manual pages on the image, help2man, doxygen, asciidoc, xmlto with docbook-xml, docbook-xsl and sgml-common, and scdoc. With libxml2 and libxslt from formats, and Sphinx above, these are the tools a port’s own documentation build calls. Their absence is not always survivable: the list’s comment on help2man notes that a Makefile rule piping $(PROG) --help into it exits 127 when it is missing, and takes the build with it.

Init, devices, accounts and login records

The base and auth shelves hold the system’s foundation:

What these are on a running system is in Boot and init, and why utmps is required of every reader and writer of the login records is in Login records.

The rest of the bootstrap’s userland

The bootstrap installed a minimal userland by hand. 20_selfhost rebuilt part of it (tar, diffutils, gawk, m4 and the toolchain); this phase rebuilds the rest as ports: coreutils, grep, bash and make from the pinned run; patch, findutils, sed and gzip from the base shelf; and xz from the archiver shelf. Each port installs over the bootstrap’s files and adopts them, and several gain what the bootstrap build left out: coreutils is built against ACLs, extended attributes, libcap and utmps, and grep with --enable-perl-regexp against PCRE2. which, less and bc join them as programs the bootstrap did not have. The base userland says which package owns each command-line name and gives the constraints on coreutils’ configure line.

The musl shims

musl leaves out some interfaces that glibc carries and that ports expect, and these ports supply them as libraries of their own:

Port What it supplies
libintl The gettext runtime, libintl: musl does not carry it in libc, and the gettext port is built --disable-nls
argp-standalone glibc’s argp argument parser
musl-fts fts(3), the file-tree walk
musl-obstack glibc’s obstack allocator
musl-rpmatch rpmatch(3), the yes/no answer matcher
musl-utils The getconf, getent and iconv programs, from Alpine’s musl package, which musl’s own source does not carry

elfutils depends on argp-standalone, musl-fts, musl-obstack and musl-rpmatch. musl-utils is in the pinned run, with the rest of the userland every build.sh runs in.

Libraries

The remaining sections install the libraries a large part of the tree links: compression and archives (bzip2, xz, lz4, zstd, LZO, libarchive, Brotli), cryptography (OpenSSL, with openssl3 beside it as a runtime-only second version), networking (nghttp2, ngtcp2, nghttp3, libidn2, libpsl, libssh2, curl, libuv, c-ares), formats and text (Expat, libyaml, libxml2, libxslt, PCRE2), databases (gdbm, SQLite), internationalisation (libunistring, gettext, ICU) and mpdecimal, which Python’s _decimal module links. The vcs shelf adds git, and libgit2, which cargo and cargo-c link in 31_compilers and which every Rust port’s git2 crate would otherwise compile from a bundled copy.

How two versions of one library live side by side, as openssl3 and lua54 do, is in A second version beside the first.

When the phase is over

When the phase finishes:

Snapshots are off by default. In a run that writes them (kdosbuild --snapshot, or S in the startup picker), the phase’s snapshot is the restore point in front of Part VII: a failure among the compilers restores this tree instead of building this phase again (see Snapshots).

See also