SUMMARY="Open source graph visualization software"
DESCRIPTION="Graphviz is open source graph visualization software. Graph \
visualization is a way of representing structural information as diagrams of \
abstract graphs and networks. It has important applications in networking, \
bioinformatics,  software engineering, database and web design, machine \
learning, and in visual interfaces for other technical domains.
The Graphviz layout programs take descriptions of graphs in a simple text \
language, and make diagrams in useful formats, such as images and SVG for web \
pages, PDF or Postscript for inclusion in other documents; or display in an \
interactive graph browser. (Graphviz also supports GXL, an XML dialect.)
Graphviz has many useful features for concrete diagrams, such as options for \
colors, fonts, tabular node layouts, line styles, hyperlinks, rolland custom \
shapes."
HOMEPAGE="https://www.graphviz.org/"
COPYRIGHT="1994-2021 AT&T Corp."
LICENSE="EPL v1.0"
REVISION="1"
SOURCE_URI="https://gitlab.com/graphviz/graphviz/-/archive/$portVersion/graphviz-$portVersion.tar.bz2"
CHECKSUM_SHA256="c84e17cee66500aae992ffad05a218f6a9619c59d15198f2a9f26d39cebf2bfc"
PATCHES="graphviz-$portVersion.patchset"

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

graphvizLibs="\
	libcdt \
	libcgraph \
	libgvc \
	libgvpr \
	liblab_gamut \
	libpathplan \
	libxdot \
	"
libcdtVersion="5.0.0"
libcgraphVersion="6.0.0"
libgvcVersion="6.0.0"
libgvprVersion="2.0.0"
liblab_gamutVersion="1.0.0"
libpathplanVersion="4.0.0"
libxdotVersion="4.0.0"
portVersionCompat="$portVersion compat >= 2"
for i in $graphvizLibs; do
	eval "${i}VersionCompat=\"\$${i}Version compat >= \${${i}Version%%.*}\""
done

PROVIDES="
	graphviz$secondaryArchSuffix = $portVersionCompat
	cmd:acyclic
	cmd:bcomps
	cmd:ccomps
	cmd:circo
	cmd:cluster
	cmd:diffimg
	cmd:dijkstra
	cmd:dot
	cmd:dot2gxl
	cmd:dot_builtins
	cmd:edgepaint
	cmd:fdp
	cmd:gc
	cmd:gml2gv
	cmd:graphml2gv
	cmd:gv2gml
	cmd:gv2gxl
	cmd:gvcolor
	cmd:gvgen
	cmd:gvmap
	cmd:gvmap.sh
	cmd:gvpack
	cmd:gvpr
	cmd:gxl2dot
	cmd:gxl2gv
	cmd:mm2gv
	cmd:neato
	cmd:nop
	cmd:osage
	cmd:patchwork
	cmd:prune
	cmd:sccmap
	cmd:sfdp
	cmd:tred
	cmd:twopi
	cmd:unflatten
	lib:libcdt$secondaryArchSuffix = $libcdtVersionCompat
	lib:libcgraph$secondaryArchSuffix = $libcgraphVersionCompat
	lib:libgvc$secondaryArchSuffix = $libgvcVersionCompat
	lib:libgvpr$secondaryArchSuffix = $libgvprVersionCompat
	lib:liblab_gamut$secondaryArchSuffix = $liblab_gamutVersionCompat
	lib:libpathplan$secondaryArchSuffix = $libpathplanVersionCompat
	lib:libxdot$secondaryArchSuffix = $libxdotVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libexpat$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgd$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libpython3.7m$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	graphviz${secondaryArchSuffix}_devel = $portVersion
	devel:libcdt$secondaryArchSuffix = $libcdtVersionCompat
	devel:libcgraph$secondaryArchSuffix = $libcgraphVersionCompat
	devel:libgvc$secondaryArchSuffix = $libgvcVersionCompat
	devel:libgvpr$secondaryArchSuffix = $libgvprVersionCompat
	devel:liblab_gamut$secondaryArchSuffix = $liblab_gamutVersionCompat
	devel:libpathplan$secondaryArchSuffix = $libpathplanVersionCompat
	devel:libxdot$secondaryArchSuffix = $libxdotVersionCompat
	"
REQUIRES_devel="
	graphviz$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libexpat$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgd$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libltdl$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libpython3.7m$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:autoreconf
	cmd:awk
	cmd:bison
	cmd:flex
	cmd:freetype_config$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3.7
	"

defineDebugInfoPackage graphviz$secondaryArchSuffix \
	$prefix/bin/acyclic \
	$prefix/bin/bcomps \
	$prefix/bin/ccomps \
	$prefix/bin/circo \
	$prefix/bin/cluster \
	$prefix/bin/dijkstra \
	$prefix/bin/dot_builtins \
	$prefix/bin/dot \
	$prefix/bin/dot2gxl \
	$prefix/bin/edgepaint \
	$prefix/bin/fdp \
	$prefix/bin/gc \
	$prefix/bin/gml2gv \
	$prefix/bin/graphml2gv \
	$prefix/bin/gv2gml \
	$prefix/bin/gv2gxl \
	$prefix/bin/gvcolor \
	$prefix/bin/gvgen \
	$prefix/bin/gvpack \
	$prefix/bin/gvpr \
	$prefix/bin/gvmap \
	$prefix/bin/gxl2dot \
	$prefix/bin/gxl2gv \
	$prefix/bin/mm2gv \
	$prefix/bin/neato \
	$prefix/bin/nop \
	$prefix/bin/osage \
	$prefix/bin/patchwork \
	$prefix/bin/prune \
	$prefix/bin/sccmap \
	$prefix/bin/sfdp \
	$prefix/bin/tred \
	$prefix/bin/twopi \
	$prefix/bin/unflatten \
	$libDir/libcdt.so.$libcdtVersion \
	$libDir/libcgraph.so.$libcgraphVersion \
	$libDir/libgvc.so.$libgvcVersion \
	$libDir/libgvpr.so.$libgvprVersion \
	$libDir/liblab_gamut.so.$liblab_gamutVersion \
	$libDir/libpathplan.so.$libpathplanVersion \
	$libDir/libxdot.so.$libxdotVersion

BUILD()
{
	./autogen.sh NOCONFIG
	runConfigure --omit-dirs "dataDir binDir" \
		./configure CPPFLAGS=-D_BSD_SOURCE \
		--datadir=$developDocDir \
		--bindir=$prefix/bin \
		--enable-shared \
		--enable-python=yes \
		--enable-perl=no

	make $jobArgs
}

INSTALL()
{
	make install

	#remove libtool files
	rm $libDir/*.la
	rm $libDir/graphviz/*.la

	prepareInstalledDevelLibs $graphvizLibs
	fixPkgconfig

	# fix pkg-config paths
	if [ -n "$secondaryArchSuffix" ]; then
		sed -i 's,\/headers/x86,\/headers/x86/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libcdt.pc
		sed -i 's,\/headers/x86,\/headers/x86/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libcgraph.pc
		sed -i 's,\/headers/x86,\/headers/x86/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libgvc.pc
		sed -i 's,\/headers/x86,\/headers/x86/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libgvpr.pc
		sed -i 's,\/headers/x86,\/headers/x86/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/liblab_gamut.pc
		sed -i 's,\/headers/x86,\/headers/x86/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libpathplan.pc
		sed -i 's,\/headers/x86,\/headers/x86/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libxdot.pc
	else
		sed -i 's,\/headers,\/headers/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libcdt.pc
		sed -i 's,\/headers,\/headers/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libcgraph.pc
		sed -i 's,\/headers,\/headers/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libgvc.pc
		sed -i 's,\/headers,\/headers/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libgvpr.pc
		sed -i 's,\/headers,\/headers/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/liblab_gamut.pc
		sed -i 's,\/headers,\/headers/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libpathplan.pc
		sed -i 's,\/headers,\/headers/graphviz,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libxdot.pc
	fi

	packageEntries devel \
		$developDir \
		$manDir/man3
}

TEST()
{
	make check
}
