# Template file for 'mupdf'
pkgname=mupdf
version=1.4
revision=1
wrksrc="${pkgname}-${version}-source"
hostmakedepends="pkg-config zlib-devel libcurl-devel freetype-devel libjpeg-turbo-devel jbig2dec-devel"
makedepends="zlib-devel libcurl-devel freetype-devel libjpeg-turbo-devel jbig2dec-devel libXext-devel desktop-file-utils"
depends="desktop-file-utils"
short_desc="Lightweight PDF and XPS viewer"
maintainer="Juan RP <xtraeme@gmail.com>"
license="GPL-3"
homepage="http://mupdf.com"
distfiles="http://mupdf.com/downloads/mupdf-${version}-source.tar.gz"
checksum=018bab9520b5e93bb33ab07b0472fdf9f768c5801769f95b9a696941b633ec22

pre_configure() {
	rm -rf thirdparty/{curl,freetype,jpeg,zlib,jbig2dec}
}

do_configure() {
	if [ "$CROSS_BUILD" ]; then
		unset CFLAGS
		make CC=cc LD=ld AR=ar build=release generate
	fi
}

do_build() {
	if [ "$CROSS_BUILD" ]; then
		make CROSSCOMPILE=yes CURL_LIBS='-lcurl -lpthread' build=release
	else
		make CURL_LIBS='-lcurl -lpthread' build=release
	fi
}

do_install() {
	make build=release prefix=${DESTDIR}/usr install

	mv ${DESTDIR}/usr/bin/mupdf-x11-curl ${DESTDIR}/usr/bin/mupdf
	rm ${DESTDIR}/usr/bin/mupdf-x11

	cd platform/debian
	sed -i -e 's/mupdf.xpm/mupdf/' \
		-e 's/application\/x-pdf/application\/x-pdf/' \
		-e 's/mupdf-select-file/mupdf/' \
		-e 's/^$/NoDisplay=true/' mupdf.desktop

	vinstall mupdf.desktop 644 usr/share/applications
	vinstall mupdf.xpm 644 usr/share/pixmaps
}

mupdf-devel_package() {
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib
	}
}
