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

35.4. m4-1.4.21

GNU implementation of the traditional Unix macro processor

Version 1.4.21, release 1
Shelf toolchain — The native compilers, the linker, the C library, and the LLVM family
Phase 20_selfhost (Self-Hosting Bootstrap), 8 of 15 in build order
Licence GPL-3.0-or-later
Homepage https://www.gnu.org/software/m4/
Build time 0.6 SBU
Installed size 747.9 KiB in 6 files
Recipe ports/core/toolchain/m4/kpkgbuild

About

GNU m4 is the macro processor. Few people run it by hand, but autoconf is written in it: every configure script is generated by running m4 over configure.ac, so autoconf depends on it, and so does any port whose build.sh runs autoreconf. bison and flex run it each time they generate a parser or a scanner. 20_selfhost builds it because the GMP and GCC builds of that phase run it (see The toolchain rebuilt as packages), and 30_foundation names it again among the build tools it installs first.

The bootstrap of Part III builds no m4, so this port is the first m4 in the root.

Sources

Dependencies

Depends on: nothing a recipe names.

Required by (13): acpica, autoconf, bison, dvd+rw-tools, flex, glibmm, glibmm2.66, groff, handbrake, ispc, libpulse, orcaslicer, thunderbird.

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 m4'

What kpkg does

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

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

export CFLAGS="$CFLAGS -std=gnu17 -D_GL_ATTRIBUTE_NODISCARD=\"\""
./configure --prefix=/usr
make
make DESTDIR=$PKG install

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

Contents

Installed programs: m4.

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

Short descriptions

m4 macro processor

Notes

Built with the tree’s compiler and C library, m4 configures and compiles without a warning, and links to a byte-identical m4, with both settings above left out: neither changes the build as it stands.