# Maintainer: PktSurf <smlinux@pktsurf.in>
app=bzip2
version=1.0.8
build=1sml
homepage="https://sourceware.org/$app/"
download="https://sourceware.org/pub/bzip2/bzip2-$version.tar.gz"
requires="musl"
desc="block-sorting file compressor based on Burrows-Wheeler text compression algorithm"

prepbuilddir() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version
  fixbuilddirpermissions
}

build() {
  # Prevent tests from running
  sed -i 's@all: libbz2.a bzip2 bzip2recover test@all: libbz2.a bzip2 bzip2recover@' Makefile

  # Prep the shared library and then all binaries
  make -f Makefile-libbz2_so
  make $MAKEFLAGS

  # Copy headers, the shared library and the binaries
  install -Dm 644 bzlib.h $pkg/usr/include/bzlib.h
  install -Dm 755 libbz2.so.$version $pkg/usr/lib/libbz2.so.$version

  # Copy binaries
  install -Dm 755 bzdiff $pkg/bin/bzdiff
  install -Dm 755 bzgrep $pkg/bin/bzgrep 
  install -Dm 755 bzmore $pkg/bin/bzmore
  install -Dm 755 bzip2-shared $pkg/bin/bzip2
  install -Dm 755 bzip2recover $pkg/bin/bzip2recover

  # And man pages
  mkdir -p $pkg/usr/share/man/man1
  for manpage in bzip2.1 bzdiff.1 bzgrep.1 bzmore.1 ; do
    cp $manpage $pkg/usr/share/man/man1/
  done

  cp LICEN?E $pkgdocs/
  
  (
   cd $pkg/usr/lib
   ln -sf libbz2.so.$version libbz2.so.1.0
   ln -sf libbz2.so.$version libbz2.so

   cd $pkg/bin
   ln -sf bzip2 bunzip2
   ln -sf bzip2 bzcat
   ln -sf bzmore bzless
  )

  mkfinalpkg
}

sha512sums="
5c2e4a3dd274ddd4c4c3d6bb4dc9c6fc64315229184bf05f26e439f998c36c4f422f5f1da3c4c6b0992378be05dc0728e54d26f377056140aae767086ceaae35  bzip2-1.0.8.tar.lz
"
