SUMMARY="An extensible, customizable, free/libre text editor — and more"
DESCRIPTION="An extensible, customizable, free/libre text editor — and more.
At its core is an interpreter for Emacs Lisp, a dialect of the Lisp programming language with \
extensions to support text editing.

* Content-aware editing modes, including syntax coloring, for many file types.
* Complete built-in documentation, including a tutorial for new users.
* Full Unicode support for nearly all human scripts.
* Highly customizable, using Emacs Lisp code or a graphical interface.
* An entire ecosystem of functionality beyond text editing, including a project planner, mail and \
news reader, debugger interface, calendar, and more.
* A packaging system for downloading and installing extensions."
HOMEPAGE="https://gnu.org/s/emacs/"
COPYRIGHT="2001-2022 Free Software Foundation, Inc."
LICENSE="GNU GPL v3"
REVISION="4"
srcGitRev="018eeb655aa66ce1f32288ed2c23c042877a578b"
SOURCE_URI="https://github.com/emacs-mirror/emacs/archive/$srcGitRev.tar.gz"
SOURCE_DIR="emacs-$srcGitRev"
CHECKSUM_SHA256="e309ee93279d681f2c2b0cd3abe823e0ac222c060809d7c32cfe36499ec95742"
ADDITIONAL_FILES="emacs.rdef.in"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	emacs$secondaryArchSuffix = $portVersion
	app:Emacs = $portVersion
	cmd:ctags.emacs$commandSuffix = $portVersion
	cmd:ebrowse$commandSuffix = $portVersion
	cmd:emacs$commandSuffix = $portVersion
	cmd:emacsclient$commandSuffix = $portVersion
	cmd:emacs_${portVersion%\~*}$commandSuffix = $portVersion
	cmd:etags$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libexecinfo$secondaryArchSuffix
	lib:libgio_2.0$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libgnutls$secondaryArchSuffix
	lib:libgobject_2.0$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjansson$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libexecinfo$secondaryArchSuffix
	devel:libgio_2.0$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libgnutls$secondaryArchSuffix
	devel:libgobject_2.0$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjansson$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:autoreconf
	cmd:awk
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:g++$secondaryArchSuffix
	cmd:grep
	cmd:gzip
	cmd:install_info
	cmd:make
	cmd:makeinfo
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage emacs$secondaryArchSuffix \
	$appsDir/Emacs \
	$commandBinDir/ctags.emacs \
	$commandBinDir/emacs-${portVersion%\~*} \
	$commandBinDir/emacsclient \
	$commandBinDir/etags

BUILD()
{
	autoreconf -vfi -I m4

	runConfigure --omit-dirs "binDir sbinDir" ./configure \
		--bindir="$commandBinDir" \
		--sbindir="$commandBinDir" \
		--with-be-app

	make $jobArgs
}

INSTALL()
{
	# 'make install' assumes this directory already exists
	mkdir -p $appsDir

	make install

	# clean up files that aren't useful on Haiku
	rm -rf \
		$dataDir/applications \
		$dataDir/icons \
		$dataDir/metainfo \
		$libDir/systemd

	# rename ctags so that the official ctags can be installed alongside without conflicting
	mv $commandBinDir/ctags $commandBinDir/ctags.emacs

	# add our version and vector icon resources
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "${portVersion%\~*}" | cut -d. -f3`"

	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|B_APPV_FINAL|B_APPV_DEVELOPMENT|" \
		$portDir/additional-files/emacs.rdef.in > emacs.rdef

	addResourcesToBinaries emacs.rdef $appsDir/Emacs

	addAppDeskbarSymlink $appsDir/Emacs Emacs
}

TEST()
{
	make check
}
