# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=bzip2
pkgver=1.0.6
pkgrel=6
pkgdesc="A high-quality data compression program"
url="http://sources.redhat.com/bzip2"
arch="all"
license="BSD"
depends=""
subpackages="$pkgname-dev $pkgname-doc libbz2"
source="http://www.bzip.org/$pkgver/$pkgname-$pkgver.tar.gz
	bzip2-1.0.4-makefile-CFLAGS.patch
	bzip2-1.0.6-saneso.patch
	bzip2-1.0.4-man-links.patch
	bzip2-1.0.2-progress.patch
	bzip2-1.0.3-no-test.patch
	bzip2-1.0.4-POSIX-shell.patch
	CVE-2016-3189.patch
	"

# secfixes:
#   1.0.6-r5:
#   - CVE-2016-3189

builddir="$srcdir"/$pkgname-$pkgver
prepare() {
	default_prepare

	# Fix man path
	# Generate relative symlinks
	sed -i \
		-e 's:\$(PREFIX)/man:\$(PREFIX)/share/man:g' \
		-e 's:ln -s -f $(PREFIX)/bin/:ln -s :' \
		Makefile

	# fixup broken version stuff
	sed -i \
		-e "s:1\.0\.4:$pkgver:" \
		bzip2.1 bzip2.txt Makefile-libbz2_so manual.*
}

build () {
	cd "$builddir"
	make -f Makefile-libbz2_so all
	make all
}

check() {
	cd "$builddir"
	make check
}

package() {
	cd "$builddir"
	make PREFIX="$pkgdir"/usr install
	install -D libbz2.so.$pkgver "$pkgdir"/usr/lib/libbz2.so.$pkgver
	ln -s libbz2.so.$pkgver "$pkgdir"/usr/lib/libbz2.so
	ln -s libbz2.so.$pkgver "$pkgdir"/usr/lib/libbz2.so.${pkgver%%.*}
}

libbz2() {
	pkgdesc="Shared library for bz2"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*.so.* "$subpkgdir"/usr/lib/
}

sha512sums="00ace5438cfa0c577e5f578d8a808613187eff5217c35164ffe044fbafdfec9e98f4192c02a7d67e01e5a5ccced630583ad1003c37697219b0f147343a3fdd12  bzip2-1.0.6.tar.gz
58cc37430555520b6e35db2740e699cf37eacdd82989c21a222a593e36288710a0defb003662d4238235c12b3764bfc89cd646e6be9d0a08d54bd2c9baa6ad15  bzip2-1.0.4-makefile-CFLAGS.patch
8a7528b5b931bb72f637c6940bc811d54fb816fd5bb453af56d9b4a87091004eb5e191ba799d972794b24c56cf8134344a618b58946d3f1d985c508f88190845  bzip2-1.0.6-saneso.patch
2d9a306bc0f552a58916ebc702d32350a225103c487e070d2082121a54e07f1813d3228f43293cc80a4bee62053fd597294c99a1751b1685cd678f4e5c6a2fe7  bzip2-1.0.4-man-links.patch
b6810c73428f17245e0d7c2decd00c88986cd8ad1cfe4982defe34bdab808d53870ed92cb513b2d00c15301747ceb6ca958fb0e0458d0663b7d8f7c524f7ba4e  bzip2-1.0.2-progress.patch
aefcafaaadc7f19b20fe023e0bd161127b9f32e0cd364621f6e5c03e95fb976e7e69e354ec46673a554392519532a3bfe56d982a5cde608c10e0b18c3847a030  bzip2-1.0.3-no-test.patch
64ab461bf739c29615383750e7f260abb2d49df7eb23916940d512bd61fd9a37aaade4d8f6f94280c95fc781b8f92587ad4f3dda51e87dec7a92a7a6f8d8ae86  bzip2-1.0.4-POSIX-shell.patch
cef6f448b661a775cc433f9636730e89c1285d07075536217657056be56e0a11e96f41f7c14f6ec59e235464b9ddd649a71fb8de1c60eda2fd5c2cdfbb6a8fdc  CVE-2016-3189.patch"
