# Template file for 'octave'
pkgname=octave
version=9.4.0
revision=1
build_style=gnu-configure
build_helper=qmake6
configure_args="--disable-docs"
hostmakedepends="perl gcc-fortran pkg-config qt6-base qt6-tools"
makedepends="pcre2-devel readline-devel libSM-devel libltdl-devel lcms2-devel
 glpk-devel SuiteSparse-devel rapidjson arpack-ng-devel libsndfile-devel
 portaudio-devel libcurl-devel fftw-devel hdf5-devel libgraphicsmagick-devel
 qt6-base-devel qt6-tools-devel qt6-qt5compat-devel qt6-plugin-sqlite
 qscintilla-qt6-devel glu-devel fltk-devel fontconfig-devel freetype-devel
 gl2ps-devel libgomp-devel libqhull-devel zlib-devel"
depends="qt6-plugin-sqlite texinfo"
checkdepends="zip unzip ghostscript gnuplot tar texinfo"
short_desc="High-level language, primarily intended for numerical computations"
maintainer="Gonzalo Tornaría <tornaria@cmat.edu.uy>"
license="GPL-3.0-or-later"
homepage="https://octave.org/"
changelog="http://hg.savannah.gnu.org/hgweb/octave/raw-file/default/etc/NEWS.${version%%.*}.md"
distfiles="${GNU_SITE}/octave/octave-${version}.tar.gz"
checksum=da9481205bfa717660b7d4a16732d8b2d58aadceab4993d41242a8e2848ea6c1

# Use OpenBLAS on platforms where it is available and fallback to regular BLAS
# on all others.
case "$XBPS_TARGET_MACHINE" in
	# List of supported architectures copied from openblas.
	armv[67]*|aarch64*|i686*|x86_64*|ppc64*)
		makedepends+=" openblas-devel"
		configure_args+=" --with-blas=openblas --with-lapack=openblas"
		;;
	*)
		makedepends+=" blas-devel lapack-devel"
		;;
esac

if [ -n "$CROSS_BUILD" ];then
	# cross build cannot determine integer size for BLAS
	# our BLAS (lapack and openblas) are built with 32 bit ints
	# even in 64 bit architectures
	configure_args+=" ax_blas_integer_size=4"
fi

case "$XBPS_TARGET_MACHINE" in
	ppc64*) ;;
	ppc*) broken="fails to configure";;
esac

pre_build() {
	chmod +x build-aux/mk-opts.pl
}

post_install() {
	# add helper to launch octave from dmenu etc.
	printf "#!/bin/sh\noctave --gui" > octave-gui
	vbin octave-gui

	# install man pages
	for f in doc/*/*.1; do
		vman $f
	done

	# install info files
	vmkdir usr/share/info
	touch ${DESTDIR}/usr/share/info/dir
	vcopy "doc/*/*.info*" usr/share/info
}
