SUMMARY="A programming language primarily for statistics and numerical analysis"
DESCRIPTION="R is GNU S, a system for statistical computation and graphics. \
It consists of a language plus a run-time environment with graphics, a \
debugger, access to certain system functions, and the ability to run programs \
stored in script files. The core of R is an interpreted computer language \
which allows branching and looping as well as modular programming using \
functions. The R distribution contains functionality for a large number of \
statistical procedures such as: linear and generalized linear models, \
nonlinear regression models, time series analysis, classical parametric and \
nonparametric tests, clustering, smoothing and graphical data \
representations. Additional modules ('add-on packages') are available for a \
variety of specific purposes but are not distributed with this package."
HOMEPAGE="https://www.r-project.org/"
COPYRIGHT="1993-2020 The R Core Team"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://cloud.r-project.org/src/base/R-4/R-$portVersion.tar.gz"
CHECKSUM_SHA256="09983a8a78d5fb6bc45d27b1c55f9ba5265f78fa54a55c13ae691f87c5bb9e0d"
SOURCE_DIR="R-$portVersion"

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

PROVIDES="
	r$secondaryArchSuffix = $portVersion
	cmd:r$secondaryArchSuffix
	cmd:rscript$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:less
	lib:libbz2$secondaryArchSuffix
#	lib:libcairo$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libgettextpo$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libicui18n$secondaryArchSuffix >= 66
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblapack$secondaryArchSuffix
	lib:liblzma$secondaryArchSuffix
	lib:libncursesw$secondaryArchSuffix
	lib:libopenblas$secondaryArchSuffix
#	lib:libpango_1.0$secondaryArchSuffix
	lib:libpaper$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libquadmath$secondaryArchSuffix
	lib:libreadline$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libtcl8.6
	lib:libtiff$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
#	devel:libcairo$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libgettextpo$secondaryArchSuffix
	devel:libgfortran$secondaryArchSuffix
	devel:libgomp$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libicui18n$secondaryArchSuffix >= 66
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:liblapack$secondaryArchSuffix
	devel:liblzma$secondaryArchSuffix
	devel:libncursesw$secondaryArchSuffix
	devel:libnghttp2$secondaryArchSuffix
	devel:libopenblas$secondaryArchSuffix
#	devel:libpango_1.0$secondaryArchSuffix
	devel:libpaper$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libquadmath$secondaryArchSuffix
	devel:libreadline$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libtclstub8.6
	devel:libtiff$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:bison
	cmd:gcc$secondaryArchSuffix
	cmd:gfortran$secondaryArchSuffix
	cmd:grep
#	cmd:kpsewhich #texlive
	cmd:ld$secondaryArchSuffix
	cmd:less
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
#	cmd:makeindex #texlive
	cmd:pcre2_config$secondaryArchSuffix
#	cmd:pdflatex #texlive
#	cmd:pdftex #texlive
	cmd:pkg_config$secondaryArchSuffix
	cmd:pwd
	cmd:sed
	cmd:texi2any
	cmd:which
	cmd:yacc
	"

BUILD()
{
	export CPPFLAGS="-D_BSD_SOURCE"
	export LIBS="-lnetwork -lbsd"

	runConfigure --omit-dirs sysconfdir ./configure \
		--with-x=no \
		--sysconfdir="$sysconfDir/R" \
		--enable-R-shlib \
		rdocdir="$docDir" \
		rincludedir=$includeDir \
		rsharedir="$dataDir/R"

	make $jobArgs
}

INSTALL()
{
	make install

	fixPkgconfig
}

TEST()
{
	make check
}
