# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=nspr
pkgver=4.36
pkgrel=0
pkgdesc="Netscape Portable Runtime"
url="https://www.mozilla.org/projects/nspr/"
arch="all"
license="MPL-2.0"
options="!check"  # No test suite.
# -dev package does not ship any symlinks so dependency cannot be autodetected
depends_dev="$pkgname=$pkgver-r$pkgrel linux-headers"
makedepends="autoconf automake linux-headers"
subpackages="$pkgname-dev"
source="https://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v$pkgver/src/nspr-$pkgver.tar.gz
	lfs64.patch
	"

prepare() {
	mkdir build inst
	default_prepare
	update_config_sub
}

build() {
	local conf=
	case "$CARCH" in
		arm*|x86) conf="";;
		*) conf="--enable-64bit";;
	esac
	cd "$builddir"/build
	# ./nspr/pr/include/md/_linux.h tests only __GLIBC__ version
	# to detect c-library features, list musl features here for now.
	CFLAGS="$CFLAGS -D_PR_POLL_AVAILABLE -D_PR_HAVE_OFF64_T -D_PR_INET6 -D_PR_HAVE_INET_NTOP -D_PR_HAVE_GETHOSTBYNAME2 -D_PR_HAVE_GETADDRINFO -D_PR_INET6_PROBE" \
	../nspr/configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--disable-debug \
		--enable-optimize \
		--enable-ipv6 \
		$conf
	make CC="${CC:-gcc}" CXX="${CXX:-g++}"
}

package() {
	cd "$builddir"/build
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"/usr/lib
	rm -f -- *.a

	cd "$builddir"/build/config
	install -Dm755 nspr-config "$pkgdir"/usr/bin/nspr-config
	install -Dm644 nspr.pc "$pkgdir"/usr/lib/pkgconfig/nspr.pc
	rm -rf "$pkgdir"/usr/bin/prerr.properties \
		"$pkgdir"/usr/bin/compile-et.pl \
		"$pkgdir"/usr/share/aclocal/nspr.m4 \
		"$pkgdir"/usr/include/nspr/md
}

sha512sums="
55d21e196508ad29a179639fc8006f44b04dc2c0b5a85895e727f0a4f0ea37aeeceb936e37ac6b271b882a18e9f06d96133a60f19cee6345f8424c1c66e270ee  nspr-4.36.tar.gz
626208e91c296bb26cee84e2b5dcc2ff2d576e06dacf7008655590c0b76ea21cb33cd96994fad3b0e771e8d7d60a3d90f71f81f33a8e9c1b7ce8536f5c6cab8a  lfs64.patch
"
