#Maintainer: George Vlahavas (vlahavas~at~gmail~dot~com)

pkgname=R
pkgver=2.12.1
pkgrel=1gv
arch=i486
source=("http://cran.r-project.org/src/base/R-2/R-$pkgver.tar.gz" "R.desktop" "icons.tar.gz")
docs=("readme" "install" "copying" "changelog" "authors" "news" "todo" "maintainers" "onews" "oonews" "svn-revision" "version" )
url=http://www.r-project.org

# The i486 and x86_64 SLKBUILDs only differ in the doinst. It's not
# possible to use $LIBDIRSUFFIX in doinst.
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/R/lib" etc/ld.so.conf`
	#
	if [ ! "$ff" ]; then
	        #
	        echo "Adding the R directory to the file: /etc/ld.so.conf"
	        echo "/usr/lib/R/lib" >> etc/ld.so.conf
	        ldconfig
	        #
	fi
	
	#
	# remove the temp-var
	#
	unset ff
	
	#
	# make sure all libraries that are installed are 'registered'
	#
	ldconfig
}

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."
)


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

	# Configure and build
	cd $startdir/src/$pkgname-$pkgver
	./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-system-zlib \
		--with-system-bzlib \
		--with-system-pcre \
		--with-recommended-packages \
		rdocdir=/usr/doc/$pkgname-$pkgver \
		rincludedir=/usr/include/R
	make || 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
	# Relocate locale directory
	mkdir -p $startdir/pkg/usr/share
	mv $startdir/pkg/usr/lib/R/share/locale $startdir/pkg/usr/share

	# Problems with locale
	cd $startdir/pkg/usr/bin
	sed -i -e 's|# Shell wrapper for R executable.|# Shell wrapper for R executable.\n\nLANG=en_US|g' R

	# Copy icons to the right place
	ICONSIZES="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;
		mv $startdir/src/$pkgname-$i.png $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps/$pkgname.png;
	done;

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