# Template file for 'R'
pkgname=R
version=4.3.1
revision=1
build_style=gnu-configure
configure_args="--docdir=/usr/share/doc/R rdocdir=/usr/share/doc/R
 --with-blas$(vopt_if openblas '=openblas') --with-lapack
 --enable-R-shlib --with-tcltk
 --enable-memory-profiling
 ac_cv_path_WHICH=/usr/bin/which
 LIBnn=lib"
hostmakedepends="gcc-fortran pkg-config perl less which tar"
makedepends="libgomp-devel readline-devel libXmu-devel libXt-devel
 libpng-devel libjpeg-turbo-devel tiff-devel cairo-devel icu-devel
 zlib-devel bzip2-devel pcre2-devel liblzma-devel
 libcurl-devel tcl-devel tk-devel libxml2-devel
 $(vopt_if openblas openblas-devel 'blas-devel lapack-devel')"
depends="xdg-utils less which"
checkdepends="texlive texlive-fontsextra texinfo"
short_desc="System for statistical computation and graphics"
maintainer="Luke Hannan <lukehannan@gmail.com>"
license="GPL-2.0-or-later"
homepage="https://www.r-project.org/"
changelog="https://cran.r-project.org/doc/manuals/r-release/NEWS.html"
distfiles="https://cran.r-project.org/src/base/R-4/${pkgname}-${version}.tar.gz"
checksum=8dd0bf24f1023c6f618c3b317383d291b4a494f40d73b983ac22ffea99e4ba99
nocross=yes
shlib_provides="libR.so"
# tests require texlive distribution
make_check=extended

build_options="openblas"

case "$XBPS_TARGET_MACHINE" in
	x86_64*|i686*|aarch64*|armv[67]*|ppc64*)
		# Prefer accelerated routines where available
		build_options_default="openblas"
		;;
	*) ;;
esac

if [ "$XBPS_TARGET_LIBC" = musl ]; then
	export CPPFLAGS=-D__MUSL__
fi

pre_configure() {
	export R_BROWSER=/usr/bin/xdg-open
	export R_PDFVIEWER=/usr/bin/xdg-open
}

pre_check() {
	export TEST_MC_CORES=${XBPS_MAKEJOBS}
}

post_install() {
	# Sanitize Makeconf flags
	vsed -i -e 's/^\(CFLAGS\|CXXFLAGS\|CXX1XFLAGS\|FFLAGS\|SAFE_FFLAGS\) = .*/\1 = -O2 -g $(LTO)/' \
		-e 's/^LDFLAGS = .*/LDFLAGS =/' \
		$DESTDIR/usr/lib/R/etc/Makeconf
}
