# Former Maintainer: George Vlahavas <vlahavas~at~gmail~dot~com>
# Maintainer: Frédéric Galusik <fredg~at~salixos~dot~org>

pkgname=libreoffice
pkgver=4.0.0
_majorver=4.0
_minorver=4.0.0.3
pkgrel=1fg
arch=x86_64
source=("http://download.documentfoundation.org/libreoffice/stable/4.0.0/deb/x86_64/LibreOffice_4.0.0_Linux_x86-64_deb.tar.gz")
url=http://www.documentfoundation.org/

doinst() {
if [ -x /usr/bin/update-mime-database ]; then
   /usr/bin/update-mime-database usr/share/mime >/dev/null 2>&1
fi
if [ -x /usr/bin/update-desktop-database ]; then
   /usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
fi
}

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"libreoffice (free office suite)"
"LibreOffice is an Open Source, community-developed, office"
"productivity suite. It includes key desktop applications, such as a"
"word processor, spreadsheet, presentation manager, formula editor and"
"drawing program, with a user interface and feature set similar to"
"other office suites. LibreOffice also works transparently with a"
"variety of file formats, including Microsoft Office File Formats."
""
"libreoffice home: http://www.documentfoundation.org/"
)


build() {
	# Unpack DEBS
	cd $SRC/LibreOffice_${_minorver}_Linux_x86-64_deb/DEBS
	for i in `ls *.deb`; do
		  ar x $i
		  tar xf data.tar.gz
		  rm data.tar.gz control.tar.gz
	done
	
	# Unpack desktop-integration DEB and install icons and mime
	# files
	cd desktop-integration
	ar x libreoffice*.deb
	tar xf data.tar.gz
	mkdir -p $PKG/usr/share
	mv usr/share/icons $PKG/usr/share/
	mv usr/share/mime $PKG/usr/share/
	mv usr/share/mimelnk $PKG/usr/share/
	cd ..
	
	# Install program files
	mkdir -p $PKG/usr/lib${LIBDIRSUFFIX}
	cp -Rf opt/* $PKG/usr/lib${LIBDIRSUFFIX}/
	mkdir -p $PKG/usr/share/applications
	mv $PKG/usr/lib${LIBDIRSUFFIX}/libreoffice${_majorver}/share/xdg/*.desktop $startdir/pkg/usr/share/applications/
	rm $PKG/usr/share/applications/{startcenter,qstart,javafilter}.desktop
	rmdir $PKG/usr/lib${LIBDIRSUFFIX}/libreoffice${_majorver}/share/xdg
	
	mkdir -p $PKG/usr/bin
	(
	cd $PKG/usr/bin
	ln -sf ../lib${LIBDIRSUFFIX}/libreoffice${_majorver}/program/soffice soffice
	ln -sf ../lib${LIBDIRSUFFIX}/libreoffice${_majorver}/program/soffice libreoffice
	ln -sf ../lib${LIBDIRSUFFIX}/libreoffice${_majorver}/program/soffice libreoffice${_majorver}
	ln -sf ../lib${LIBDIRSUFFIX}/libreoffice${_majorver}/program/spadmin libreoffice-printeradmin
	ln -sf ../lib${LIBDIRSUFFIX}/libreoffice${_majorver}/program/spadmin libreoffice${_majorver}-printeradmin
	cd $PKG/usr/lib${LIBDIRSUFFIX}/libreoffice${_majorver}/program
	ln -sf soffice.bin libreoffice
	ln -sf soffice.bin libreoffice${_majorver}
	)
	
	cd $PKG/usr/bin
	for APP in base calc draw impress math padmin writer; do
		  ln -s /usr/lib${LIBDIRSUFFIX}/libreoffice${_majorver}/program/s${APP} lo${APP}
	done
	
	# we don't need the included fonts, we already have packages for
	# them anyway. We want to keep the opens___.ttf and
	# fc_local.conf files.
	find \
		  $PKG/usr/lib${LIBDIRSUFFIX}/libreoffice${_majorver}/share/fonts/truetype/ \
		  ! -name "opens___.ttf" ! -name "fc_local.conf" \
		  -type f \
		  -exec rm {} \;
	
	# these dictionaries are not needed either. They are included in
	# the respective langpacks.
	rm -rf $PKG/usr/lib${LIBDIRSUFFIX}/libreoffice${_majorver}/share/extensions/dict-{es,fr,an}
	
	# this one causes problems, we'll stick to the system lib
	rm $PKG/usr/lib${LIBDIRSUFFIX}/libreoffice${_majorver}/ure-link/lib/libstdc++.so.6
	
	chown -R root:root $PKG
}