6.10. bsdgrep master snapshot
bsdgrep provides a FreeBSD-derived grep implementation for Linux targets.
Input assumption:
bsdgrep-master.zip is already present in LBI_SOURCES from the chapter 4 source staging step.
Snapshot note: this package is built from
master, so upstream source content may change over time.
Licenses:
- BSD-2-Clause-FreeBSD
Dependencies:
- musl (libc)
- make
bsdgrep is a FreeBSD-derived grep implementation for Linux. we need it to provide grep, egrep, fgrep, and rgrep as BSD-style replacements in the target userspace.
Extract and Enter the Source Tree
cd "$LBI_SOURCES"
unzip -q bsdgrep-master.zip
cd bsdgrep-master
Apply Install Path Patch
sed -i \
-e 's|${DESTDIR}${PREFIX}/bin|${DESTDIR}/system/binaries|g' \
-e 's|${DESTDIR}${PREFIX}/share/man/man1|${DESTDIR}/system/documentation/man-pages/man1|g' \
Makefile
Build bsdgrep
CC="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang" \
CFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT -DREG_STARTEND=0 $LWI_CFLAGS" \
LDFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT $LBI_CUSTOM_LDFLAGS" \
make $LWI_MAKE_FLAGS
Install bsdgrep
DESTDIR="$LBI_ROOT" make install
Command Explanations
unzip -q bsdgrep-master.zip: Extracts the upstream snapshot archive quietly.sed -i ... Makefile: Rewrites upstream install destinations from default prefix-relative paths to the book's binary and man-page directories.CC="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang": Builds bsdgrep with the target-prefixed Clang compiler.CFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT -DREG_STARTEND=0 $LWI_CFLAGS": Targets the selected sysroot and disablesREG_STARTENDuse for compatibility with the target regex implementation.LDFLAGS="--target=$LBI_TARGET --sysroot=$LBI_ROOT $LBI_CUSTOM_LDFLAGS": Links against the target sysroot while preserving local linker tuning.make $LWI_MAKE_FLAGS: Builds with the shared make parallelism setting.DESTDIR="$LBI_ROOT" make install: Installs into the target root using the patched Makefile paths.