# Template file for 'ppp'
pkgname=ppp
version=2.4.5
distfiles="ftp://ftp.samba.org/pub/ppp/ppp-$version.tar.gz"
build_style=configure
configure_args="--prefix=/usr"
make_install_target="DESTDIR=$XBPS_DESTDIR/$pkgname-$version/usr install"
short_desc="PPP (Point-to-Point Protocol) daemon"
maintainer="Juan RP <xtraeme@gmail.com>"
checksum=43317afec9299f9920b96f840414c977f0385410202d48e56d2fdb8230003505
long_desc="
 This packages provides a daemon which implements the PPP protocol for
 dial-up networking."

CFLAGS="-D_GNU_SOURCE"

conf_files="
/etc/ppp/ip-up
/etc/ppp/chap-secrets
/etc/ppp/options
/etc/ppp/ip-down
/etc/ppp/pap-secrets"

subpackages="ppp-devel"

Add_dependency run glibc
Add_dependency run libpcap
Add_dependency build libpcap-devel

pre_configure()
{
	# Custom CFLAGS.
	sed -i "s:-O2 -pipe -Wall -g:${XBPS_CFLAGS}:" \
		${wrksrc}/pppd/Makefile.linux
	sed -i "s:-g -O2:${XBPS_CFLAGS}:" ${wrksrc}/pppd/plugins/Makefile.linux
	sed -i "s:-O2:${XBPS_CFLAGS}:" ${wrksrc}/pppstats/Makefile.linux
	sed -i "s:-O2 -g -pipe:${XBPS_CFLAGS}:" ${wrksrc}/chat/Makefile.linux
	sed -i "s:-O:${XBPS_CFLAGS}:" ${wrksrc}/pppdump/Makefile.linux
	# Enable active filter
	sed -i "s:^#FILTER=y:FILTER=y:" ${wrksrc}/pppd/Makefile.linux
	# Enable ipv6 support
	sed -i "s:^#HAVE_INET6=y:HAVE_INET6=y:" ${wrksrc}/pppd/Makefile.linux
	# Enable Microsoft Proprietary Callback Control Protocol
	sed -i "s:^#CBCP=y:CBCP=y:" ${wrksrc}/pppd/Makefile.linux 
}

pre_install()
{
	for f in $(find ${wrksrc} -type f -name Makefile); do
		sed -i -e "s|\$(INSTALL) -s|\$(INSTALL|g" ${f} || return 1
	done
}

post_install()
{
	chmod 755 ${DESTDIR}/usr/lib/pppd/${version}/*.so
	install -m755 ${wrksrc}/pppd/pppd ${DESTDIR}/usr/sbin

	install -D -m644 ${FILESDIR}/options \
		${DESTDIR}/etc/ppp/options || return 1
	install -D -m755 ${FILESDIR}/ip-up \
		${DESTDIR}/etc/ppp/ip-up || return 1
	install -D -m755 ${FILESDIR}/ip-down \
		${DESTDIR}/etc/ppp/ip-down || return 1
	install -d -m755 ${DESTDIR}/etc/ppp/ip-up.d || return 1
	install -d -m755 ${DESTDIR}/etc/ppp/ip-down.d || return 1
	install -m755 ${FILESDIR}/ip-up.d.dns.sh \
		${DESTDIR}/etc/ppp/ip-up.d/00-dns.sh || return 1
	install -m755 ${FILESDIR}/ip-down.d.dns.sh \
		${DESTDIR}/etc/ppp/ip-down.d/00-dns.sh || return 1
	install -D -m755 ${FILESDIR}/pon \
		${DESTDIR}/usr/bin/pon || return 1
	install -D -m755 ${FILESDIR}/poff \
		${DESTDIR}/usr/bin/poff || return 1
	install -D -m755 ${FILESDIR}/plog \
		${DESTDIR}/usr/sbin/plog || return 1
	install -D -m600 ${wrksrc}/etc.ppp/pap-secrets \
		${DESTDIR}/etc/ppp/pap-secrets  || return 1
	install -D -m600 ${wrksrc}/etc.ppp/chap-secrets \
		${DESTDIR}/etc/ppp/chap-secrets || return 1
	#install -D -m644 ${FILESDIR}/pon.1 \
	#	${DESTDIR}/usr/share/man/man1/pon.1 || return 1
	install -d -m755 ${DESTDIR}/etc/ppp/peers || return 1
	touch -f ${DESTDIR}/etc/ppp/peers/.empty_on_purpose
}
