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

39.6. grep-3.12

Searches text for patterns — grep, egrep and fgrep, with PCRE2 for -P

Version 3.12, release 1
Shelf base — The minimal userland and system daemons that every KDOS image boots with
Phase 30_foundation (Build Foundation), 67 of 127 in build order
Licence GPL-3.0-or-later
Homepage https://www.gnu.org/software/grep/
Build time 0.6 SBU
Installed size 489.3 KiB in 6 files
Recipe ports/core/base/grep/kpkgbuild

About

GNU grep searches text for lines matching a pattern: basic and extended regular expressions, fixed strings, and Perl-compatible expressions with grep -P. egrep and fgrep are installed as the small scripts upstream ships. On KDOS every grep is this one, which matters to build systems: configure scripts and build.sh files lean on GNU behaviour such as \| in a basic pattern (The base userland).

10_bootstrap cross-compiles the same source without PCRE (Grep). This port rebuilds it natively in the first run of 30_foundation, linked to pcre2, and takes over the files the bootstrap installed.

Why it is in KDOS

The comment above the 24 ports from fortify-headers to musl-utils in script/phases/30_foundation/packages.txt is quoted in The build foundation.

Sources

Dependencies

Depends on: pcre2.

Required by: no port names it.

Differs from the bootstrap build. Grep builds this source too, in script/phases/10_bootstrap/066_grep.sh, before kpkg exists.

Only in the bootstrap build: --build=$(build-aux/config.guess), --disable-perl-regexp, --host=$KDOS_TARGET.

Only in this build: --enable-perl-regexp.

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

What kpkg does

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

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/base/grep
echo '2649b27c0e90e632eadcd757be06c6e9a4f48d941de51e7c0f83ff76408a07b9  grep-3.12.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/grep
SRC=$SRC_ROOT/grep-3.12
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf grep-3.12.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:

./configure --prefix=/usr --disable-nls --enable-perl-regexp
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/grep, 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 grep-3.12-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/grep, and runs the triggers its paths call for.

Contents

Installed programs: egrep, fgrep, grep.

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

Short descriptions

grep print lines that match patterns