# $NetBSD$
#

DISTNAME=	asterisk-1.6.0.1
CATEGORIES=	comms net audio
MASTER_SITES=	http://ftp.digium.com/pub/asterisk/ \
		http://ftp.digium.com/pub/asterisk/old-releases/

MAINTAINER=	pkgsrc-users@NetBSD.org
HOMEPAGE=	http://www.asterisk.org/
COMMENT=	The Asterisk Software PBX


.include "../../mk/bsd.prefs.mk"

BUILD_DEFS+=	VARBASE

GNU_CONFIGURE=	yes
USE_TOOLS+=	pkg-config gmake perl
USE_LANGUAGES=	c c++


PKGCONFIG_OVERRIDE+=	menuselect/mxml/mxml.pc.in

INSTALL_TARGET=		install samples
INSTALLATION_DIRS=	lib/pkgconfig

# Running as non-root will come later
#ASTERISK_USER?= 	asterisk
#ASTERISK_GROUP?= 	asterisk
#PKG_GROUPS= 		${ASTERISK_GROUP}
#PKG_USERS= 		${ASTERISK_USER}:${ASTERISK_GROUP}
#PKG_GROUPS_VARS+=	ASTERISK_GROUP
#PKG_USERS_VARS+=	ASTERISK_USER

# Various path settings for Asterisk
PKG_SYSCONFSUBDIR=	asterisk
ASTLIBDIR?=		${PREFIX}/lib/asterisk
ASTVARLIBDIR?=		${PREFIX}/libdata/asterisk
ASTETCDIR?=		${PKG_SYSCONFDIR}
ASTSPOOLDIR?=		${VARBASE}/spool/asterisk
ASTLOGDIR?=		${VARBASE}/log/asterisk
ASTHEADERDIR?=		${PREFIX}/include/asterisk
ASTCONFPATH?=		${ASTETCDIR}/asterisk.conf
ASTBINDIR?=		${PREFIX}/bin
ASTSBINDIR?=		${PREFIX}/sbin
ASTVARRUNDIR?=		${VARBASE}/run
ASTMANDIR?=		${PREFIX}/man
ASTEXAMPLEDIR?=		${PREFIX}/share/examples/asterisk

INSTALLATION_DIRS=	share/examples/asterisk share/examples/rc.d

# Override default paths in Makefile
SUBST_CLASSES+=		makepaths
SUBST_STAGE.makepaths=	pre-configure
SUBST_FILES.makepaths=	Makefile
SUBST_SED.makepaths+=	-e 's|/var/lib/asterisk|${ASTVARLIBDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTLIBDIR\)=.*|\1 = ${ASTLIBDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTVARLIBDIR\)=.*|\1 = ${ASTVARLIBDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTETCDIR\)=.*|\1 = ${ASTETCDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTSPOOLDIR\)=.*|\1 = ${ASTSPOOLDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTLOGDIR\)=.*|\1 = ${ASTLOGDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTHEADERDIR\)=.*|\1 = ${ASTHEADERDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTCONFPATH\)=.*|\1 = ${ASTCONFPATH}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTBINDIR\)=.*|\1 = ${ASTBINDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTSBINDIR\)=.*|\1 = ${ASTSBINDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTVARRUNDIR\)=.*|\1 = ${ASTVARRUNDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTMANDIR\)=.*|\1 = ${ASTMANDIR}|'
SUBST_SED.makepaths+=	-e 's|^ *\(ASTEXAMPLEDIR\)=.*|\1 = ${ASTEXAMPLEDIR}|'

# XXXrkb: need more files to fix up here?
SUBST_CLASSES+=		configs
SUBST_FILES.configs=	configs/musiconhold.conf.sample
SUBST_SED.configs+=	-e 's|/var/lib/asterisk|${ASTVARLIBDIR}|'
SUBST_SED.configs+=	-e "s|/usr/local/man|${ASTMANDIR}|"
SUBST_SED.configs+=	-e "s|/usr/local|${PREFIX}|"
SUBST_SED.configs+=	-e "s|/var|${VARBASE}|"

RCD_SCRIPTS=		asterisk
OWN_DIRS+=		${ASTSPOOLDIR} ${ASTLOGDIR} ${ASTVARRUNDIR}
OWN_DIRS+=		${ASTLOGDIR}/cdr-csv ${ASTLOGDIR}/cdr-custom

CONF_FILES=		# empty
.for f in asterisk.conf extensions.conf
CONF_FILES+=	${ASTEXAMPLEDIR}/${f:Q} ${ASTETCDIR}/${f:Q}
.endfor

MAKE_ENV+=		VARBASE=${VARBASE}
MAKE_FLAGS+=		INSTALL_PREFIX=${PREFIX}

# if we put all the files in $CONF_FILES, the message is _way_ too long.
.for f in adsi.conf adtranvofr.conf agents.conf alarmreceiver.conf	\
	alsa.conf amd.conf asterisk.adsi cdr.conf 			\
	cdr_adaptive_odbc.conf cdr_custom.conf cdr_manager.conf		\
	cdr_odbc.conf cdr_pgsql.conf cdr_sqlite3_custom.conf		\
	cdr_tds.conf chan_dahdi.conf cli.conf codecs.conf console.conf	\
	dnsmgr.conf dundi.conf enum.conf extensions.ael extensions.conf	\
	extensions.lua extensions_minivm.conf features.conf		\
	festival.conf followme.conf func_odbc.conf gtalk.conf h323.conf	\
	http.conf iax.conf iaxprov.conf indications.conf jabber.conf	\
	jingle.conf logger.conf manager.conf meetme.conf mgcp.conf	\
	minivm.conf misdn.conf modules.conf musiconhold.conf muted.conf	\
	osp.conf oss.conf phone.conf phoneprov.conf queuerules.conf	\
	queues.conf res_ldap.conf res_odbc.conf res_pgsql.conf		\
	res_snmp.conf rpt.conf rtp.conf say.conf sip.conf		\
	sip_notify.conf skinny.conf sla.conf smdi.conf telcordia-1.adsi	\
	udptl.conf unistim.conf usbradio.conf users.conf voicemail.conf	\
	vpb.conf
CONF_FILES+=		${ASTEXAMPLEDIR}/${f:Q} ${ASTETCDIR}/${f:Q}
.endfor

PTHREAD_OPTS+=	require native

.include "../../devel/zlib/buildlink3.mk"
.include "../../security/openssl/buildlink3.mk"
.include "../../mk/curses.buildlink3.mk"
.include "../../mk/pthread.buildlink3.mk"
.include "../../mk/bsd.pkg.mk"
