# Template file for 'gettext'
pkgname=gettext
version=0.21
revision=4
build_style=gnu-configure
configure_args="--disable-java --disable-native-java --disable-csharp
 --disable-libasprintf --enable-threads=posix --disable-rpath --without-emacs
 --disable-acl --with-included-glib --with-included-libcroco --without-git
 --with-included-libxml --with-included-libunistring --disable-openmp
 --disable-curses --without-examples --enable-nls
 gl_cv_func_gettimeofday_clobber=no"
# gettext will try to use xz bzip2 gzip to compress
# /usr/share/gettext/archive.dir.tar.<ext>
# Either:
# - Have xz in hostmakedepends; or
# - Let gettext-devel depends on bzip2
hostmakedepends="xz"
short_desc="Internationalized Message Handling Library and tools"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="GPL-3.0-or-later"
homepage="https://www.gnu.org/software/gettext/"
changelog="https://git.savannah.gnu.org/cgit/gettext.git/plain/NEWS"
distfiles="${GNU_SITE}/${pkgname}/${pkgname}-${version}.tar.gz"
checksum=c77d0da3102aec9c07f43671e60611ebff89a996ef159497ce8e59d075786b12

subpackages="gettext-devel-examples gettext-devel gettext-devel-tools"
unset _intl_lib
if [ "$XBPS_TARGET_LIBC" = musl ]; then
	# force libintl
	configure_args+=" --with-included-gettext"
	subpackages+=" gettext-libs"
	_intl_lib=intl
else
	# on glibc, old gettext-libs conflicts with gettext
	replaces="gettext-libs>=0"
	conflicts="gettext-libs>=0"
fi

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" automake libtool"
	pre_configure() {
		autoreconf -fi
	}
fi

post_install() {
	# don't overwrite musl's header
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		vmkdir usr/include/gettext
		mv ${DESTDIR}/usr/include/libintl.h ${DESTDIR}/usr/include/gettext/libintl.h
	fi
}

gettext-devel-examples_package() {
	short_desc+=" - examples for development"
	pkg_install() {
		vmove usr/share/doc/gettext
	}
}

gettext-devel_package() {
	depends="${sourcepkg}>=${version}_${revision}
	 gettext-devel-tools>=${version}_${revision}"
	if [ -n "${_intl_lib}" ]; then
		depends+=" gettext-libs>=${version}_${revision}"
	fi
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.a"
		# libgettext{lib,src}-$version.so need to be in the main package
		for _lib in ${_intl_lib} gettextlib gettextpo gettextsrc textstyle
		do
			vmove "usr/lib/lib${_lib}.so"
		done
		vmove usr/share/man/man3
	}
}

gettext-devel-tools_package() {
	depends="${sourcepkg}>=${version}_${revision} tar xz"
	short_desc+=" - development tools"
	pkg_install() {
		vmove usr/share/aclocal
		vmove usr/bin/autopoint
		vmove usr/bin/gettextize
		vmove usr/share/man/man1/autopoint.1
		vmove usr/share/man/man1/gettextize.1
		vmove usr/share/gettext
	}
}

gettext-libs_package() {
	short_desc+=" - shared libraries"
	pkg_install() {
		vmove "usr/lib/libintl.so.*"
	}
}
