SUMMARY="Japanese input method editor"
DESCRIPTION="A Japanese Input Method Editor (IME) designed for multi-platform. \
This is open source version. \
Mozcdic-ut dictionary is contained which adds over 1,000,000 entries \
to mozc dictionary."
HOMEPAGE="https://github.com/google/mozc"
COPYRIGHT="2010-2021 Google Inc.
	2021 Utumi Hirosi"
LICENSE="BSD (3-clause)
	Apache v2"
REVISION="1"
SOURCE_URI="https://github.com/hanya/mozc/releases/download/v$portVersion/mozc-v$portVersion.tar.bz2"
CHECKSUM_SHA256="745a8d91bbdfb6eab44e22f89b58add79b012e994ffdb233e2468d7accc73ec3"
SOURCE_DIR="mozc"
PATCHES="mozc-$portVersion.patchset"

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

PROVIDES="
	mozc$secondaryArchSuffix
	addon:mozc
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libprotobuf$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libprotobuf$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	cmd:protoc$secondaryArchSuffix
	cmd:python3
	cmd:which
	cmd:xres
	six_python3
	"
if [ "$targetArchitecture" = x86_gcc2 ]; then
BUILD_PREREQUIRES+="
	cmd:g++
	"
fi

BUILD()
{
	cd src

	cat third_party/mozcdic-ut/mozcdic-ut-20210725.txt >> \
		$sourceDir/src/data/dictionary_oss/dictionary00.txt

	GYP_DEFINES="document_dir=$dataDir/mozc \
		enable_gtk_renderer=0 \
		target_x86_gcc2=$targetArchitecture" \
	$portPackageLinksDir/cmd~python3/bin/python3 build_mozc.py gyp \
		--target_platform=Linux --variant=Haiku --noqt \
		--server_dir=$dataDir/mozc

	$portPackageLinksDir/cmd~python3/bin/python3 build_mozc.py build \
		-c Release \
		server/server.gyp:mozc_server \
		emacs/emacs.gyp:mozc_emacs_helper \
		input_method/input_method.gyp:mozc \
		haiku_gui/haiku_gui.gyp:mozc_tool_haiku
}

INSTALL()
{
	MozcOutDir=src/out_linux/Release
	MozcDataDir=$dataDir/mozc
if [ "$targetArchitecture" = x86_gcc2 ]; then
	InputMethodDir=$addOnsDir/../input_server/methods
else
	InputMethodDir=$addOnsDir/input_server/methods
fi
	mkdir -p $MozcDataDir
	mkdir -p $MozcDataDir/images
	mkdir -p $dataDir/locale/catalogs/x-vnd.Mozc-InputMethod
	mkdir -p $dataDir/locale/catalogs/x-vnd.Mozc-MozcTool
	mkdir -p $InputMethodDir

	cp $MozcOutDir/mozc $InputMethodDir/mozc
if [ "$targetArchitecture" = x86_gcc2 ]; then
	cp $MozcOutDir/mozc_task $MozcDataDir/mozc_task
fi
	cp $MozcOutDir/mozc_server $MozcDataDir/mozc_server
	cp $MozcOutDir/mozc_tool_haiku $MozcDataDir/mozc_tool
	cp $MozcOutDir/mozc_emacs_helper $MozcDataDir/mozc_emacs_helper
	cp src/data/installer/credits_en.html $MozcDataDir/credits_en.html
	cp src/data/images/product_icon_32bpp-128.png \
		$MozcDataDir/images/product_icon_32bpp-128.png

	cp $MozcOutDir/x-vnd.Mozc-InputMethod/* \
		$dataDir/locale/catalogs/x-vnd.Mozc-InputMethod
	cp $MozcOutDir/x-vnd.Mozc-MozcTool/* \
		$dataDir/locale/catalogs/x-vnd.Mozc-MozcTool
}

TEST()
{
	cd src
	# Some tests fails with job > 1
	python3 build_mozc.py runtests -c Release --test_jobs 1
}
