# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit php-lib-r1

DESCRIPTION="Free PDF PHP Library."
HOMEPAGE="http://www.fpdf.org/"
LICENSE="public-domain"
SLOT="0"
KEYWORDS="~x86"
IUSE=""

MY_P="${PN}${PV/_rc/-rc}"
# SRC_URI="http://www.fpdf.org/en/dl.php\?v\=${PV/_rc/-rc}\&f\=tgz"
SRC_URI="mirror://${MY_P}.tgz"
S="${WORKDIR}/${MY_P}"

# Using nomirror because it is not mirrored in gentoo distfiles yet.
RESTRICT="nomirror fetch"

RDEPEND="${RDEPEND}"

need_php_by_category

pkg_nofetch() {
	einfo "This source package cannot be automatically downloaded by portage."
	einfo "Point your browser to the URL below and save the downloaded file as"
	einfo "  ${DISTDIR}${MY_P}"
	einfo "to continue."
	einfo ""
	einfo "URL: http://www.fpdf.org/en/dl.php?v=153?f=tgz"
}

src_unpack() {
	# First handle the messed up name of the download
	# cd ${DISTDIR}
	# mv dl.php?v=153\&f=tgz fpdf153.tgz

	# einfo unpack {$A} {$MY_P}
	# unpack {$A}
	# mkdir ${S}
	# mkdir -p ${S}
	# cd ${S}
	unpack ${A}

	# Permissions in the default package are not secure, fix them now.
	find ${S} -name "*.php" -exec chmod 644 {} \;
	find ${S} -name "*.map" -exec chmod 644 {} \;
}

src_install() {

	cd ${S}

	# Handle the documentation
	local docs="FAQ.htm fpdf.css install.txt histo.htm"
	dodoc ${docs}
	# And the general documentation for the api
	docinto doc
	cd doc
	dodoc `ls -1`

	docinto tutorial
	cd ../tutorial
	dodoc `ls -1`

	# First handle the fonts
	cd ${S}
	mkdir -p ${D}/usr/lib/php/font
	fperms 775 /usr/lib/php/font
	cd font
	cp -pPR * ${D}/usr/lib/php/font
	# The default permissions for the files are pretty crappy.  Let's fix them
	# up before the install finishes

	# Done with the fonts
	cd ${S}
	insopts -m0644
	insinto /usr/lib/php
	doins fpdf.php
}