# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=apr
pkgver=1.7.5
pkgrel=0
pkgdesc="The Apache Portable Runtime"
url="https://apr.apache.org/"
arch="all"
license="Apache-2.0"
depends_dev="util-linux-dev"
makedepends="$depends_dev"
subpackages="$pkgname-dev"
source="https://www.apache.org/dist/apr/apr-$pkgver.tar.bz2
	apr-1.6.2-dont-test-dlclose.patch
	semtimedop-s390x.patch
	"

# secfixes:
#   1.7.5-r0:
#     - CVE-2023-49582
#   1.7.1-r0:
#     - CVE-2022-24963
#     - CVE-2022-25147
#     - CVE-2022-28331
#   1.7.0-r2:
#     - CVE-2021-35940

build() {
	case "$CARCH" in
	x86)
		# apr before 1.7.3 implicitly disabled these for i*86
		# now that they're enabled, it seems to fail tests instead
		local atomics=no
		;;
	*)
		local atomics=yes
		;;
	esac
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--datadir=/usr/share \
		--enable-nonportable-atomics=$atomics \
		--with-devrandom=/dev/urandom
	make
}

check() {
	make -j1 check
}

package() {
	make DESTDIR="$pkgdir" install
}

# basicly everything thats not a *.so* file belongs to the -dev package
# we override the pre-defined func.
dev() {
	depends="$pkgname=$pkgver-r$pkgrel $depends_dev"
	mkdir -p "$subpkgdir"
	mv "$pkgdir"/* "$subpkgdir"/
	mkdir -p "$pkgdir"/usr/lib
	mv "$subpkgdir"/usr/lib/*.so* "$pkgdir"/usr/lib/
}

sha512sums="
d8a7553642da0c81261ac3992536efd9d43ecb9154934ef1a10ae808d6a3ce8198b40433091d3a6d04f61e67c59426fb5276193a37e810ae4bc74a8a10fb651b  apr-1.7.5.tar.bz2
9fb931e45f30fbe68af56849dfca148c09cdf85e300af14fb259cbd43470113288680bdb21189d4cf13f5ce95f8d28666822535e017e64ace5324339ab50cbef  apr-1.6.2-dont-test-dlclose.patch
5d1afa9419d0481e7c3369724e8b4c1e199cbfd5d031bd9d9fc4f46ee0d3819353ff03c3b2c508d5b939f66ef4549953bbf9cdae7ff934002b9a01d824c843e8  semtimedop-s390x.patch
"
