# Copyright 2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="Make Linux crash dump small by filtering and compressing pages"
HOMEPAGE="https://github.com/makedumpfile/makedumpfile"
SRC_URI="https://github.com/makedumpfile/makedumpfile/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"

# README talks about something with elfutils, special installation
# method, idk, just dump this and Hope It Works
#
# VDB thing complained about things not being in RDEPEND, so here's
# everything in DEPEND and RDEPEND instead of only BDEPEND
DEPEND="
	virtual/zlib
	dev-libs/elfutils
	lzo? (
		dev-libs/lzo
	)
	zstd? (
		app-arch/zstd:=
	)
	snappy? (
		app-arch/snappy
	)
"
RDEPEND="${DEPEND}"
IUSE="lzo zstd snappy debug"

# TODO: USE flags static(?)
# TODO: eppic stuff? wtf is that anywyas

devutil_crash_incompatibility() {
	ewarn "Note: dev-utils/crash::gentoo has no USE flags to support compressed dumps."
	ewarn "You won't be able to analyze compressed dumps, at least on Gentoo."
	ewarn "See https://bugs.gentoo.org/955818"
}

src_compile() {
	extra_args=""
	if use lzo; then
		extra_args+=" USELZO=on "
	fi
	if use zstd; then
		extra_args+=" USEZSTD=on "
	fi
	if use snappy; then
		extra_args+=" USESNAPPY=on "
	fi
	# no idea if this is actually useful but i'm doing it anyways
	if use debug; then
		extra_args+=" DEBUG=on "
	fi
	# seems to default to static? and that just breaks
	emake LINKTYPE=dynamic $extra_args
}

pkg_postinst() {
	if use lzo || use zstd || use snappy; then
		devutil_crash_incompatibility
	fi
}