pkg: name fixes and cleanups, Patch from Claudio Furrer, elcaio at gmail dot com
[sip-router] / pkg / ser / gentoo / sip-router-3.1.4.ebuild
1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
4
5 inherit eutils flag-o-matic toolchain-funcs multilib
6
7 DESCRIPTION="Sip-Router (Kamailio/SER) is an Open Source SIP Server"
8 HOMEPAGE="http://sip-router.org/"
9 MY_P="${P/sip-router/kamailio}"
10 SRC_URI="http://www.kamailio.org/pub/kamailio/${PV}/src/${MY_P}_src.tar.gz"
11 S=${WORKDIR}/${MY_P}
12
13 SLOT="0"
14 LICENSE="GPL-2"
15 KEYWORDS="~amd64 ~x86"
16
17 #Documentation can be found here: http://www.kamailio.org/docs/modules/3.1.x/
18 IUSE="flavour_kamailio flavour_ser debug ipv6 sctp
19 group_standard group_standard_dep group_mysql group_radius group_postgres group_presence group_stable group_experimental
20 group_kstandard group_kmysql group_kradius group_kpostgres group_kpresence group_kxml group_kperl group_kldap
21 acc acc_radius alias_db app_lua app_python auth auth_identity auth_db auth_diameter auth_radius avpops
22 benchmark blst
23 call_control carrierroute cfg_db cfg_rpc cfgutils counters cpl-c ctl
24 db_berkeley db_flatstore db_mysql db_oracle db_postgres db_text db_unixodbc
25 debugger dialog dialplan dispatcher diversion domain domainpolicy drouting
26 enum exec
27 geoip group
28 h350 htable imc iptrtpproxy jabber kex
29 lcr ldap
30 matrix maxfwd mediaproxy memcached misc_radius mi_datagram mi_fifo mi_rpc mi_xmlrpc mqueue msilo mtree
31 nathelper nat_traversal
32 osp
33 path pdb pdt peering perl perlvdb permissions pike pipelimit prefix_route
34 presence presence_conference presence_dialoginfo presence_mwi presence_xml
35 pua pua_bla pua_dialoginfo pua_mi pua_usrloc pua_xmpp purple pv
36 qos
37 ratelimit regex registrar rls rtimer rr rtpproxy
38 sanity seas siptrace siputils sl sms snmpstats speeddial sqlops statistics sst
39 textops textopsx tls tm tmx topoh
40 uac uac_redirect uri_db userblacklist usrloc utils
41 xcap_client xcap_server xhttp xlog xmlops xmlrpc xmpp"
42
43 #osp? ( net-libs/osptoolkit )
44 #pdb? ( pdb-server )
45 #seas? ( www.wesip.eu )
46
47 RDEPEND="
48         >=sys-libs/ncurses-5.7
49         >=sys-libs/readline-6.1_p2
50         group_mysql? ( >=dev-db/mysql-5.1.50 sys-libs/zlib )
51         group_radius? ( >=net-dialup/radiusclient-ng-0.5.0 )
52         group_presence? ( dev-libs/libxml2 net-misc/curl )
53         group_postgres? ( dev-db/postgresql-base )
54         group_standard? ( dev-libs/libxml2 dev-libs/openssl net-misc/curl )
55         group_kmysql? ( >=dev-db/mysql-5.1.50 sys-libs/zlib )
56         group_kradius? ( >=net-dialup/radiusclient-ng-0.5.0 )
57         group_kpresence? ( dev-libs/libxml2 net-misc/curl )
58         group_kpostgres? ( dev-db/postgresql-base )
59         group_kstandard? ( dev-libs/libxml2 dev-libs/openssl net-misc/curl )
60         group_kxml? ( dev-libs/libxml2 dev-libs/xmlrpc-c )
61         group_kperl? ( dev-lang/perl dev-perl/perl-ldap )
62         group_kldap? ( net-nds/openldap )
63         acc_radius? ( net-dialup/radiusclient-ng )
64         app_lua? ( dev-lang/lua )
65         app_python? ( dev-lang/python )
66         auth_identity? ( dev-libs/openssl net-misc/curl )
67         carrierroute? ( dev-libs/confuse )
68         cpl-c? ( dev-libs/libxml2 )
69         db_berkeley? ( >=sys-libs/db-4.6 )
70         db_mysql? ( >=dev-db/mysql-5.1.50 )
71         db_oracle? ( dev-db/oracle-instantclient-basic )
72         db_postgres? ( dev-db/postgresql-base )
73         db_unixodbc? ( dev-db/unixODBC )
74         dialplan? ( dev-libs/libpcre )
75         geoip? ( dev-libs/geoip )
76         h350? ( net-nds/openldap )
77         jabber? ( dev-libs/expat )
78         lcr? ( dev-libs/libpcre )
79         ldap? ( net-nds/openldap )
80         memcached? ( dev-libs/libmemcache net-misc/memcached )
81         mi_xmlrpc? ( dev-libs/libxml2 dev-libs/xmlrpc-c )
82         peering? ( net-dialup/radiusclient-ng )
83         perl? ( dev-lang/perl dev-perl/perl-ldap )
84         presence? ( dev-libs/libxml2 )
85         presence_conference? ( dev-libs/libxml2 )
86         presence_xml? ( dev-libs/libxml2 )
87         pua? ( dev-libs/libxml2 )
88         pua_bla? ( dev-libs/libxml2 )
89         pua_dialoginfo? ( dev-libs/libxml2 )
90         pua_usrloc? ( dev-libs/libxml2 )
91         pua_xmpp? ( dev-libs/libxml2 )
92         purple? ( net-im/pidgin )
93         regex? ( dev-libs/libpcre )
94         rls? ( dev-libs/libxml2 )
95         snmpstats? ( net-analyzer/net-snmp sys-apps/lm_sensors )
96         tls? (
97                 sys-libs/zlib
98                 >=dev-libs/openssl-1.0.0a-r1
99         )
100         utils? ( net-misc/curl )
101         xcap_client? ( dev-libs/libxml2 net-misc/curl )
102         xcap_server? ( dev-libs/libxml2 )
103         xmlops? ( dev-libs/libxml2 )
104         xmpp? ( dev-libs/expat )
105 "
106 DEPEND="${RDEPEND}
107         >=sys-devel/bison-1.35
108         >=sys-devel/flex-2.5.4a
109         app-text/docbook2X"
110
111 src_unpack() {
112         unpack ${A}
113         cd "${S}"
114
115         use ipv6 || \
116                 sed -i -e "s/-DUSE_IPV6//g" Makefile.defs || die
117 }
118
119 src_compile() {
120         # iptrtpproxy broken as the needed netfilter module is not supported
121         local mod_exc="iptrtpproxy"
122         local group_inc=""
123         local k=""
124         if use flavour_kamailio; then
125                 k="k"
126                 use group_kxml && group_inc="${group_inc} kxml"
127                 use group_kperl && group_inc="${group_inc} kperl"
128                 use group_kldap && group_inc="${group_inc} kldap"
129         fi
130         # you can USE flavour=kamailio but also group_standard. It will be converted to group_kstandard
131         # same as mysql/kmysql, postgres/kpostgres, radius/kradius, presence/kpresence
132         (use group_standard || use group_kstandard) && group_inc="${group_inc} ${k}standard"
133         use group_standard_dep && group_inc="${group_inc} standard_dep"
134         (use group_mysql || use group_kmysql) && group_inc="${group_inc} ${k}mysql"
135         (use group_radius || use group_kradius) && group_inc="${group_inc} ${k}radius"
136         (use group_postgres || use group_kpostgres) && group_inc="${group_inc} ${k}postgres"
137         (use group_presence || use group_kpresence) && group_inc="${group_inc} ${k}presence"
138         use group_stable && group_inc="${group_inc} stable"
139         use group_experimental && group_inc="${group_inc} experimental"
140         # TODO: skip_modules?
141
142         local mod_inc=""
143         # some IUSE flags must not be included here in mod_inc
144         # e.g.: flavour_kamailio, flavour_ser, debug, sctp, ipv6
145         for i in ${IUSE[@]}; do
146                 for j in ${i[@]}; do
147                         [[ ! "${i}" =~ "flavour_" ]] && \
148                                 [ ! "${i}" == "debug" ] && \
149                                 [ ! "${i}" == "ipv6" ] && \
150                                 [ ! "${i}" == "sctp" ] && \
151                                 [[ ! "${i}" =~ "group_" ]] && \
152                         use "${i}" && mod_inc="${mod_inc} ${i}"
153                 done
154         done
155
156         if use tls; then
157                 tls_hooks=1
158         else
159                 tls_hooks=0
160         fi
161
162         if use debug; then
163                 mode=debug
164         else
165                 mode=release
166         fi
167
168         if use flavour_kamailio; then
169                 flavour=kamailio
170         else
171                 flavour=ser # defaults to SER compatibility names
172         fi
173
174         if use sctp; then
175                 sctp=1
176         else
177                 sctp=0
178         fi
179
180         emake \
181                 CC="$(tc-getCC)" \
182                 CPU_TYPE="$(get-flag march)" \
183                 SCTP="${sctp}" \
184                 CC_EXTRA_OPTS=-I/usr/gnu/include \
185                 mode="${mode}" \
186                 TLS_HOOKS="${tls_hooks}" \
187                 FLAVOUR="${flavour}" \
188                 group_include="${group_inc}" \
189                 include_modules="${mod_inc}" \
190                 exclude_modules="${mod_exc}" \
191                 prefix="/" \
192                 all || die "emake all failed"
193 }
194
195 src_install() {
196         emake -j1 \
197                 BASEDIR="${D}" \
198                 FLAVOUR="${flavour}" \
199                 prefix="/" \
200                 bin_dir=/usr/sbin/ \
201                 cfg_dir=/etc/${flavour}/ \
202                 lib_dir=/usr/$(get_libdir)/${flavour}/ \
203                 modules_dir="/usr/$(get_libdir)/${flavour}/" \
204                 man_dir="/usr/share/man/" \
205                 doc_dir="/usr/share/doc/${flavour}/" \
206                 install || die "emake install failed"
207
208         sed -e "s/sip-router/${flavour}/g" \
209                 ${FILESDIR}/ser.initd > ${flavour}.initd || die
210         sed -e "s/sip-router/${flavour}/g" \
211                 ${FILESDIR}/ser.confd > ${flavour}.confd || die
212
213         newinitd "${flavour}".initd "${flavour}"
214         newconfd "${flavour}".confd "${flavour}"
215 }
216
217 pkg_preinst() {
218         if [[ -z "$(egetent passwd ${flavour})" ]]; then
219                 einfo "Adding ${flavour} user and group"
220                 enewgroup "${flavour}"
221                 enewuser  "${flavour}" -1 -1 /dev/null "${flavour}"
222         fi
223
224         chown -R root:"${flavour}"  "${D}/etc/${flavour}"
225         chmod -R u=rwX,g=rX,o= "${D}/etc/${flavour}"
226
227         has_version <="${CATEGORY}/ser-0.9.8"
228         previous_installed_version=$?
229         if [[ $previous_installed_version = 1 ]] ; then
230                 elog "You have a previous version of SER on ${ROOT}etc/ser"
231                 elog "Consider or verify to remove it (emerge -C ser)."
232                 elog
233                 elog "Sip-Router may not could be installed/merged. See your elog."
234         fi
235 }
236
237 pkg_postinst() {
238         if [ use mediaproxy ]; then
239                 einfo "You have enabled mediaproxy support. In order to use it, you have
240                 to run it somewhere."
241         fi
242         if [ use rtpproxy ]; then
243                 einfo "You have enabled rtpproxy support. In order to use it, you have
244                 to run it somewhere."
245         fi
246 }
247
248 pkg_prerm () {
249         /etc/init.d/"${flavour}" stop >/dev/null
250 }