SUMMARY="Monitor applications and system services"
DESCRIPTION="Einsteinium provides smarter monitoring of applications and \
system services for Haiku. It can restart applications and system services \
that were quit or crashed, gather statistics on application usage and \
provides customizable ranked lists of applications."
HOMEPAGE="https://perelandra0x309.github.io/einsteinium"
COPYRIGHT="2010-2017 Brian Hill"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://github.com/Perelandra0x309/einsteinium/archive/v${portVersion}.tar.gz"
CHECKSUM_SHA256="cf420ac69304e48895398bec6b85401786c746418f103a291bd9209f275d96d2"

ARCHITECTURES="all"

USER_SETTINGS_FILES="settings/Einsteinium directory"
POST_INSTALL_SCRIPTS="$relativePostInstallDir/einsteinium_hpkg_postinstall.sh"

PROVIDES="
	einsteinium = $portVersion
	app:Einsteinium = $portVersion
	cmd:einsteinium_daemon = $portVersion
	cmd:einsteinium_engine = $portVersion
	"
REQUIRES="
	haiku
	lib:libsqlite3
	lib:libxml2
	"

BUILD_REQUIRES="
	haiku_devel
	devel:libsqlite3
	devel:libxml2
	"
BUILD_PREREQUIRES="
	makefile_engine
	cmd:g++
	cmd:make
	"

BUILD()
{
	cd src
	for f in Engine; do
		pushd $f
		make $jobArgs OBJ_DIR=_${f:0:1}objects
		popd
	done
	for f in Daemon Launcher Preferences; do
		pushd $f
		make $jobArgs OBJ_DIR=_${f:0:1}objects
		make bindcatalogs OBJ_DIR=_${f:0:1}objects
		popd
	done
	make -C Engine/SubscriberExample
}

INSTALL()
{
	mkdir -p $appsDir/Einsteinium/EngineSubscriberKit
	mkdir -p $binDir
	mkdir -p $dataDir/Einsteinium
	mkdir -p $preferencesDir
	mkdir -p $postInstallDir

	# copy documentation
	cp -af docs/ReadMe.html docs/License $appsDir/Einsteinium
	cp -af "docs/Engine Subscriber's Development Guide.pdf" \
		$appsDir/Einsteinium/EngineSubscriberKit

	# post install script
	cp -af scripts/einsteinium_hpkg_postinstall.sh $postInstallDir
	chmod +x $postInstallDir/einsteinium_hpkg_postinstall.sh
	cp -af src/Icons/notify_icon $dataDir/Einsteinium

	# launch bootscript
	cp -af scripts/EinsteiniumBootscript.sh $dataDir/Einsteinium
	chmod +x $dataDir/Einsteinium/EinsteiniumBootscript.sh

	# copy executables
	cd src
	cp -af Engine/einsteinium_engine Daemon/einsteinium_daemon $binDir
	cp -af Preferences/Einsteinium_Preferences $preferencesDir/Einsteinium
	cp -af Launcher/Einsteinium $appsDir/Einsteinium/Einsteinium

	# create the Subscriber Example Kit
	cp -af Engine/SubscriberExample/makefile \
		Engine/SubscriberExample/subscriber_example \
		Engine/SubscriberExample/subscriber_example.rsrc \
		Engine/SubscriberExample/SubscriberExample.cpp \
		Engine/EngineSubscriber.cpp \
		Engine/EngineSubscriber.h \
		$appsDir/Einsteinium/EngineSubscriberKit

	# deskbar links
	addPreferencesDeskbarSymlink $preferencesDir/Einsteinium
	addAppDeskbarSymlink $appsDir/Einsteinium/Einsteinium
}
