SUMMARY="Linux Emulator that runs WINE"
DESCRIPTION="Boxedwine is an emulator that runs Windows applications. \
It achieves this by running an unmodified 32-bit version of Wine, and \
emulating the Linux kernel and CPU.  It is written in C++ with SDL and \
is supported on multiple platforms.

Features:
* Runs 16-bit Windows applications
* Runs 32-bit Windows applications
* Runs in a browser with Emscripten (wasm and asm.js)
* Runs on Windows, Mac, Linux and Haiku
* Currently supports running multiple Wine Version: from 1.7 to Wine 5.0"
HOMEPAGE="http://www.boxedwine.org/"
COPYRIGHT="2021 danoon2"
LICENSE="GNU GPL v2"
REVISION="2"
SOURCE_URI="https://github.com/danoon2/Boxedwine/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="d8b9402658f71225913f0b8de1ecfcda8de3848b08cf3d0741fff80aa2ce8235"
SOURCE_DIR="Boxedwine-$portVersion"
PATCHES="boxedwine-$portVersion.patchset"

ADDITIONAL_FILES="boxedwine.rdef.in"

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

PROVIDES="
	boxedwine$secondaryArchSuffix = $portVersion
	app:Boxedwine
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglew$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
	lib:libminizip$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglew$secondaryArchSuffix >= 2.2
	devel:libglu$secondaryArchSuffix
	devel:libminizip$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	makefile_engine
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p project/haiku/poco_build
	cd project/haiku/poco_build

	cmake ../../../lib/poco \
		-DENABLE_SEVENZIP=OFF \
		-DENABLE_XML=OFF \
		-DENABLE_JSON=OFF \
		-DENABLE_DATA=OFF \
		-DENABLE_DATA_SQLITE=OFF \
		-DENABLE_DATA_MYSQL=OFF \
		-DENABLE_DATA_ODBC=OFF \
		-DENABLE_MONGODB=OFF \
		-DENABLE_REDIS=OFF \
		-DENABLE_PDF=OFF \
		-DENABLE_ZIP=OFF \
		-DENABLE_APACHECONNECTOR=OFF \
		-DENABLE_CPPPARSER=OFF \
		-DENABLE_ENCODINGS=OFF \
		-DENABLE_PAGECOMPILER=OFF \
		-DENABLE_PAGECOMPILER_FILE2PAGE=OFF \
		-DENABLE_TESTS=OFF \
		-DENABLE_JWT=OFF \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_SHARED_LIBS=OFF

	make $jobArgs

	cd ..
	make $jobArgs OBJ_DIR=objects
}

INSTALL()
{
	mkdir -p $appsDir
	cp project/haiku/objects/Boxedwine $appsDir

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

	addResourcesToBinaries boxedwine.rdef $appsDir/Boxedwine
	mimeset -f $appsDir/Boxedwine
	
	addAppDeskbarSymlink $appsDir/Boxedwine
}
