8.21. BSD-Diffutils stage 2 main snapshot
Rebuild BSD-Diffutils in the final target environment so the diff-family tools match the completed userspace.
Input assumption: BSD-Diffutils-main.zip is already present in /sources from the chapter 4 source staging step.
Source URL: https://github.com/littlefly365/BSD-Diffutils/archive/refs/heads/main.zip
Snapshot note: this package is built from main, so upstream source content may change over time. The source archive staged by this book is pinned by scripts/sources.b2sums.
Upstream build note: upstream lists glibc or musl, clang or gcc, and bmake as requirements. The package uses BSD makefiles and does not ship a configure script.
Licenses:
- BSD-3-Clause
Dependencies:
- musl (libc)
- bmake
- bheaded
BSD-Diffutils is a BSD-style diff and comparison utility set. we need it to provide final target cmp, diff, diff3, and sdiff tools for validation, package builds, and day-to-day system work.
Extract and Enter the Source Tree
cd /sources
rm -rf BSD-Diffutils-main
unzip -q BSD-Diffutils-main.zip
cd BSD-Diffutils-main
Remove Bundled Build Outputs
find . \( \
-name '*.o' -o \
-name '*.po' -o \
-name '*.pico' -o \
-name '*.a' -o \
-name '*.d' -o \
-name '.depend' \
\) -exec rm -f {} +
Apply Compatibility and Layout Patches
sed -i '' \
-e '1s|^#!/bin/ksh -$|#!/bin/sh|' \
-e 's|^diff3prog=/usr/libexec/diff3prog$|diff3prog=/system/systembinaries/diff3prog|' \
-e 's|^export PATH=.*$|export PATH=/system/binaries:/system/systembinaries|' \
src/diff3/diff3.ksh
sed -i '' \
's|${DESTDIR}/usr/bin/diff3|${DESTDIR}/system/binaries/diff3|' \
src/diff3/Makefile
sed -i '' \
's|char[[:space:]]*\*splice(char \*, char \*);|char *diff_splice(char *, char *);|' \
src/diff/diff.h
sed -i '' \
-e 's|= splice(|= diff_splice(|g' \
-e 's|^splice(char \*dir, char \*file)|diff_splice(char *dir, char *file)|' \
src/diff/diff.c src/diff/diffreg.c
sed -i '' \
's|u_char ch, \*p1, \*p2;|unsigned char ch, *p1, *p2;|' \
src/cmp/regular.c
Build BSD-Diffutils
for d in common cmp diff diff3 sdiff; do
CC=cc \
CPPFLAGS='-D__dead=__attribute__\(\(__noreturn__\)\)' \
CFLAGS="-O2 $LWI_CFLAGS" \
LDFLAGS="$LBI_CUSTOM_LDFLAGS" \
bmake -C "src/$d" $LWI_MAKE_FLAGS
done
Install BSD-Diffutils
install -d /system/binaries /system/systembinaries
for d in cmp diff sdiff; do
CC=cc \
CPPFLAGS='-D__dead=__attribute__\(\(__noreturn__\)\)' \
CFLAGS="-O2 $LWI_CFLAGS" \
LDFLAGS="$LBI_CUSTOM_LDFLAGS" \
bmake -C "src/$d" \
BINDIR=/system/binaries \
MANDIR=/system/documentation/man-pages \
STRIP_FLAG= \
BINOWN="$(id -un)" BINGRP="$(id -gn)" \
MANOWN="$(id -un)" MANGRP="$(id -gn)" \
install
done
CC=cc \
CPPFLAGS='-D__dead=__attribute__\(\(__noreturn__\)\)' \
CFLAGS="-O2 $LWI_CFLAGS" \
LDFLAGS="$LBI_CUSTOM_LDFLAGS" \
bmake -C src/diff3 \
BINDIR=/system/systembinaries \
MANDIR=/system/documentation/man-pages \
STRIP_FLAG= \
BINOWN="$(id -un)" BINGRP="$(id -gn)" \
MANOWN="$(id -un)" MANGRP="$(id -gn)" \
install
/sources if you do not plan to rebuild BSD-Diffutils again.
Command Explanations
rm -rf BSD-Diffutils-mainandunzip -q: Recreate a clean snapshot source tree.find . ... -exec rm -f {} +: Removes stale build artifacts from previous attempts.sed -i ... diff3.kshandsed -i ... Makefile: Patch shell, PATH, helper, and install locations for the book's layout.for d in common cmp diff diff3 sdiff; do ... bmake -C ...: Builds each BSD make subdirectory with target compiler settings.CPPFLAGS=...__dead...: Provides the BSD__deadattribute macro expected by the sources.install -d /system/binaries /system/systembinaries: Creates the command destination directories.bmake -C "src/$d" ... install: Installs each user-facing utility into/system/binaries.bmake -C src/diff3 ... BINDIR=/system/systembinaries: Installsdiff3proginto the system-binary directory used by the wrapper script.