50.1. bzip2-1.0.8
Block-sorting compressor: libbz2 and the bzip2, bunzip2 and bzcat commands
| Version | 1.0.8, release 3 |
| Shelf | archiver — Compression libraries and archive tools |
| Phase | 30_foundation (Build Foundation), 2 of 127 in build order |
| Licence | bzip2-1.0.6 |
| Homepage | https://sourceware.org/bzip2/ |
| Build time | 0.1 SBU |
| Installed size | 262.6 KiB in 26 files |
| Recipe | ports/core/archiver/bzip2/kpkgbuild |
About
bzip2 is the Burrows–Wheeler block-sorting compressor: the library libbz2 and the bzip2, bunzip2 and bzcat commands, with the bzgrep, bzmore and bzdiff scripts. Programs that open .bz2 files link the library, among them file, libarchive, elfutils and ffmpeg. It is the first of the archiver shelf in 30_foundation; no port of 20_selfhost needs it.
The source has no configure script, only two makefiles: Makefile-libbz2_so builds the shared library and a bzip2 linked against it, and Makefile builds the static library, a statically linked bzip2 and bzip2recover. Neither installs everything a distribution needs, so most of build.sh is the install done by hand.
Sources
bzip2-1.0.8.tar.gz(791.0 KiB)
sha256ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269
upstream: https://www.sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz
archive copy: sources-1/archiver--bzip2-1.0.8.tar.gz
Dependencies
Depends on: nothing a recipe names.
Required by (55): boost, botan, cfitsio, clamav, coin, devilutionx, elfutils, ffmpeg, file, freeciv, freetype2, gimp, gnuastro, gnupg, goldendict-ng, graphicsmagick, gst-plugins-bad, gst-plugins-good, handbrake, htslib, imagemagick, imhex, iverilog, john, karchive, kbd, libarchive, libewf, libgsf, libreoffice, libspectrum, libzip, lnav, lynx, minizip-ng, nbdkit, netcdf-c, octave, opencpn, openimageio, pcre2, perl, powder-toy, python3, qemu, quazip, R, ripgrep-all, routino, schismtracker, splat, thunderbird, unzip, viking, zip.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/30_foundation/phase.env && kpkg install bzip2'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/archiver/bzip2.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/archiver/bzip2
echo 'ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269 bzip2-1.0.8.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/bzip2
SRC=$SRC_ROOT/bzip2-1.0.8
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf bzip2-1.0.8.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
make -f Makefile-libbz2_so CC="gcc $LDFLAGS" CFLAGS="$CFLAGS -fPIC"
make clean
make CC="gcc $LDFLAGS" CFLAGS="$CFLAGS"
make PREFIX=$PKG/usr install
install -Dm755 libbz2.so.$version -t $PKG/usr/lib
ln -sf libbz2.so.$version $PKG/usr/lib/libbz2.so.1.0
ln -sf libbz2.so.$version $PKG/usr/lib/libbz2.so
install -m755 bzip2-shared $PKG/usr/bin/bzip2
ln -sf bzip2 $PKG/usr/bin/bunzip2
ln -sf bzip2 $PKG/usr/bin/bzcat
install -Dm644 /dev/stdin $PKG/usr/lib/pkgconfig/bzip2.pc <<EOF
prefix=/usr
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include
Name: bzip2
Description: Block-sorting file compression library
Version: $version
Libs: -L\${libdir} -lbz2
Cflags: -I\${includedir}
EOF
install -d $PKG/usr/share
mv $PKG/usr/man $PKG/usr/share/man
for l in bzegrep:bzgrep bzfgrep:bzgrep bzless:bzmore bzcmp:bzdiff; do
ln -sf ${l#*:} $PKG/usr/bin/${l%:*}
done
The switches, and why each is set:
CC="gcc $LDFLAGS"— the compiler, with the tree’s linker flags attached. The shared-library makefile’s link lines read noLDFLAGSvariable at all, so carrying the flags inCCis the one way to put them on every link.CFLAGS="$CFLAGS -fPIC"— given on the command line, this replaces each makefile’s ownCFLAGSline, which is-Wall -Winline -O2 -gwith-D_FILE_OFFSET_BITS=64: the tree’s flags are used, and no-g. On musloff_tis always 64 bits wide, so the dropped define changes nothing.-fPICrestates what the shared-library makefile’s own line carries; the tree’sCFLAGShold it already, and the static build is given the plain$CFLAGS.PREFIX=$PKG/usr— the makefile’s install target writes straight underPREFIXand takes noDESTDIR, so the staging directory goes into the prefix.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/bzip2, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf bzip2-1.0.8-3.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/bzip2, and runs the triggers its paths call for.
Contents
Installed programs: bunzip2, bzcat, bzcmp, bzdiff, bzegrep, bzfgrep, bzgrep, bzip2, bzip2recover, bzless, bzmore.
Installed libraries: libbz2.a, libbz2.so.
Installed directories: /usr/share/licenses/bzip2.
Short descriptions
bzdiff |
compare bzip2 compressed files |
bzgrep |
search possibly bzip2 compressed files for a regular expression |
bzip2 |
a block-sorting file compressor, v1.0.8 bzcat - decompresses files to stdout bzip2recover - recovers data from damaged bzip2 files |
bzmore |
file perusal filter for crt viewing of bzip2 compressed text |
bzip2.pc |
Block-sorting file compression library |
Notes
The make clean between the two builds deletes the first build’s objects. Both makefiles compile the same object names, so without it the second make would archive the shared-library build’s objects into libbz2.a instead of compiling its own. Makefile’s clean leaves libbz2.so.<version> and bzip2-shared in place for the install that follows.
The second make is upstream’s default target, which ends by running bzip2’s self-test: it compresses and decompresses the sample files and compares each result with cmp, from diffutils. A root without cmp fails this port’s build.
What build.sh does after make install, and why each step is there:
- It installs
libbz2.so.<version>and its two links,libbz2.so.1.0(the soname the library records) andlibbz2.so, which the makefile’s install leaves out. - It replaces the statically linked
bzip2the install copied withbzip2-shared, the one linked againstlibbz2.so, and makesbunzip2andbzcat, which the install wrote as copies, links to it. - It writes
bzip2.pc. The release ships no pkg-config file, and a build that looks for bzip2 through pkg-config reads this one. - It moves the manual pages from
/usr/man, where the makefile puts them, to/usr/share/man. - It remakes
bzegrep,bzfgrep,bzlessandbzcmpas relative links. The makefile creates them as links to$(PREFIX)/bin/…, which here is a path inside the staging directory, and would point nowhere once the package is installed.