#Packager: George Vlahavas <vlahavas~at~gmail~dot~com>

pkgname=R
pkgver=3.3.2
pkgrel=5dj
source=("http://cran.r-project.org/src/base/R-3/R-$pkgver.tar.gz" "R.desktop" "icons.tar.gz" "zlib.patch")
docs=("readme" "install" "copying" "changelog" "authors" "news" "todo" "maintainers" "onews" "oonews" "svn-revision" "version")
url=http://www.r-project.org

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"R (The R Project for Statistical Computing)"
"R is a language and environment for statistical computing and"
"graphics. It is a GNU project which is similar to the S language and"
"environment. The S language is often the vehicle of choice for"
"research in statistical methodology, and R provides an Open Source"
"route to participation in that activity. One of R's strengths is the"
"ease with which well-designed publication-quality plots can be"
"produced, including mathematical symbols and formulae where needed."
""
"Homepage: http://www.r-project.org"
)

doinst() {
	# add the entry /usr/lib/R/lib to the file /etc/ld.so.conf
	# but only if this line is not already there
	ff=`grep "/usr/lib${LIBDIRSUFFIX}/R/lib" etc/ld.so.conf`
	if [ ! "$ff" ]; then
			echo "Adding the R directory to the file: /etc/ld.so.conf"
			echo "/usr/lib${LIBDIRSUFFIX}/R/lib" >> etc/ld.so.conf
			ldconfig
	fi
	# remove the temp-var
	unset ff
}

build() {
	# Set R options
	export FFLAGS=$CFLAGS
	export FPICFLAGS="-fPIC"
	export R_BROWSER="/usr/bin/firefox"
	export R_PDFVIEWER="/usr/bin/atril"
	export R_PRINTCMD="lpr"

	# Configure and build
	cd $startdir/src/$pkgname-$pkgver
	patch -p1 < $startdir/src/zlib.patch || return 1
	./configure \
		--prefix=/usr \
		--libdir=/usr/lib${LIBDIRSUFFIX} \
		--localstatedir=/var \
		--sysconfdir=/etc \
		--enable-R-profiling \
		--enable-R-shlib \
		--enable-BLAS-shlib \
		--enable-shared \
		--disable-static \
		--enable-threads=posix \
		--with-blas \
		--with-lapack \
		--with-readline \
		--without-tcltk \
		--with-cairo \
		--with-libpng \
		--with-jpeglib \
		--with-zlib=/lib${LIBDIRSUFFIX} \
		--with-recommended-packages \
		--build=$arch-slackware-linux \
		rdocdir=/usr/doc/$pkgname-$pkgver \
		rincludedir=/usr/include/R
	make -j $numjobs || return 1
	make install DESTDIR=$startdir/pkg || return 1
	make install-libR DESTDIR=$startdir/pkg || return 1
	make install-info DESTDIR=$startdir/pkg || return 1
	
	# Removed unwanted files
	rm -f $startdir/pkg/usr/lib${LIBDIRSUFFIX}/R/COPYING
	rm -f $startdir/pkg/usr/lib${LIBDIRSUFFIX}/R/NEWS
	rm -f $startdir/pkg/usr/lib${LIBDIRSUFFIX}/R/SVN-REVISION
	rm -f $startdir/pkg/usr/share/info/dir
	rm -f $startdir/pkg/usr/share/info/dir.old

	# Copy icons to the right place
	ICONSIZES="128 96 72 64 48 32 24 22 16"
	for i in $ICONSIZES; do
		mkdir -p $startdir/pkg/usr/share/icons/hicolor/${i}x${i}/apps;
		cp $startdir/src/$pkgname-$i.png $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps/$pkgname.png;
	done;
	mkdir -p $startdir/pkg/usr/share/icons/hicolor/scalable/apps
	cp $startdir/src/$pkgname.svg $startdir/pkg/usr/share/icons/hicolor/scalable/apps/

	# Install menu entry
	mkdir -p $startdir/pkg/usr/share/applications/
	cp $startdir/src/R.desktop $startdir/pkg/usr/share/applications/
}

