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 inbuild/cross/bin, whichhost.envputs onPATH. --build=$(build-aux/config.guess)-
The machine doing the compiling, as patch’s own copy of
config.guessnames 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.shto068_sed.shall pass it this way. --prefix=/usr-
The program goes to
/usr/binand 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:
- It is a native build inside the chroot with KDOS’s own GCC, so it passes no
--hostor--build, and it is compiled with the chroot’s release flags rather than the plain-O2 -pipe -std=gnu99thatscript/env/host.envgives this step. - It passes
--enable-xattrand depends onattr, sopatchkeeps a file’s extended attributes when it rewrites the file. - It names
--sysconfdir=/etc,--mandir=/usr/share/manand--localstatedir=/varexplicitly.
See also
- Grep, the step before this one, and Sed, the step after it
- The patch port: its version, source and contents
- A minimal KDOS: the phase as a whole