# Template file for 'wps-office-bin' (restricted)
_suiteName=wps-office
_numericVersion=10.1.0.5503
_releaseIncrement=a20
_patchLevel=p2
_libpngVersion=1.2.56
pkgname=${_suiteName}-bin
version=${_numericVersion}${_releaseIncrement}${_patchLevel}
revision=1
maintainer="Michael Aldridge <aldridge.mac@gmail.com>"
homepage="http://wps-community.org"
license="Kingsoft WPS Community License; zlib"
#Full license is at: http://wps-community.org/license.md (Not downloadable)
short_desc="Linux office suite with similar appearance to MS Office"
allow_unknown_shlibs=yes
nodebug=yes
hostmakedepends="rsync"
makedepends="zlib-devel"
restricted=yes

_disturl="http://kdl.cc.ksosoft.com/wps-community/download/${_releaseIncrement}"

only_for_archs="i686 x86_64"
if [ "$XBPS_TARGET_MACHINE" = "x86_64" ]; then
	_arch=x86_64
	checksum=9a43a32db385a604e9959487abc330bb4602724527c9bca229a0ddf98f462e41
elif [ "$XBPS_TARGET_MACHINE" = "i686" ]; then
	_arch=x86
	checksum=6f71131835d743594e0c89a4b34a4d924d72f48b0c02f7ea6fe7270f273f71e9
fi

_distTar="${_suiteName}_${_numericVersion}~${_releaseIncrement}${_patchLevel}_${_arch}.tar.xz"
distfiles="${_disturl}/${_distTar}"
distfiles+=" ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng12/libpng-${_libpngVersion}.tar.xz"

checksum+=" 24ce54581468b937734a6ecc86f7e121bc46a90d76a0d948dca08f32ee000dbe"

do_extract() {
	vmkdir "opt/kingsoft/wps-office"
	tar xvf "${XBPS_SRCDISTDIR}/${pkgname}-${version}/${_distTar}" -C "${DESTDIR}/opt/kingsoft/wps-office" --strip-components=1

	# extract libpng
	tar xvf "${XBPS_SRCDISTDIR}/${pkgname}-${version}/libpng-${_libpngVersion}.tar.xz" --strip-components=1
}

do_configure() {
	# This is only for the included libpng
	./configure --prefix=${DESTDIR}/usr
}

do_build() {
	# This is only for the included libpng
	make
}

do_install() {
	# Install the included libpng
	make install

	# Install the wps-office suites
	vmkdir usr/bin
	vmkdir usr/share
	vmkdir usr/lib

	_programs="wps wpp et"
	for prog in ${_programs}; do
		ln -fs /opt/kingsoft/wps-office/$prog ${DESTDIR}/usr/bin/$prog
	done
	mv ${DESTDIR}/opt/kingsoft/wps-office/resource/* ${DESTDIR}/usr/share/

	#Fonts
	vmkdir usr/share/fonts/TTF
	install -m644 ${DESTDIR}/opt/kingsoft/wps-office/fonts/*.TTF ${DESTDIR}/usr/share/fonts/TTF

	#Clean up some things
	rm ${DESTDIR}/opt/kingsoft/wps-office/README.txt
	rm -rf ${DESTDIR}/opt/kingsoft/wps-office/font*
	rm ${DESTDIR}/opt/kingsoft/wps-office/install_fonts
	rm -rf ${DESTDIR}/usr/include
	rm -rf ${DESTDIR}/usr/share/man
	rm -rf ${DESTDIR}/usr/lib/pkgconfig
	rm -rf ${DESTDIR}/usr/bin/libpng*
	rm -f ${DESTDIR}/usr/lib/*.so
	rm -f ${DESTDIR}/usr/lib/*.a
}
