# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gnu-libiconv
pkgver=1.17
pkgrel=2
pkgdesc="GNU charset conversion library for libc which doesn't implement it"
url="https://www.gnu.org/software/libiconv"
arch="all"
license="LGPL-2.1-or-later"
depends_dev="$pkgname=$pkgver-r$pkgrel"
source="https://ftp.gnu.org/pub/gnu/libiconv/libiconv-$pkgver.tar.gz"
subpackages="$pkgname-doc $pkgname-dev $pkgname-libs"
builddir="$srcdir"/libiconv-$pkgver
options="!check"  # fails to detect correct libiconv.so.2

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--docdir=/usr/share/doc/$pkgname/ \
		--disable-nls \
		--disable-static \
		--enable-extra-encodings
	# since users of this package use this package to work around missing features in musls iconv,
	# enable extra encodings (like the CP437) to be closer to glibcs iconv.

	# work around rpath issue
	sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
	sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
	make
}

check() {
	make check
}

package() {
	# iconv util
	license="GPL-3.0-or-later"
	make DESTDIR="$pkgdir/" install

	# move headers so they dont clash with libc headers
	mkdir "$pkgdir"/usr/include/gnu-libiconv
	mv "$pkgdir"/usr/include/*.h "$pkgdir"/usr/include/gnu-libiconv
	mv "$pkgdir"/usr/bin/iconv "$pkgdir"/usr/bin/gnu-iconv

}

sha512sums="
18a09de2d026da4f2d8b858517b0f26d853b21179cf4fa9a41070b2d140030ad9525637dc4f34fc7f27abca8acdc84c6751dfb1d426e78bf92af4040603ced86  libiconv-1.17.tar.gz
"
