SUMMARY="A free & open source vector graphics editor"
DESCRIPTION="Inkscape is a Free and open source vector graphics editor. It offers a rich set \
of features and is widely used for both artistic and technical illustrations \
such as cartoons, clip art, logos, typography, diagramming and flowcharting. \
It uses vector graphics to allow for sharp printouts and renderings at \
unlimited resolution and is not bound to a fixed number of pixels like raster \
graphics. Inkscape uses the standardized SVG file format as its main format, \
which is supported by many other applications including web browsers."
HOMEPAGE="https://inkscape.org/"
COPYRIGHT="2021 Inkscape Developers"
LICENSE="GNU GPL v2"
REVISION="2"
SOURCE_URI="https://inkscape.org/gallery/item/29255/inkscape-$portVersion.tar.xz"
CHECKSUM_SHA256="aeca0b9d33b5b1cfa9aa70433bdee6a8c3d020ffafc2e6f0c9a60eed7a7978af"
SOURCE_DIR="inkscape-1.1.1_2021-09-20_3bf5ae0d25"
PATCHES="inkscape-$portVersion.patchset"
ADDITIONAL_FILES="
	inkscape.rdef.in
	inkview.rdef.in
	"

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

PROVIDES="
	inkscape$secondaryArchSuffix = $portVersion
	lib:lib2geom$secondaryArchSuffix = $portVersion
	app:Inkscape = $portVersion
	app:Inkview = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	boehm_gc$secondaryArchSuffix
	lib:libatkmm_1.6$secondaryArchSuffix
	lib:libboost_filesystem$secondaryArchSuffix
	lib:libcairo$secondaryArchSuffix
	lib:libcairomm_1.0$secondaryArchSuffix
	lib:libcdr_0.1$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libglibmm_2.4$secondaryArchSuffix
	lib:libgiomm_2.4$secondaryArchSuffix
	lib:libgdk_3$secondaryArchSuffix
	lib:libgdk_pixbuf_2.0$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	lib:libGraphicsMagick++$secondaryArchSuffix
	lib:libgsl$secondaryArchSuffix
	lib:libgtk_3$secondaryArchSuffix
	lib:libgtkmm_3.0$secondaryArchSuffix
	lib:libharfbuzz$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:liblcms2$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpango_1.0$secondaryArchSuffix
	lib:libpangomm_1.4$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:librevenge_0.0$secondaryArchSuffix
	lib:librevenge_stream_0.0$secondaryArchSuffix
	lib:librsvg_2$secondaryArchSuffix
	lib:libsigc_2.0$secondaryArchSuffix
	lib:libsoup_2.4$secondaryArchSuffix
	lib:libdouble_conversion$secondaryArchSuffix
	lib:libpotrace$secondaryArchSuffix
	lib:libvisio_0.1$secondaryArchSuffix
	lib:libwpd_0.10$secondaryArchSuffix
	lib:libwpg_0.3$secondaryArchSuffix
	lib:libX11$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libxslt$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	boehm_gc${secondaryArchSuffix}_devel
	devel:libboost_filesystem$secondaryArchSuffix
	devel:libcdr_0.1$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libglibmm_2.4$secondaryArchSuffix
	devel:libGraphicsMagick$secondaryArchSuffix
	devel:libGraphicsMagickWand$secondaryArchSuffix
	devel:libgsl$secondaryArchSuffix
	devel:libgtkmm_3.0$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:liblcms2$secondaryArchSuffix
	devel:libpango_1.0$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:librevenge_0.0$secondaryArchSuffix
	devel:libsoup_2.4$secondaryArchSuffix
	devel:libdouble_conversion$secondaryArchSuffix
	devel:libpotrace$secondaryArchSuffix
	devel:libvisio_0.1$secondaryArchSuffix
	devel:libwpd_0.10$secondaryArchSuffix
	devel:libwpg_0.3$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libxslt$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	LDFLAGS="-Wl,--as-needed" \
	cmake . $cmakeDirArgs -GNinja \
		-DCMAKE_BUILD_TYPE=Release \
		-DSHARE_INSTALL=$dataDir \
		-DINKSCAPE_DATADIR=$dataDir \
		-DPACKAGE_LOCALE_DIR=$dataDir/locale

	# otherwise it runs out of memory, unfortunately
	ninja -j1
}

INSTALL()
{
	ninja install

	mkdir -p $appsDir
	mv $binDir/inkscape $appsDir/Inkscape
	mv $binDir/inkview $appsDir/Inkview

	rm -rf $binDir $developDir $libDir/{cmake,pkgconfig}

	local APP_SIGNATURE="application/x-vnd.inkscape-inkscape"
	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/inkscape.rdef.in > inkscape.rdef

	local APP_SIGNATURE="application/x-vnd.inkscape-inkview"
	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/inkview.rdef.in > inkview.rdef

	addResourcesToBinaries inkscape.rdef $appsDir/Inkscape
	addAppDeskbarSymlink $appsDir/Inkscape

	addResourcesToBinaries inkview.rdef $appsDir/Inkview
	addAppDeskbarSymlink $appsDir/Inkview
}
