SUMMARY="A highly configurable text editor"
DESCRIPTION="Vim is a highly configurable text editor built to enable \
efficient text editing. It is an improved version of the vi editor \
distributed with most UNIX systems.

Vim is often called a \"programmer's editor,\" and so useful for programming \
that many consider it an entire IDE. It's not just for programmers, though. \
Vim is perfect for all kinds of text editing, from composing email to editing \
configuration files.
Despite this, Vim can be configured to work in a very simple (Notepad-like) \
way, called evim or Easy Vim."
HOMEPAGE="https://www.vim.org/"
COPYRIGHT="1991-2021 Bram Moleenar et al."
LICENSE="Vim"
REVISION="2"
SOURCE_URI="https://github.com/vim/vim/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="b2a7860b8236e26baafacd459123216d3b860b0a1205f87d61cf25409887bd9c"
SOURCE_FILENAME="vim-$portVersion.tar.gz"

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	vim$secondaryArchSuffix = $portVersion
	cmd:ex$commandSuffix = $portVersion
	cmd:gview$commandSuffix = $portVersion
	cmd:gvim$commandSuffix = $portVersion
	cmd:gvimdiff$commandSuffix = $portVersion
	cmd:rgview$commandSuffix = $portVersion
	cmd:rgvim$commandSuffix = $portVersion
	cmd:rview$commandSuffix = $portVersion
	cmd:rvim$commandSuffix = $portVersion
	cmd:vi$commandSuffix = $portVersion
	cmd:view$commandSuffix = $portVersion
	cmd:vim$commandSuffix = $portVersion compat >= 8.1
	cmd:vimdiff$commandSuffix = $portVersion
	cmd:vimtutor$commandSuffix = $portVersion
	cmd:xxd$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix >= 6
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
#	devel:liblua$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix >= 6
#	devel:libtclstub8.5
	"

if [ $effectiveTargetArchitecture != "x86_gcc2" ] ; then
	BUILD_REQUIRES+="
		devel:libruby$secondaryArchSuffix
	"
fi

BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:gettext
	cmd:grep
#	cmd:lua
	cmd:make
#	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	cmd:ruby
	cmd:sed
	"

BUILD()
{

# Global ----------------------------------------

	cd src
	autoconf

	export CFLAGS="\
		`pkg-config --cflags python3` \
		-fPIC"

# CLI -------------------------------------------

	# Clean objects from possible previous run to avoid mixup of GUI/CLI objects
	rm objects/*.o || true

	runConfigure --omit-dirs binDir ./configure \
		--bindir="$commandBinDir" \
		--disable-gui \
		--with-features=huge \
		--enable-cscope \
		--enable-pythoninterp=dynamic \
		--enable-rubyinterp=dynamic \
		--with-compiledby=HaikuPorts \
#		--enable-python3interp=dynamic \ crashes on file open
#		--enable-luainterp=dynamic \ currently broken
#		--enable-tclinterp=dynamic \
#		--enable-perlinterp=dynamic not dynamic yet

	make $jobArgs
	cp vim vim.con # preserve gui-less executable
	rm objects/*.o

# GUI -------------------------------------------

	runConfigure --omit-dirs binDir ./configure \
		--bindir="$commandBinDir" \
		--with-features=huge \
		--enable-cscope \
		--enable-pythoninterp=dynamic \
		--enable-rubyinterp=dynamic \
		--with-compiledby=HaikuPorts \
#		--enable-python3interp=dynamic \ crashes on file open
#		--enable-luainterp=dynamic \ currently broken
#		--enable-tclinterp=dynamic \
#		--enable-perlinterp=dynamic not dynamic yet

	make $jobArgs
}

INSTALL()
{
	make install
	ln -s vim $commandBinDir/vi
	addAppDeskbarSymlink $commandBinDir/gvim Vim
}

TEST()
{
	cd src
	make check
}
