8.13. bsdgrep stage 2 master snapshot
Rebuild bsdgrep in the final target environment so grep-family tools match the completed userspace.
Input assumption: bsdgrep-master.zip is already present in /sources from the chapter 4 source staging step.
Source URL: https://github.com/arp242/bsdgrep/archive/refs/heads/master.zip
Snapshot note: this package is built from master, 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 documents the standard make and make install flow. The Makefile installs grep, egrep, fgrep, and rgrep by default.
Licenses:
- BSD-2-Clause-FreeBSD
Dependencies:
- musl (libc)
- make
bsdgrep is a FreeBSD-derived grep implementation for Linux. we need it to provide final target grep, egrep, fgrep, and rgrep command behavior for package builds and system use.
Extract and Enter the Source Tree
cd /sources
rm -rf bsdgrep-master
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
bsdgrep does not ship a configure script, so lbi_configure is not applicable here.
make $LWI_MAKE_FLAGS \
CC=cc \
CFLAGS="-O2 -DREG_STARTEND=0 $LWI_CFLAGS" \
LDFLAGS="$LBI_CUSTOM_LDFLAGS"
Install bsdgrep
make install
/sources if you do not plan to rebuild bsdgrep again.
Command Explanations
rm -rf bsdgrep-masterandunzip -q: Recreate a clean source tree from the snapshot archive.sed -i ... Makefile: Rewrites upstream install paths to the book's binary and man-page locations.make $LWI_MAKE_FLAGS CC=cc: Builds with the target C compiler and shared make parallelism.CFLAGS="-O2 -DREG_STARTEND=0 $LWI_CFLAGS": Uses optimization, disables unsupported regex behavior, and preserves local C tuning.LDFLAGS="$LBI_CUSTOM_LDFLAGS": Applies local linker tuning.make install: Installs bsdgrep using the patched paths.