summaryrefslogtreecommitdiff
blob: d6be4cda7f6e1fc796a35db8e4a3aae868526de1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-misc/asterisk/asterisk-1.0.6.ebuild,v 1.3 2005/05/05 15:52:23 swegener Exp $

IUSE="alsa doc gtk mmx mysql pri zaptel uclibc debug postgres vmdbmysql vmdbpostgres bri hardened speex"

inherit eutils

ADDONS_VERSION="1.0.6"
BRI_VERSION="0.2.0-RC7k"

DESCRIPTION="Asterisk: A Modular Open Source PBX System"
HOMEPAGE="http://www.asterisk.org/"
SRC_URI="ftp://ftp.asterisk.org/pub/telephony/${PN}/${P}.tar.gz
	 ftp://ftp.asterisk.org/pub/telephony/${PN}/${PN}-addons-${ADDONS_VERSION}.tar.gz
	 bri? ( http://www.junghanns.net/${PN}/downloads/bristuff-${BRI_VERSION}.tar.gz )"

S=${WORKDIR}/${P}
S_ADDONS=${WORKDIR}/${PN}-addons-${ADDONS_VERSION}

SLOT="0"
LICENSE="GPL-2"
KEYWORDS="~x86 ~sparc ~hppa ~amd64"

DEPEND="dev-libs/newt
	media-sound/mpg123
	media-sound/sox
	doc? ( app-doc/doxygen )
	gtk? ( =x11-libs/gtk+-1.2* )
	pri? ( >=net-libs/libpri-1.0.3 )
	bri? ( >=net-libs/libpri-1.0.6
		>=net-misc/zaptel-1.0.6 )
	alsa? ( media-libs/alsa-lib )
	mysql? ( dev-db/mysql )
	speex? ( media-libs/speex )
	uclibc? ( sys-libs/uclibc )
	zaptel? ( >=net-misc/zaptel-1.0.3 )
	postgres? ( dev-db/postgresql )
	vmdbmysql? ( dev-db/mysql )
	vmdbpostgres? ( dev-db/postgresql )"

#	resperl? ( dev-lang/perl
#		   >=net-misc/zaptel-1.0.3 )

pkg_setup() {
	einfo "Running some pre-flight checks..."
#	if use resperl; then
#		# res_perl pre-flight check...
#		if ! $(perl -V | grep -q "usemultiplicity=define"); then
#			eerror "Embedded perl add-on needs Perl with built-in threads support"
#			eerror "(rebuild perl with ithreads use-flag enabled)"
#			die "Perl w/o threads support..."
#		fi
#		einfo "Perl with ithreads support found"
#	fi


	# mysql and postgres voicemail support are mutually exclusive..
	if use vmdbmysql && use vmdbpostgres; then
		eerror "MySQL and PostgreSQL Voicemail support are mutually exclusive... choose one!"
		die "Conflicting use-flags"
	fi

	# check if zaptel and libpri have been built with bri enabled
	if use bri; then
		if ! built_with_use zaptel bri; then
			eerror "Re-emerge zaptel with bri use-flag enabled!"
			die "Zaptel without bri support detected"
		fi

		if ! built_with_use libpri bri; then
			eerror "Re-emerge libpri with bri use-flag enabled!"
			die "Libpri without bri support detected"
		fi
	fi
}

src_unpack() {
	unpack ${A}
	cd ${S}

	# set cflags & mmx optimization
	sed -i  -e "s:^\(OPTIMIZE+=\).*:\1 ${CFLAGS}:" \
		-e "s:^\(CFLAGS+=\$(shell if \$(CC)\):#\1:" \
		Makefile

	# gsm codec still uses -fomit-frame-pointer, and other codecs have their
	# own flags. We only change the arch.
	sed -i  -e "s:^OPTIMIZE+=.*:OPTIMIZE=${CFLAGS}:" \
		-e "s:^CFLAGS[\t ]\++=:CFLAGS =:" \
		codecs/gsm/Makefile

	# hppa patch for gsm codec
	epatch ${FILESDIR}/1.0.0/${PN}-1.0.5-hppa.patch

	if use mmx; then
		if ! use hardened; then
			einfo "Enabling mmx optimization"
			sed -i  -e "s:^#\(K6OPT[\t ]\+= -DK6OPT\):\1:" \
				codecs/gsm/Makefile
		else
			ewarn "Hardened use-flag is set, not enabling mmx optimization for codec_gsm!"

		fi
	fi
	if ! use mmx || use hardened; then
		# don't build + link asm mmx object file
		# without this codec_gsm.so will include text relocations
		sed -i  -e "/k6opt\.\(s\|o\)/ d" \
			codecs/gsm/Makefile
	fi

	if ! use debug; then
		einfo "Disabling debugging"
		sed -i -e "s:^\(DEBUG=\):#\1:" Makefile
	fi

	# change image path in voicemail cgi
	sed -i -e "s:^\(\$astpath = \).*:\1 \"/asterisk\";:" contrib/scripts/vmail.cgi

	#
	# embedded perl
	#
#	if use resperl; then
#		einfo "Patching asterisk for embedded perl support..."
#		epatch ${S_ADDONS}/res_perl/astmake.diff
#
#		# create necessary .c file
#		perl -MExtUtils::Embed -e xsinit || die "Could not create perlxsi.c"
#
#		cd ${S_ADDONS}
#		# asterisk-1.0.6 changed two channel functions
#		epatch ${FILESDIR}/1.0.0/${P}-resperl.diff
#
#		# fix perl path
#		sed -i -e "s:/usr/local/bin/perl:/usr/bin/perl:" \
#			res_perl/Makefile \
#			${S}/Makefile
#		sed -i -e "s:^ASTSRC.*:ASTSRC = ${S}:" \
#			-e "s:\$(ASTLIBDIR)/modules/\(res_musiconhold.so\):\1:" \
#			-e "s:\(res_musiconhold.so \$(LDFLAGS)\):\1 -Wl,-rpath,/usr/lib/asterisk/modules/:" \
#			res_perl/Makefile
#
#		cd ${S}
#	fi

	#
	# uclibc patch
	#
	if use uclibc; then
		einfo "Patching asterisk for uclibc..."
		epatch ${FILESDIR}/1.0.0/${PN}-1.0.5-uclibc-dns.diff
	fi

	#
	# other patches
	#

	# asterisk-config
	epatch ${FILESDIR}/1.0.0/${PN}-1.0.5-astcfg-0.0.2.diff

	# fix include path for speex >= 1.1.0
	epatch ${FILESDIR}/1.0.0/${PN}-1.0.5-speex.diff

	#
	# database voicemail support
	#
	if use postgres; then
		sed -i  -e "s:^#\(APPS+=app_sql_postgres.so\):\1:" \
			-e "s:/usr/local/pgsql/include:/usr/include/postgresql/pgsql:" \
			-e "s:/usr/local/pgsql/lib:/usr/lib/postgresql:" \
			apps/Makefile
	fi

	if use vmdbpostgres; then
		einfo "Enabling PostgreSQL voicemail support"
		sed -i  -e "s:^\(USE_POSTGRES_VM_INTERFACE\).*:\1=1:" \
			-e "s:/usr/local/pgsql/include:/usr/include/postgresql/pgsql:" \
			-e "s:/usr/local/pgsql/lib:/usr/lib/postgresql:" \
			apps/Makefile

		# patch app_voicemail.c
		sed -i -e "s:^#include <postgresql/libpq-fe\.h>:#include \"libpq-fe\.h\":" \
			apps/app_voicemail.c

	elif use vmdbmysql; then
		einfo "Enabling MySQL voicemail support"
		sed -i  -e "s:^\(USE_MYSQL_VM_INTERFACE\).*:\1=1:" \
			-e "s:^\(CFLAGS+=-DUSEMYSQLVM\):\1 -I${S_ADDONS}:" \
			apps/Makefile
	fi

	#
	# asterisk add-ons
	#
	cd ${S_ADDONS}
	sed -i -e "s:-I../asterisk:-I${S} -I${S}/include:" Makefile
	sed -i  -e "s:^OPTIMIZE+=.*:OPTIMIZE+=${CFLAGS}:" \
		-e "s:^\(CFLAGS=\)\(.*\):\1-I${S}/include -fPIC \2:" \
		format_mp3/Makefile


	#
	# BRI patches
	#
	if use bri; then
		cd ${S}
		einfo "Patching asterisk w/ BRI stuff"
		epatch ${WORKDIR}/bristuff-${BRI_VERSION}/patches/asterisk.patch
	fi

	#
	# Revived snmp plugin support
	#
#	if use snmp; then
#		cd ${S}
#		einfo "Patching snmp plugin helper functions"
#		epatch ${FILESDIR}/1.0.0/ast-ax-snmp-1.0.6.diff
#	fi
}

src_compile() {
	# build asterisk first...
	einfo "Building Asterisk..."
	cd ${S}
	emake -j1 || die "Make failed"

	#
	# add-ons
	#
	einfo "Building additional stuff..."
	cd ${S_ADDONS}
	emake -j1 || die "Make failed"

#	if use resperl; then
#		cd ${S_ADDONS}/res_perl
#
#		# copy plugin because -rpath and stuff only works for lib*.* files and we don't want
#		# res_perl.so to look at the wrong places... (ugly but works)
#		cp ${S}/res/res_musiconhold.so . || die "Could not copy musiconhold plugin, needed by res_perl!"
#
#		emake -j1 || die "Building embedded perl failed"
#	fi
}

src_install() {
	emake -j1 DESTDIR=${D} install || die "Make install failed"
	emake -j1 DESTDIR=${D} samples || die "Make install samples failed"

	# install addmailbox and astgenkey
	dosbin contrib/scripts/addmailbox
	dosbin contrib/scripts/astgenkey

	# documentation
	use doc && \
		emake -j1 DESTDIR=${D} progdocs

# rem	# install necessary files
#	dodir /etc/env.d
#	echo "LD_LIBRARY_PATH=\"/usr/lib/asterisk\"" > ${D}/etc/env.d/25asterisk

	exeinto /etc/init.d
	newexe  ${FILESDIR}/1.0.0/asterisk.rc6 asterisk

	insinto /etc/conf.d
	newins  ${FILESDIR}/1.0.0/asterisk.confd asterisk

	# don't delete these, even if they are empty
	keepdir /var/spool/asterisk/voicemail/default/1234/INBOX
	keepdir /var/spool/asterisk/tmp
	keepdir /var/log/asterisk/cdr-csv

	# install standard docs...
	dodoc BUGS CREDITS LICENSE ChangeLog HARDWARE README README.fpm SECURITY

	docinto scripts
	dodoc contrib/scripts/*
	docinto firmware/iax
	dodoc contrib/firmware/iax/*

	insinto /usr/share/doc/${PF}/cgi
	doins contrib/scripts/vmail.cgi
	for i in "images/*.gif"; do
		doins $i
	done

	#
	# add-ons
	#

	# install additional modules...
	einfo "Installing additional modules..."
	cd ${S_ADDONS}
	emake -j1 INSTALL_PREFIX=${D} install || die "Make install failed"

#	if use resperl; then
#		cd ${S_ADDONS}/res_perl
#		emake -j1 INSTALL_PREFIX=${D} install || die "Installation of perl AST_API failed"
#	fi
}

pkg_postinst() {
	einfo "Asterisk has been installed"
	einfo ""
	einfo "to add new Mailboxes use: /usr/sbin/addmailbox"
	einfo ""
	einfo "If you want to know more about asterisk, visit these sites:"
	einfo "http://www.asteriskdocs.org/"
	einfo "http://www.voip-info.org/wiki-Asterisk"
	echo
	einfo "http://asterisk.xvoip.com/"
	einfo "http://junghanns.net/asterisk/"
	einfo "http://www.automated.it/guidetoasterisk.htm"
	echo
	einfo "Gentoo VoIP IRC Channel:"
	einfo "#gentoo-voip @ irc.freenode.net"
	echo
	ewarn "Additional sounds have been split-out into"
	ewarn "net-misc/asterisk-sounds"
}