app=bzip2
version=1.0.6
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"

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

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

  # Taken from sabotage

  applypatch $srcdir/bzip2-flags.patch

  sed -i 's@$(PREFIX)@$(DESTDIR)$(PREFIX)@g' Makefile
  sed -i 's@$(PREFIX)/man@$(PREFIX)/share/man@g' Makefile

  sed -i 's@all: libbz2.a bzip2 bzip2recover test@all: libbz2.a bzip2 bzip2recover@' Makefile
  make -f Makefile-libbz2_so 
  make PREFIX="/" CFLAGS="-fPIC" 

  make install DESTDIR=$pkg PREFIX="/"
  install -m 0644 libbz2.so.1.0.6 $pkg/lib

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

  mkfinalpkg
}

sha512sums="
a8e36dd2987acb7f39fbfecc5207e9a18f5029b9254c75b0b832b72fa443a227f1e5490739707129ca325a6fab8acfd8fed9fec3330cdc67f4594147f84a1ba0  bzip2-1.0.6.tar.lz
8b8eff6348994c5d67691d3b4d53bd3e66785138c613737c1f38ac8c245412cde4efe44e671e9ee05c7216e9f895d7ef7212c1f76d31724f5016a3720aad335d  bzip2-flags.patch
"
