8.32. libarchive stage 2 3.8.7
libarchive provides archive libraries and BSD archive tools, including bsdtar, bsdcpio, and bsdunzip.
Input assumption:
libarchive-3.8.7.tar.xz is already present in LBI_SOURCES from the chapter 4 source staging step.
Licenses:
- BSD-2-Clause (primary)
- BSD-3-Clause, public domain, and other permissive notices in selected files
Dependencies:
- musl (libc)
- cmake
- make
- zlib-ng (libz)
libarchive is a multi-format archive reading and writing library plus BSD archive utilities. we need it to provide tar, cpio, and unzip command compatibility.
Extract and Enter the Source Tree
cd "/sources"
tar -xf libarchive-3.8.7.tar.xz
cd libarchive-3.8.7
Configure libarchive (CMake Path)
lbi_cmake build \
-DCMAKE_C_FLAGS="$LWI_CFLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS="$LBI_CUSTOM_LDFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LBI_CUSTOM_LDFLAGS" \
-DBUILD_SHARED_LIBS=ON \
-DENABLE_TAR=ON \
-DENABLE_CPIO=ON \
-DENABLE_UNZIP=ON \
-DENABLE_CAT=OFF \
-DENABLE_ZLIB=ON \
-DENABLE_OPENSSL=ON \
-DENABLE_BZip2=OFF \
-DENABLE_LZMA=OFF \
-DENABLE_ZSTD=OFF \
-DENABLE_LZ4=OFF \
-DENABLE_LZO=OFF \
-DENABLE_LIBB2=OFF \
-DENABLE_LIBXML2=OFF \
-DENABLE_EXPAT=OFF \
-DENABLE_ICONV=OFF \
-DENABLE_ACL=OFF \
-DENABLE_XATTR=OFF \
-DENABLE_TEST=OFF \
-G Ninja
Build libarchive
cmake --build build $LWI_MAKE_FLAGS
Install libarchive
cmake --install build
Normalize Installed Paths to LBI Layout
Path note: upstream
libarchive CMake install rules hardcode some destinations (bin, include, share/man). Move those outputs into the book's layout after install.
if [ -d "/system/bin" ]; then
mv "/system/bin/"* "/system/binaries/" 2>/dev/null || true
rmdir "/system/bin" 2>/dev/null || true
fi
if [ -d "/system/include" ]; then
mv "/system/include/"* "/system/headers/" 2>/dev/null || true
rmdir "/system/include" 2>/dev/null || true
fi
for sec in man1 man3 man5; do
if [ -d "/system/share/man/$sec" ]; then
mv "/system/share/man/$sec/"* \
"/system/documentation/man-pages/$sec/" 2>/dev/null || true
rmdir "/system/share/man/$sec" 2>/dev/null || true
fi
done
Remove static library
rm -f "/system/libraries/libarchive.a"
Provide tar, cpio, and unzip Commands
ln -sf bsdtar "/system/binaries/tar"
ln -sf bsdcpio "/system/binaries/cpio"
ln -sf bsdunzip "/system/binaries/unzip"
Command Explanations
cd /sources,tar -xf, andcd libarchive-...: Enter the staged libarchive source tree.lbi_cmake build: Configures libarchive with the book's CMake helper.-DBUILD_SHARED_LIBS=ON: Builds shared libarchive libraries.-DENABLE_TAR,-DENABLE_CPIO, and-DENABLE_UNZIP: Build the BSD archive command-line tools.-DENABLE_ZLIB,-DENABLE_LZMA, and-DENABLE_ZSTD: Enable selected compression backends available in the final target.cmake --build build $LWI_MAKE_FLAGSandcmake --install build: Build and install libarchive.mv /system/bin/*andmv /system/include/*: Normalize upstream install directories into/system/binariesand/system/headers.rm -f /system/libraries/libarchive.a: Removes the static archive after installing the shared library.ln -sf bsdtar,bsdcpio, andbsdunzip: Provide standardtar,cpio, andunzipcommand names.