# Template file for 'tzutils'
pkgname=tzutils
version=2022b
revision=1
bootstrap=yes
wrksrc="tzdb-${version}"
short_desc="Time zone and daylight-saving time utilities"
maintainer="Đoàn Trần Công Danh <congdanhqx@gmail.com>"
license="Public Domain"
homepage="https://www.iana.org/time-zones"
distfiles="https://www.iana.org/time-zones/repository/releases/tzdb-${version}.tar.lz"
checksum=ac7e86da284b303244c457337ff5a4d17a4617a25777c87946668a1705f7b7ec

if [ "$CROSS_BUILD" ]; then
	hostmakedepends="tzutils"
fi

if [ "$XBPS_TARGET_WORDSIZE" = 32 ]; then
	# enforce 64-bit time_t for Y2038
	CFLAGS="-Dtime_tz=int64_t"
	license+=", BSD-3-Clause"
fi

do_build() {
	touch version
	make KSHELL=/bin/sh \
		CC=$CC CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
	sed -n '/Copyright/,/SUCH DAMAGE/p' strftime.c >strftime.license
}

do_check() {
	make check
}

do_install() {
	local zic
	if [ "$CROSS_BUILD" ]; then
		zic="zic=/usr/bin/zic"
	fi
	make install DESTDIR="$DESTDIR" ZICDIR=/usr/bin $zic ZFLAGS="-b fat"
	rm -rf "$DESTDIR"/{etc,usr/lib,usr/share/man/man3}
	# Backward compatible links
	ln -s ../zoneinfo-posix "$DESTDIR/usr/share/zoneinfo/posix"
	ln -s ../zoneinfo-leaps "$DESTDIR/usr/share/zoneinfo/right"
	if [ "$XBPS_TARGET_WORDSIZE" = 32 ]; then
		vlicense strftime.license
	fi
}

tzdata_package() {
	short_desc="Time zone and daylight-saving time data"
	pkg_install() {
		vmove usr/share/man/man5
		vmove "usr/share/zoneinfo*"
	}
}
