# SliTaz package receipt.

PACKAGE="eaccelerator"
VERSION="0.9.6.1"
CATEGORY="system-tools"
SHORT_DESC="PHP accelerator, optimizer, and dynamic content cache."
MAINTAINER="pascal.bellard@slitaz.org"
TARBALL="$PACKAGE-$VERSION.tar.bz2"
WEB_SITE="http://eaccelerator.net/"
WGET_URL="http://bart.eaccelerator.net/source/$VERSION/$TARBALL"
DEPENDS="php m4"
BUILD_DEPENDS="php-dev"
TAGS="php"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	export PHP_PREFIX="/usr"
	$PHP_PREFIX/bin/phpize
	./configure --enable-eaccelerator=shared \
		--with-php-config=$PHP_PREFIX/bin/php-config \
		--prefix=/usr --infodir=/usr/share/info \
		--mandir=/usr/share/man $CONFIGURE_ARGS &&
	make &&
	make INSTALL_ROOT=$PWD/_pkg install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/tmp/eaccelerator $fs/usr/share/php
	cp $(find $_pkg | grep eaccelerator.so) $fs/usr/share/php/
	chmod 0777 $fs/tmp/eaccelerator
}

# Pre and post install commands for Tazpkg.
post_install()
{
	grep -q ^extension=msql.so $1/etc/php.ini || \
	    sed -e 's|;.*extension=msql.so|;   extension=msql.so\nextension=eaccelerator.so\neaccelerator.shm_size="48"\neaccelerator.cache_dir="/tmp/eaccelerator"\neaccelerator.enable="1"\neaccelerator.optimizer="1"\neaccelerator.check_mtime="1"\neaccelerator.debug="0"\neaccelerator.filter=""\neaccelerator.shm_max="0"\neaccelerator.shm_ttl="0"\neaccelerator.shm_prune_period="0"\neaccelerator.shm_only="0"\neaccelerator.compress="1"\neaccelerator.compress_level="9"|' -i $1/etc/php.ini

	# Start Web server.
	while read daemon file; do
		if [ -f /etc/init.d/$daemon -a ! -f "/var/run/$file" ]; then
			/etc/init.d/$daemon start
		fi
	done <<EOT
apache apache/httpd.pid
lighttpd lighttpd.pid
EOT
}

# Pre and post remove commands for Tazpkg.
pre_remove()
{
	sed -i '/.*eaccelerator.*/d' /etc/php.ini

	# Start Web server.
	while read daemon file; do
		if [ -z "$1" -a -f /etc/init.d/$daemon \
			     -a ! -f "/var/run/$file" ]; then
			/etc/init.d/$daemon start
		fi
	done <<EOT
apache apache/httpd.pid
lighttpd lighttpd.pid
EOT
}