# Template file for 'libxcrypt'
pkgname=libxcrypt
version=4.4.36
revision=3
archs="~*-musl"
build_style=gnu-configure
configure_args="--enable-hashes=all --disable-failure-tokens --enable-obsolete-api=no"
make_cmd="make -C build"
hostmakedepends="perl-bootstrap"
checkdepends="python3-passlib"
short_desc="Modern library for one-way hashing of passwords"
maintainer="oreo639 <oreo639@gmail.com>"
license="LGPL-2.1-or-later, BSD-3-Clause, BSD-2-Clause, 0BSD, Public Domain"
homepage="https://github.com/besser82/libxcrypt"
distfiles="https://github.com/besser82/libxcrypt/releases/download/v${version}/libxcrypt-${version}.tar.xz"
checksum=e5e1f4caee0a01de2aee26e3138807d6d3ca2b8e67287966d1fefd65e1fd8943

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	broken="musl already provides libcrypt"
fi

do_configure() {
	[ ! -d ${configure_builddir:=build} ] && mkdir -p ${configure_builddir}
	cd ${configure_builddir}
	../configure ${configure_args}
}

post_configure() {
	configure_args="${configure_args/--enable-obsolete-api=no/} --enable-obsolete-api=glibc"
	configure_builddir="compat-build"
	do_configure
}

post_build() {
	make_cmd="make -C compat-build"
	do_build
}

post_check() {
	make_cmd="make -C compat-build"
	do_check
}

pre_install() {
	make -C compat-build DESTDIR=${DESTDIR} install
	# Don't install development files from the compat library
	rm -r ${DESTDIR}/usr/{include,lib/{lib*.so,pkgconfig},share}
}

post_install() {
	vlicense LICENSING
}

libxcrypt-devel_package() {
	short_desc+=" - development files"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/lib/pkgconfig
		vmove usr/include
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove usr/share
	}
}

libxcrypt-compat_package() {
	short_desc+=" - legacy compatibility"
	noverifyrdeps=yes
	pkg_install() {
		vmove usr/lib/libcrypt.so.1*
	}
}
