SUMMARY="A high-level language for numerical computations"
DESCRIPTION="GNU Octave is a high-level language, primarily intended for \
numerical computations.  It provides a convenient command line interface \
for solving linear and nonlinear problems numerically."
HOMEPAGE="http://www.octave.org/"
COPYRIGHT="1996-2019 John W. Eaton"
LICENSE="GNU GPL v3"
REVISION="4"
SOURCE_URI="https://ftp.gnu.org/gnu/octave/octave-$portVersion.tar.gz"
CHECKSUM_SHA256="e36b1124cac27c7caa51cc57de408c31676d5f0096349b4d50b57bfe1bcd7495"
PATCHES="octave-$portVersion.patchset"

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

liboctaveVersion="7.0.0"
liboctaveVersionCompat="$liboctaveVersion compat >= ${liboctaveVersion%%.*}"
liboctinterpVersion="7.0.0"
liboctinterpVersionCompat="$liboctinterpVersion compat >= ${liboctinterpVersion%%.*}"

PROVIDES="
	octave$secondaryArchSuffix = $portVersion
	cmd:mkoctfile$secondaryArchSuffix = $portVersion
	cmd:mkoctfile_$portVersion$secondaryArchSuffix = $portVersion
	cmd:octave$secondaryArchSuffix = $portVersion
	cmd:octave_$portVersion$secondaryArchSuffix = $portVersion
	cmd:octave_cli$secondaryArchSuffix = $portVersion
	cmd:octave_cli_$portVersion$secondaryArchSuffix = $portVersion
	cmd:octave_config$secondaryArchSuffix = $portVersion
	cmd:octave_config_$portVersion$secondaryArchSuffix = $portVersion
	lib:liboctave$secondaryArchSuffix = $liboctaveVersionCompat
	lib:liboctinterp$secondaryArchSuffix = $liboctinterpVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:gnuplot
	cmd:gs
	lib:libamd$secondaryArchSuffix
	lib:libarpack$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcamd$secondaryArchSuffix
	lib:libccolamd$secondaryArchSuffix
	lib:libcholmod$secondaryArchSuffix
	lib:libcolamd$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libcxsparse$secondaryArchSuffix
	lib:libfftw3$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	lib:libGl$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
#	lib:libgraphicsmagick$secondaryArchSuffix
	lib:libhdf5$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:liblapack$secondaryArchSuffix
	lib:libmagick++_6.q16$secondaryArchSuffix
	lib:libncursesw$secondaryArchSuffix
	lib:libopenblas$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix
#	lib:libQt5Core$secondaryArchSuffix
#	lib:libQt5Gui$secondaryArchSuffix
#	lib:libQt5Network$secondaryArchSuffix
#	lib:libQt5OpenGL$secondaryArchSuffix
#	lib:libQt5PrintSupport$secondaryArchSuffix
#	lib:libQt5Widgets$secondaryArchSuffix
	lib:libreadline$secondaryArchSuffix
	lib:libsndfile$secondaryArchSuffix
	lib:libsuitesparseconfig$secondaryArchSuffix
	lib:libsundials_ida$secondaryArchSuffix
	lib:libumfpack$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	octave${secondaryArchSuffix}_devel = $portVersion
	devel:liboctave$secondaryArchSuffix = $liboctaveVersionCompat
	devel:liboctinterp$secondaryArchSuffix = $liboctinterpVersionCompat
	"
REQUIRES_devel="
	octave$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libamd$secondaryArchSuffix
	devel:libarpack$secondaryArchSuffix
	devel:libbz2$secondaryArchSuffix
	devel:libcamd$secondaryArchSuffix
	devel:libccolamd$secondaryArchSuffix
	devel:libcholmod$secondaryArchSuffix
	devel:libcolamd$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libcxsparse$secondaryArchSuffix
	devel:libfftw3$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgfortran$secondaryArchSuffix
	devel:libGl$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libgomp$secondaryArchSuffix
#	devel:libgraphicsmagick$secondaryArchSuffix
	devel:libhdf5$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libklu$secondaryArchSuffix
	devel:liblapack$secondaryArchSuffix
	devel:libmagick++_6.q16$secondaryArchSuffix
	devel:libncursesw$secondaryArchSuffix
	devel:libopenblas$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix
#	devel:libQt5Core$secondaryArchSuffix
#	devel:libQt5Gui$secondaryArchSuffix
#	devel:libQt5Network$secondaryArchSuffix
#	devel:libQt5OpenGL$secondaryArchSuffix
#	devel:libQt5PrintSupport$secondaryArchSuffix
#	devel:libQt5Widgets$secondaryArchSuffix
	devel:libreadline$secondaryArchSuffix
	devel:libsndfile$secondaryArchSuffix
	devel:libsuitesparseconfig$secondaryArchSuffix
	devel:libsundials_ida$secondaryArchSuffix
	devel:libumfpack$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:awk
	cmd:bison >= 3
	cmd:find
	cmd:flex
	cmd:g++$secondaryArchSuffix
	cmd:gfortran$secondaryArchSuffix
	cmd:gnuplot
	cmd:gperf
	cmd:grep
	cmd:gs
	cmd:less
	cmd:libtoolize$secondaryArchSuffix
#	cmd:lrelease$secondaryArchSuffix >=5 # Qt
	cmd:make
	cmd:makeinfo
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
#	cmd:qcollectiongenerator$secondaryArchSuffix >=5 # Qt
#	cmd:qhelpgenerator$secondaryArchSuffix >=5 # Qt
#	cmd:rsvg_convert
	cmd:sed
	"

BUILD()
{
	# Avoid using rsvg-convert and icotool, which we don't have
	# and it doesn't make any sense to create those icons
	rm -rf etc/icons/octave-logo-*.png
	rm -rf octave-logo.ico
	touch etc/icons/octave-logo-{16,22,24,32,48,64,128,256,512}.png
	touch etc/icons/octave-logo.ico

	export LDFLAGS="-lnetwork"

	runConfigure ./configure \
		--disable-docs \
		--without-qt \
		--with-openssl \
		--without-x

	# $jobArgs uses too much RAM
	make
}

INSTALL()
{
	make install-strip

	# Remove libtool .la files
	# TODO libs should be left in $libDir/octave/$portVersion
	# Move libs to $libDir to please Haikuporter complaining
	# about missing libs.
	for f in liboctave liboctinterp; do
		rm -rf $libDir/octave/$portVersion/$f.la
		mv $libDir/octave/$portVersion/$f.so* $libDir
	done

	# Remove empty folders
	rm -rf $libDir/octave/$portVersion/site

	for f in api-v51 site; do
		rm -rf $libDir/octave/$f
	done

	# Remove unnecessary stuff
	for f in appdata applications icons; do
		rm -rf $dataDir/$f
	done

	prepareInstalledDevelLibs \
		liboctave \
		liboctinterp

	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	make check
}
