SUMMARY="A vi-like file manager"
DESCRIPTION="Vifm is an ncurses based file manager with vi-like keybindings/modes/\
options/commands/configuration, which also borrows some useful ideas from mutt. \
If you use vi, Vifm gives you complete keyboard control over your files without \
having to learn a new set of commands."
HOMEPAGE="https://vifm.info/"
COPYRIGHT="2018 ksteen xaizek"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/vifm/vifm/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="f145896c1a4237d6aa160e8616f4c600f276729a17958b6a1cf5186276815395"
SOURCE_DIR="vifm-$portVersion"
PATCHES="vifm-$portVersion.patchset"
ADDITIONAL_FILES="vifm.rdef.in"

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

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

GLOBAL_WRITABLE_FILES="settings/vifm/colors/Default-256.vifm keep-old"

PROVIDES="
	vifm$secondaryArchSuffix = $portVersion
	cmd:vifm$commandSuffix = $portVersion
	cmd:vifm_convert_dircolors$commandSuffix = $portVersion
	cmd:vifm_pause$commandSuffix = $portVersion
	cmd:vifm_screen_split$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libncurses$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:man
	cmd:sed
	cmd:which
	"

BUILD()
{
	autoreconf -vfi
	runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir
	make $jobArgs
}

INSTALL()
{
	make install

	# Add Haiku resources
	local APP_SIGNATURE="application/x-vnd.vifm"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/vifm.rdef.in > vifm.rdef

	addResourcesToBinaries vifm.rdef $commandBinDir/vifm
}
