# Template file for 'octave'
pkgname=octave
version=6.3.0
revision=1
build_style=gnu-configure
hostmakedepends="perl gcc-fortran pkg-config gnuplot texinfo texlive-dvi tar"
makedepends="pcre-devel readline-devel libSM-devel libltdl-devel lcms2-devel
 glpk-devel"
depends="$(vopt_if gui qt5-plugin-sqlite) texinfo"
checkdepends="zip unzip"
short_desc="High-level language, primarily intended for numerical computations"
maintainer="Diogo Leal <diogo@diogoleal.com>"
license="GPL-3.0-or-later"
homepage="https://gnu.org/software/octave/"
changelog="https://www.gnu.org/software/octave/NEWS-6.1.html"
distfiles="${GNU_SITE}/octave/octave-${version}.tar.gz"
checksum=232065f3a72fc3013fe9f17f429a3df69d672c1f6b6077029a31c8f3cd58a66e

# 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

# Package build options
# TODO: some options are still missing, such as
# java, qrupdate, suitesparse
build_options="
	arpack
	audio
	curl
	fftw3
	graphicsmagick
	gui
	hdf5
	imagemagick
	opengl
	openmp
	qhull
	zlib"

vopt_conflict graphicsmagick imagemagick

desc_option_arpack="Provides 'eigs' and 'svds' functions."
desc_option_audio="Provides audiofile related functionality."
desc_option_curl="Provides 'urlread' and 'urlwrite' functions and the 'ftp' class."
desc_option_fftw3="Improves performance on discrete Fourier transforms."
desc_option_gui="Graphical User Interface."
desc_option_graphicsmagick="Provides 'imread' and 'imwrite' functions."
desc_option_hdf5="Support for HDF data files."
desc_option_imagemagick="Provides 'imread' and 'imwrite' functions."
desc_option_qhull="Provides 'convhull{,n}', 'delaunay{,n}' and 'voronoi{,n}' functions."
desc_option_openmp="Enable support for OpenMP SMP multi-threading"
desc_option_zlib="Support for compressed data."

build_options_default="
	arpack
	audio
	curl
	fftw3
	graphicsmagick
	gui
	hdf5
	opengl
	openmp
	qhull
	zlib"

makedepends+="
	$(vopt_if arpack arpack-ng-devel)
	$(vopt_if audio 'libsndfile-devel portaudio-devel')
	$(vopt_if curl libcurl-devel)
	$(vopt_if fftw3 fftw-devel)
	$(vopt_if graphicsmagick libgraphicsmagick-devel)
	$(vopt_if gui 'qt5-devel qt5-plugin-sqlite qscintilla-qt5-devel qt5-tools-devel')
	$(vopt_if hdf5 hdf5-devel)
	$(vopt_if imagemagick libmagick-devel)
	$(vopt_if opengl "glu-devel fltk-devel fontconfig-devel freetype-devel gl2ps-devel")
	$(vopt_if openmp libgomp-devel)
	$(vopt_if qhull libqhull-devel)
	$(vopt_if zlib zlib-devel)"

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
}
