SUMMARY="A WYSIWIG editor for beautiful structured technical documents"
DESCRIPTION="TeXmacs provides a unified and user friendly framework for \
editing structured documents with different types of content: text, \
mathematics, graphics, interactive content, slides, etc.
Its rendering engine uses high-quality typesetting algorithms so as to \
produce professionally looking documents, which can either be printed out \
or presented from a laptop."
HOMEPAGE="http://www.texmacs.org/"
COPYRIGHT="Free Software Foundation"
LICENSE="GNU GPL v3"
REVISION="2"
SOURCE_URI="https://github.com/mgubi/texmacs/archive/texmacs-$portVersion-haiku-qt5.tar.gz"
CHECKSUM_SHA256="607fa4db4676b78780f7af086feec2e2332dc18a371d79fa50d640de6db10b43"
SOURCE_DIR="texmacs-texmacs-$portVersion-haiku-qt5/src"
PATCHES="texmacs-$portVersion.patchset"
ADDITIONAL_FILES="
	texmacs.rdef.in
	x-texmacs.doc.rdef
	x-texmacs.sty.rdef
	"

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

PROVIDES="
	texmacs$secondaryArchSuffix = $portVersion
	app:TeXmacs
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libguile$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libQt5Concurrent$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfreetype$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libguile$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libltdl$secondaryArchSuffix
	devel:libQt5Concurrent$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:guile == 1.8.8
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

BUILD()
{
	runConfigure ./configure
	make $jobArgs
}

INSTALL()
{
	make install

	mkdir $appsDir
	mv $binDir/fig2ps $libExecDir/TeXmacs/bin/fig2ps
	mv $libExecDir/TeXmacs/bin/texmacs.bin $appsDir/TeXmacs
	rm -f $binDir/texmacs
	rm -rf $dataDir/pixmaps
	rm -rf $libExecDir/TeXmacs/lib

	mkdir -p $dataDir/mime_db/text
	rc $portDir/additional-files/x-texmacs.doc.rdef -o x-texmacs.doc.rsrc
	resattr -O -o $dataDir/mime_db/text/x-texmacs.doc x-texmacs.doc.rsrc
	rc $portDir/additional-files/x-texmacs.sty.rdef -o x-texmacs.sty.rsrc
	resattr -O -o $dataDir/mime_db/text/x-texmacs.sty x-texmacs.sty.rsrc
	rm x-texmacs.doc.rsrc x-texmacs.sty.rsrc

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local INTERNAL="0"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@INTERNAL@|$INTERNAL|" \
		$portDir/additional-files/texmacs.rdef.in > texmacs.rdef

	addResourcesToBinaries texmacs.rdef \
		$appsDir/TeXmacs

	addAppDeskbarSymlink $appsDir/TeXmacs
}
