# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=gettext
pkgver=0.24.1
pkgrel=0
pkgdesc="GNU locale utilities"
url="https://www.gnu.org/software/gettext/gettext.html"
arch="all"
license="GPL-3.0-or-later AND LGPL-2.1-or-later AND MIT"
# do _not_ add the optional dependencies on libcroco or glib
# they depend on gettext and would introduce cyclic dependencies
# xz for autopoint autoreconf
depends_dev="!musl-libintl xz"
makedepends="perl ncurses-dev libxml2-dev~2.13 libunistring-dev"
checkdepends="coreutils"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-static
	$pkgname-dev
	$pkgname-lang
	$pkgname-envsubst:_envsubst
	libintl
	$pkgname-asprintf
	$pkgname-libs
	"
source="https://ftp.gnu.org/gnu/gettext/gettext-$pkgver.tar.xz
	cwd.patch
	skip-tests-musl.patch
	skip-meaningless-pthread-rwlock-test.patch
	"

# secfixes:
#   0.20.1-r0:
#     - CVE-2018-18751

build() {
	# force using system posix complaint printf
	# the test is broken and fails with ash
	gt_cv_func_printf_posix=yes \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--enable-threads=posix \
		--disable-java \
		--enable-static
	make
}

check() {
	case "$CARCH" in
		# test-verify fails if run in parallel
		# test-memset_explicit fails on armhf if -Os/-01 are set in CFLAGS/LDFLAGS
		armhf) make -j1 check CFLAGS="${CFLAGS/-Os/}" LDFLAGS="${LDFLAGS/-O1,/}" ;;
		*) make -j1 check ;;
	esac

}

package() {
	depends="$pkgname-envsubst=$pkgver-r$pkgrel"
	make -j1 DESTDIR="$pkgdir" install

	# nothing in here is particularly useful, mostly just hello world examples in
	# every single programming language for using gettext
	rm -r "$pkgdir"/usr/share/doc
}

libintl() {
	pkgdesc="GNU gettext runtime library"
	license="LGPL-2.1-or-later"

	amove usr/lib/libintl.so.*
	chmod +x "$subpkgdir"/usr/lib/libintl.so.*
}

asprintf() {
	pkgdesc="GNU gettext asprintf library"
	license="LGPL-2.1-or-later"

	amove usr/lib/libasprintf.so.*
}

_envsubst() {
	pkgdesc="GNU gettext envsubst binary"
	provides="envsubst"
	provider_priority=100 # highest (other provider of cmd:envsubst is testing/envsubst)

	amove usr/bin/envsubst
}

sha512sums="
53d5c54105598cc6156b940ff82d9754f4b7cdeafcd2400206c975db9412012511b60a7ebefcd31068a0bc2d99173ecd93a66844c7f3a9772df69d53b3cebeb5  gettext-0.24.1.tar.xz
31796534e40c1569b08cf48e25375ca1d0f439df8aa0d24283769d52a290e28522760128f11f5bd04217605974ae1fdee9557ec189ed32b11b2a45b4af3b0f4a  cwd.patch
a16963f804ce4abe8480da211228f7b24a0715d6ef3ff7d5e5c58a1387d6c4260ee237864081b05b164f082ef199a592494ce691dd0c96c61978e4c451707c7a  skip-tests-musl.patch
e426f3a3bc39193e0dbf8d51e0019e672ddcab07b277281a1912fd0ec6a3fea5eb59bc4daeed465e152c567b05d6c3b457e4bc415a8d36dd768725fb72daf817  skip-meaningless-pthread-rwlock-test.patch
"
