# $Id: Portfile,v 1.1 2006/06/23 20:11:23 mww Exp $

PortSystem			1.0
name				pear-base
version				1.4.9
categories			www php lang
maintainers			darwinports@opendarwin.org
description			PHP PEAR Base system (PEAR, Archive_Tar, Console_Getopt, XML_RPC)
long_description	"${description}"
homepage			http://pear.php.net
master_sites		http://pear.php.net/get/
distname 			PEAR-${version}
set tar_name		Archive_Tar
set tar_ver 		1.3.1
set tar_distname 	${tar_name}-${tar_ver}
set console_name	Console_Getopt
set console_ver		1.2
set console_distname ${console_name}-${console_ver}
set xml_name		XML_RPC
set xml_ver			1.4.8
set xml_distname 	${xml_name}-${xml_ver}
set pear_dir		${prefix}/lib/php
set indirs			{OS PEAR}
set pear_bin		{pear peardev pecl}
platforms			darwin
extract.suffix		.tgz
distfiles-append	${tar_distname}${extract.suffix} \
					${console_distname}${extract.suffix} \
					${xml_distname}${extract.suffix}
checksums			${distname}${extract.suffix} \
						md5    52257e23987717c474a3da87f161a272 \
						sha1   cb74e281d7d30b7105ce2b4f152036b775e68cf1 \
						rmd160 038fb6f0f5d22bb1bb34fff1f80cf609d434cdd2 \
					${tar_distname}${extract.suffix} \
						md5    31e54ce401302065d43888223a0be4d9 \
						sha1   b1eb763a5fba1289686cf1355f90f0fe9149fa6d \
						rmd160 e4d94299018d49835c9adb5d0d0bb7a4f3ee7fac \
					${console_distname}${extract.suffix} \
						md5    8f9ec8253c04350bc01ee7ca941e24b6 \
						sha1   706a9fb1724ef97ee333dadcda95cc7cc50c0c43 \
						rmd160 d9bebe03b52a59b35a4d0fd0825da069037aa000 \
					${xml_distname}${extract.suffix} \
						md5    c2e94575bd14a4425de9e20976c65d43 \
						sha1   5fd5e0f4dfc49374a97b2a9c36254427462a604e \
						rmd160 f4c541a6ed0758c32eca52d0a7da6ce2796a7f56

#depends_run			port:php5
					
use_configure		no

build {
	# pearcmd.php
	reinplace "s|@pear_version@|${version}|g" \
		${worksrcpath}/scripts/\pearcmd.php

	# pear script
	reinplace "s|@php_bin@|${prefix}/bin/php|g" ${worksrcpath}/scripts/\pear.sh
	reinplace "s|@bin_dir@|${prefix}/bin|g" ${worksrcpath}/scripts/\pear.sh
	reinplace "s|@php_dir@|${pear_dir}|g" ${worksrcpath}/scripts/\pear.sh
	reinplace "s|-d output_buffering=1|-d output_buffering=1 -d memory_limit=16M|g" \
		${worksrcpath}/scripts/\pear.sh

	# peardev script
	reinplace "s|@php_bin@|${prefix}/bin/php|g" \
		${worksrcpath}/scripts/\peardev.sh
	reinplace "s|@bin_dir@|${prefix}/bin|g" ${worksrcpath}/scripts/\peardev.sh
	reinplace "s|@php_dir@|${pear_dir}|g" ${worksrcpath}/scripts/\peardev.sh

	# pecl script
	reinplace "s|@php_bin@|${prefix}/bin/php|g" ${worksrcpath}/scripts/\pecl.sh
	reinplace "s|@bin_dir@|${prefix}/bin|g" ${worksrcpath}/scripts/\pecl.sh
	reinplace "s|@php_dir@|${pear_dir}|g" ${worksrcpath}/scripts/\pecl.sh

	# Dependency2.php
	reinplace "s|@PEAR-VER@|${version}|g" ${worksrcpath}/PEAR/Dependency2.php

	# /PEAR/Command/Package.php
	reinplace "s|@package_version@|${version}|g" \
		${worksrcpath}/PEAR/Command/Package.php
	reinplace "s|@DATA-DIR@|${pear_dir}/data|g" \
		${worksrcpath}/PEAR/Command/Package.php
}

destroot {
	# Install PEAR
	xinstall -d -m 755 ${destroot}${prefix}/bin/ ${destroot}${pear_dir}
	foreach B ${pear_bin} {
		xinstall -m 755 ${worksrcpath}/scripts/${B}.sh \
			${destroot}${prefix}/bin/${B}
	}

	foreach D ${indirs} {
		file copy ${worksrcpath}/${D} ${destroot}${pear_dir}/${D}
		#xinstall -d -m 755 ${destroot}${pear_dir}${D}
		#eval xinstall -m 644 [glob ${worksrcpath}/${D}/*.php] \
		#`	${destroot}${pear_dir}/${D}
	}
	eval xinstall -m 644 [glob ${worksrcpath}/*.php] ${destroot}${pear_dir}

	#Install Archive_tar
	xinstall -d -m 755 ${destroot}${pear_dir}/Archive
	eval xinstall -m 644 [glob ${workpath}/${tar_distname}/Archive/*] \
		${destroot}${pear_dir}/Archive

	#Install Console_Getopt
	xinstall -d -m 755 ${destroot}${pear_dir}/Console
	eval xinstall -m 644 \
		[glob ${workpath}/${console_distname}/Console/*] \
		${destroot}${pear_dir}/Console

	#Install XML_RPC
	xinstall -d -m 755 ${destroot}${pear_dir}/XML
	eval xinstall -m 644 \
		[glob ${workpath}/${xml_distname}/*.php] \
		${destroot}${pear_dir}/XML
}

