6.8. BSD-Diffutils main snapshot
BSD-Diffutils provides BSD-style file and directory difference tools, built here from the upstream main branch snapshot.
Input assumption:
BSD-Diffutils-main.zip is already present in LBI_SOURCES from the chapter 4 source staging step.
Snapshot note: this package is built from
main.zip, so upstream source content may change over time.
Licenses:
- BSD-3-Clause
Dependencies:
- musl (libc)
- bmake (for building)
- bheaded (for BSD compatibility headers)
BSD-Diffutils is a BSD-style diff and comparison utility set. we need it to provide file and directory comparison tools for later validation and maintenance steps in the book.
Extract and Enter the Source Tree
cd "$LBI_SOURCES"
unzip -q BSD-Diffutils-main.zip
cd BSD-Diffutils-main
Apply Compatibility and Layout Patches
sed -i \
-e '1s|^#!/bin/ksh -$|#!/bin/sh|' \
-e 's|^diff3prog=/usr/libexec/diff3prog$|diff3prog=/systembinaries/diff3prog|' \
-e 's|^export PATH=.*$|export PATH=/binaries:/systembinaries:/bin:/usr/bin:/sbin:/usr/sbin|' \
src/diff3/diff3.ksh
sed -i \
's|${DESTDIR}/usr/bin/diff3|${DESTDIR}/system/binaries/diff3|' \
src/diff3/Makefile
sed -i \
's|char\\s*\\*splice(char \\*, char \\*);|char\t*diff_splice(char *, char *);|' \
src/diff/diff.h
sed -i \
's/\bsplice(/diff_splice(/g' \
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
CC="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang" \
CPPFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT -include ../../include/sys/cdefs.h" \
CFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT $LWI_CFLAGS" \
LDFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT $LBI_CUSTOM_LDFLAGS" \
bmake $LWI_MAKE_FLAGS
Install BSD-Diffutils
install -d "$LBI_ROOT/system/binaries"
for d in cmp diff sdiff; do
CC="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang" \
CPPFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT -include ../../include/sys/cdefs.h" \
CFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT $LWI_CFLAGS" \
LDFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT $LBI_CUSTOM_LDFLAGS" \
bmake -C "src/$d" \
DESTDIR="$LBI_ROOT" \
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="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang" \
CPPFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT -include ../../include/sys/cdefs.h" \
CFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT $LWI_CFLAGS" \
LDFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT $LBI_CUSTOM_LDFLAGS" \
bmake -C src/diff3 \
DESTDIR="$LBI_ROOT" \
BINDIR=/system/systembinaries \
MANDIR=/system/documentation/man-pages \
STRIP_FLAG= \
BINOWN="$(id -un)" BINGRP="$(id -gn)" \
MANOWN="$(id -un)" MANGRP="$(id -gn)" \
install
Command Explanations
unzip -q BSD-Diffutils-main.zip: Extracts the upstream snapshot archive quietly.sed -i ... src/diff3/diff3.ksh: Rewrites the helper script to use/bin/sh, the book'sdiff3proglocation, and the target command search path.sed -i ... src/diff3/Makefile: Changes thediff3install path from the upstream/usr/bindefault to/system/binaries.sed -i ... src/diff/diff.handsed -i ... src/diff/diff.c src/diff/diffreg.c: Rename the localsplicehelper so it does not collide with Linux'ssplice(2)declaration.sed -i ... src/cmp/regular.c: Replaces the BSDu_chartypedef with standardunsigned charfor portability on musl.CC="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang": Builds the target utilities with the target-prefixed Clang compiler.CPPFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT -include ../../include/sys/cdefs.h": Targets the sysroot and force-includes the BSD compatibilitycdefs.hheader needed by this codebase.CFLAGSandLDFLAGS: Keep compile and link steps on the target triple/sysroot while preserving local tuning variables.bmake $LWI_MAKE_FLAGS: Uses BSD make because this project uses BSD-style makefiles, while still honoring the shared make parallelism setting.install -d "$LBI_ROOT/system/binaries": Ensures the destination directory exists before package install rules run.for d in cmp diff sdiff; do ... done: Installs the normal user-facing comparison tools with the same cross-build settings.bmake -C "src/$d" ... install: Runs each utility's install rule from its own source directory.BINDIR=/system/binariesandMANDIR=/system/documentation/man-pages: Override BSD make install destinations to match the book's layout.STRIP_FLAG=: Prevents the install rule from stripping binaries automatically.BINOWN,BINGRP,MANOWN, andMANGRP: Use the current user and group so the non-root install intoLBI_ROOTsucceeds.bmake -C src/diff3 ... BINDIR=/system/systembinaries: Installsdiff3progsupport files into the system-binary directory where the patched script expects them.