# SliTaz package receipt.

PACKAGE="asterisk"
VERSION="1.6.2.7"
CATEGORY="misc"
SHORT_DESC="Open Source PBX and telephony toolkit."
MAINTAINER="pascal.bellard@slitaz.org"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WEB_SITE="http://www.asterisk.org/"
WGET_URL="http://downloads.asterisk.org/pub/telephony/asterisk/$TARBALL"
DEPENDS="openssl ncurses zlib libogg libvorbis curl newt libusb-compat alsa-lib \
speex iksemel spandsp tiff radiusclient-ng nbs freetds libpostgresqlclient \
libmysqlclient libunixODBC popt dahdi libpri lua libcap attr net-snmp \
portaudio sqlite libkrb5 libcomerr3 libsdl-image"
BUILD_DEPENDS="gtk+-dev libxml2-dev postgresql-dev libsdl-dev \
gmime gmime-dev unixODBC-dev unixODBC openldap-dev openldap \
dahdi-linux dahdi-tools"
CONFIG_FILES="/etc/asterisk"
TAGS="telephone toolkit"

# Rules to configure and make the package.
#
# Graphical configuration: 'make menuconfig' or 'make gmenuconfig'
#
compile_rules()
{
	cd $src
	busybox sed -i 's/tar xof/tar xf/' sounds/Makefile
	busybox sed -i '/LOG_ERROR, "The file/ {nd}' main/config.c
	busybox sed -i 's/LOG_ERROR, "The file/LOG_WARNING, "The file/' \
		main/config.c
	busybox sed -i 's|lua5.1/||' pbx/pbx_lua.c
	grep -rsl '^#define AST_PBX_MAX_STACK' * | xargs busybox sed -i \
		's/define AST_PBX_MAX_STACK.*/define AST_PBX_MAX_STACK 1024/'
	[ -s $SOURCES_REPOSITORY/rfc3951.txt ] ||
		wget -P $SOURCES_REPOSITORY http://www.ietf.org/rfc/rfc3951.txt
	cp $SOURCES_REPOSITORY/rfc3951.txt codecs/ilbc
	[ -f codecs/ilbc/iLBC_define.h ] || ( cd codecs/ilbc &&
		awk -f $stuff/extract-cfile.awk rfc3951.txt > /dev/null )
	busybox sed -i '/codec_ilbc/{ns/no/yes/}' menuselect-tree
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--without-pwlib \
		--with-dahdi=$WOK/dahdi/$(ls $WOK/dahdi/taz) \
		$CONFIGURE_ARGS &&
	make $MAKEFLAGS &&
	make DESTDIR=$PWD/_pkg install &&
	make DESTDIR=$PWD/_pkg samples &&
	cd contrib/utils &&
	gcc rawplayer.c -o $src/_pkg/usr/bin/rawplayer
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr
	cp -a $_pkg/etc $fs
	cp -a $_pkg/var $fs
	cp -a $_pkg/usr/bin $fs/usr
	cp -a $_pkg/usr/lib $fs/usr
	cp -a $_pkg/usr/sbin $fs/usr
	cp -a $stuff/*/ $fs
}

# Rules to configure package
setup_rules()
{
	case "$2" in
	mysql_host)
		sed -i "s|^hostname=.*|hostname=$3|" $1/etc/asterisk/cdr_mysql.conf
		sed -i "s|^dbhost=.*|dbhost=$3|" $1/etc/asterisk/res_mysql.conf
		;;
	mysql_user)
		sed -i "s|^user=.*|user=$3|" $1/etc/asterisk/cdr_mysql.conf
		sed -i "s|^dbuser=.*|dbuser=$3|" $1/etc/asterisk/res_mysql.conf
		;;
	mysql_password)
		sed -i "s|^password=.*|password=$3|" $1/etc/asterisk/cdr_mysql.conf
		sed -i "s|^dbpass=.*|dbpass=$3|" $1/etc/asterisk/res_mysql.conf
		;;
	mysql_database)
		sed -i "s|^dbname=.*|dbname=$3|" $1/etc/asterisk/res_mysql.conf \
						 $1/etc/asterisk/cdr_mysql.conf
		;;
	pgsql_host)
		sed -i "s|^hostname=.*|hostname=$3|" $1/etc/asterisk/cdr_pgsql.conf
		sed -i "s|^dbhost=.*|dbhost=$3|" $1/etc/asterisk/res_pgsql.conf
		;;
	pgsql_user)
		sed -i "s|^user=.*|user=$3|" $1/etc/asterisk/cdr_pgsql.conf
		sed -i "s|^dbuser=.*|dbuser=$3|" $1/etc/asterisk/res_pgsql.conf
		;;
	pgsql_password)
		sed -i "s|^password=.*|password=$3|" $1/etc/asterisk/cdr_pgsql.conf
		sed -i "s|^dbpass=.*|dbpass=$3|" $1/etc/asterisk/res_pgsql.conf
		;;
	pgsql_database)
		sed -i "s|^dbname=.*|dbname=$3|" $1/etc/asterisk/res_pgsql.conf \
						 $1/etc/asterisk/cdr_pgsql.conf
		;;
	*)	cat <<EOT
mysql_host	hostname or ip of mysql server
mysql_user	username to connect to mysql server
mysql_password	password to connect to mysql server
mysql_database	database used by asterisk
pgsql_host	hostname or ip of postgresql server
pgsql_user	username to connect to postgresql server
pgsql_password	password to connect to postgresql server
pgsql_database	database used by asterisk
EOT
		;;
	esac
}