# Template file for 'dosfstools'
pkgname=dosfstools
version=4.2
revision=0
short_desc="FAT filesystem utilities (mkfs.fat, fsck.fat)"
maintainer="finwo <finwo@pm.me>"
license="GPL-3.0-or-later"
homepage="https://github.com/dosfstools/dosfstools"
distfiles="https://github.com/dosfstools/dosfstools/releases/download/v${version}/dosfstools-${version}.tar.gz"
checksum=64926eebf90092dca21b14259a5301b7b98e7b1943e8a201c7d726084809b527
depends="glibc busybox"

# Notes:
# - Why: the ESP is FAT, so the installer creates one on every install and a
#   rescue image needs to be able to REPAIR one. busybox has an mkfs.vfat
#   applet but no fsck for FAT at all, which means a corrupt ESP -- the single
#   partition that decides whether the switch boots -- was unfixable in place.
# - busybox's MKFS_VFAT applet is disabled in packages/busybox/template so
#   there is exactly one mkfs.vfat on the system. Two providers of the same
#   command name resolved by PATH order is the kind of ambiguity that only
#   shows up when the two behave differently; busybox's also emits codepage
#   warnings on every run because it wants iconv data our glibc does not carry.
# - iconv/nls off: the codepage machinery is for long-filename charset
#   conversion, which an ESP does not need and which our C.UTF-8-only glibc
#   cannot satisfy anyway.

do_configure() {
	cd "${WRKSRC}"
	./configure \
		--prefix=/usr \
		--sbindir=/usr/sbin \
		--mandir=/usr/share/man \
		--enable-compat-symlinks \
		--without-udev \
		--without-iconv
}

do_build() {
	cd "${WRKSRC}"
	make -j"$(nproc)"
}

do_install() {
	cd "${WRKSRC}"
	make install DESTDIR="${DESTDIR}"

	rm -rf "${DESTDIR}/usr/share/doc" "${DESTDIR}/usr/share/locale"

	# --enable-compat-symlinks gives the names callers actually use:
	# installer/install.sh invokes mkfs.vfat, and fsck.vfat is what anyone
	# reaching for a FAT repair will type.
	for t in mkfs.fat fsck.fat mkfs.vfat fsck.vfat fatlabel; do
		[ -e "${DESTDIR}/usr/sbin/${t}" ] || die "dosfstools: missing ${t}"
	done
}
