8.9. Bzip2-1.0.8

The Bzip2 package contains programs for compressing and decompressing files. Compressing text files with bzip2 yields a much better compression percentage than with the traditional gzip.

Approximate build time: less than 0.1 SBU
Required disk space: 7.2 MB

8.9.1. Installation of Bzip2

Create the PKGBUILD for the Bzip2 package with the following commands:

mkdir /sources/bzip2
cd /sources/bzip2
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>

pkgname="bzip2"
pkgver="1.0.8"
pkgrel="2"
pkgdesc="The Bzip2 package contains programs for compressing and decompressing files with bzip2 compression."
arch=('x86'
'x86_64')
url="https://sourceware.org/bzip2/"
groups=('core')
license=('BSD3C'
         'custom')
depends=('glibc')
makedepends=('bash'
             'binutils'
             'coreutils'
             'diffutils'
             'gcc'
             'make'
             'patch')
source=('https://www.sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz'
        'https://www.linuxfromscratch.org/patches/lfs/development/bzip2-1.0.8-install_docs-1.patch')
md5sums=('67e051268d0c475ea773822f7500d0e5'
         '6a5ac7e89b791aae556de0f745916f7f')

prepare(){
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -Np1 -i ${srcdir}/${pkgname}-${pkgver}-install_docs-1.patch
  sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile
  sed -i "s@(PREFIX)/man@(PREFIX)/share/man@g" Makefile

  # Add largefile support to libbz2
  sed -e 's/^CFLAGS=\(.*\)$/CFLAGS=\1 \$(BIGFILES)/' \
      -i Makefile-libbz2_so

  # Use makepkg's CFLAGS
  sed "s|-O2|${CFLAGS}|g" -i Makefile
  sed "s|-O2|${CFLAGS}|g" -i Makefile-libbz2_so
}

build(){
  cd ${srcdir}/${pkgname}-${pkgver}
  make -f Makefile-libbz2_so
  make clean
  make
}

check(){
  cd ${srcdir}/${pkgname}-${pkgver}
  make test
}

package(){
  cd "${srcdir}/${pkgname}-${pkgver}"
  make PREFIX="${pkgdir}/usr" install
  install -vm755 libbz2.so.* "${pkgdir}/usr/lib"
  ln -sv "libbz2.so.${pgkver}" "${pkgdir}/usr/lib/libbz2.so"
  install -vm755  bzip2-shared "${pkgdir}/usr/bin/bzip2"
  rm -v "${pkgdir}"/usr/bin/{bunzip2,bzcat}
  ln -sv bzip2 "${pkgdir}/usr/bin/bunzip2"
  ln -sv bsip2 "${pkgdir}/usr/bin/bzcat"
}
REALEOF

The meaning of the make parameter:

-f Makefile-libbz2_so

This will cause Bzip2 to be built using a different Makefile file, in this case the Makefile-libbz2_so file, which creates a dynamic libbz2.so library and links the Bzip2 utilities against it.

Prepare the build directory for the pacman user and build the package:

chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps'

Add the newly created package to the central package repository:

cp bzip2-1.0.8-2-$(uname -m).pkg.tar.xz \
   /srv/pacman/repos/LFS/
repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \
         /srv/pacman/repos/LFS/bzip2-1.0.8-2-$(uname -m).pkg.tar.xz

Update the local cache and install the Bzip2 package:

pacman -Syu
pacman -S bzip2 --overwrite \* -dd --noconfirm

Finally, copy the source files into the source repository and clean up the build directory:

mkdir /srv/pacman/source/LFS/bzip2
cp PKGBUILD /srv/pacman/source/LFS/bzip2
cd /sources
rm -rf bzip2

8.9.2. Contents of Bzip2

Installed programs: bunzip2 (link to bzip2), bzcat (link to bzip2), bzcmp (link to bzdiff), bzdiff, bzegrep (link to bzgrep), bzfgrep (link to bzgrep), bzgrep, bzip2, bzip2recover, bzless (link to bzmore), and bzmore
Installed libraries: libbz2.so
Installed directory: /usr/share/doc/bzip2-1.0.8

Short Descriptions

bunzip2

Decompresses bzipped files

bzcat

Decompresses to standard output

bzcmp

Runs cmp on bzipped files

bzdiff

Runs diff on bzipped files

bzegrep

Runs egrep on bzipped files

bzfgrep

Runs fgrep on bzipped files

bzgrep

Runs grep on bzipped files

bzip2

Compresses files using the Burrows-Wheeler block sorting text compression algorithm with Huffman coding; the compression rate is better than that achieved by more conventional compressors using Lempel-Ziv algorithms, like gzip

bzip2recover

Tries to recover data from damaged bzipped files

bzless

Runs less on bzipped files

bzmore

Runs more on bzipped files

libbz2

The library implementing lossless, block-sorting data compression, using the Burrows-Wheeler algorithm