# Copyright 2025 illogician <illogician@tutamail.com>
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit autotools flag-o-matic

DESCRIPTION="MicroGnuEmacs clone featuring added modes, Unicode support, and more"
HOMEPAGE="https://github.com/paaguti/mg3a"
SRC_URI="https://github.com/paaguti/${PN}/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="custom"
SLOT="0"
KEYWORDS="amd64 arm arm64 riscv x86"
IUSE="+dired +pipein +prefixregion slow mouse +pythonmode makemode cmode +clikemode +usermodes +usermacros ucsnames +searchall searchsimple searchenter noobjs backups minidired"

DEPEND="sys-libs/ncurses[tinfo]"
RDEPEND="${DEPEND}"
BDEPEND="virtual/pkgconfig"

src_prepare() {
	default
	head -n 17 Makefile.am >> Makefile.am.new && rm Makefile.am && mv Makefile.am.new Makefile.am
	./bootstrap.sh
}

src_configure() {
	eapply "${FILESDIR}"/fileio-c.patch

	append-libs -ltinfo
	append-cflags -std=gnu17
	econf \
		$(use_enable dired) \
		$(use_enable pipein) \
		$(use_enable prefixregion) \
		$(use_enable slow) \
		$(use_enable mouse) \
		$(use_enable pythonmode) \
		$(use_enable makemode) \
		$(use_enable cmode) \
		$(use_enable clikemode) \
		$(use_enable usermodes) \
		$(use_enable usermacros) \
		$(use_enable ucsnames) \
		$(use_enable searchall) \
		$(use_enable searchsimple) \
		$(use_enable searchenter) \
		$(use_enable noobjs) \
		$(use_enable backups) \
		$(use_enable minidired)
}

src_compile() {
	emake
}

src_install() {
	mv mg mg3
	dobin mg3

	docompress -x /usr/share/doc/${P}
	dodoc ${WORKDIR}/${P}/README.*
	dodoc -r ${WORKDIR}/${P}/orig
	dodoc -r ${WORKDIR}/${P}/bl
}