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

21. Patch

GNU patch applies a diff to a tree of files. The bootstrap root needs it because a recipe’s build.sh applies its port’s patches itself, and from 20_selfhost on that build.sh runs inside build/fs with nothing but this root’s tools. 067_patch.sh cross-compiles patch from the same source tarball as the patch port and installs it into build/fs.

Source: the archive of the patch port
Installs into: build/fs/usr
Approximate build time: 0.2 SBU

Installation of patch

The step unpacks the port’s tarball into build/tmp with extract_port_source, which reads the recipe in ports/core/base/patch/ and prints the path of the unpacked directory. It then configures, compiles and installs from inside that directory:

PATCH_SRC=$(extract_port_source patch)

cd "$PATCH_SRC"

./configure \
    --host=$KDOS_TARGET \
    --build=$(build-aux/config.guess) \
    --prefix=/usr

make
make DESTDIR=$SYSROOT install

script/phases/10_bootstrap/067_patch.sh, lines 23–33

make DESTDIR=$SYSROOT install places every file under build/fs at the path it will have when build/fs is the root, so --prefix=/usr puts the program at build/fs/usr/bin/patch. Nothing records that the file was installed: no package owns it until 30_foundation installs the port.

The meaning of the configure options

--host=$KDOS_TARGET
The system the program will run on, x86_64-kdos-linux-musl. configure looks for the compiler under that name, x86_64-kdos-linux-musl-gcc, and finds the cross compiler from Part II in build/cross/bin, which host.env puts on PATH.
--build=$(build-aux/config.guess)
The machine doing the compiling, as patch’s own copy of config.guess names it. With the build machine and the host both named and different, configure treats the build as a cross build from the start and never tries to run a program it compiled. 060_gzip.sh to 068_sed.sh all pass it this way.
--prefix=/usr
The program goes to /usr/bin and its manual page under /usr/share/man.

Nothing else is passed. The root holds no libattr at this point, so configure builds patch without extended-attribute support.

When the install is done the step removes the source directory and touches build/mark/bootstrap/patch. While that file exists the step exits at once without building, unless a build plan names it; see Marks and KDOS_REPLAY.

Built again later

30_foundation installs the patch port over this copy. kpkg adopts the file this step left (see Who owns a file), and from then on the program belongs to the package. The port build differs in three ways:

See also