# Template file for 'libhugetlbfs'
pkgname=libhugetlbfs
version=2.23
revision=1
# fails to build on musl (relies on glibc specifics) + only for these archs
archs="x86_64 i686 armv[67]l aarch64 ppc64le ppc64 ppc"
build_style=gnu-makefile
make_build_args="ARCH=${XBPS_TARGET_MACHINE%-*} LIB32=lib32 LIB64=lib64 BUILDTYPE=NATIVEONLY"
make_install_args="${make_build_args}"
short_desc="Library to deal with hugetlbfs"
maintainer="q66 <daniel@octaforge.org>"
license="LGPL-2.1-or-later"
homepage="https://github.com/libhugetlbfs/libhugetlbfs"
distfiles="https://github.com/${pkgname}/${pkgname}/releases/download/${version}/${pkgname}-${version}.tar.gz"
checksum=b70672f1e807c61b7eb3adf41c1903b42917951f2e7f8aef6821841700c04479
CFLAGS="-fPIC"

do_check() {
	# requires mounted hugetlbfs
	:
}

post_extract() {
	vsed -i 's,CUSTOM_LDSCRIPTS = yes,CUSTOM_LDSCRIPTS = no,' Makefile
}

post_install() {
	# only needed with old binutils, and wrong for some of our setups
	rm -rf ${DESTDIR}/usr/share/libhugetlbfs/ldscripts
	# don't need this
	rm -f ${DESTDIR}/usr/lib/libhugetlbfs_privutils.so
	# soname
	mv ${DESTDIR}/usr/lib/libhugetlbfs.so ${DESTDIR}/usr/lib/libhugetlbfs-${version}.so
	ln -s libhugetlbfs-${version}.so ${DESTDIR}/usr/lib/libhugetlbfs.so.0
	ln -s libhugetlbfs.so.0 ${DESTDIR}/usr/lib/libhugetlbfs.so
	# ld
	rm ${DESTDIR}/usr/share/${pkgname}/ld
	mv ${DESTDIR}/usr/share/${pkgname}/ld.hugetlbfs ${DESTDIR}/usr/bin
}

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

libhugetlbfs-tools_package() {
	short_desc="Tools to ease use of hugetlbfs"
	pkg_install() {
		vmove usr/bin
		vmove usr/share/man/man1
		vmove usr/share/man/man8
	}
}
