# Contributor: grharry
# Maintainer:
pkgname=coova-chilli
pkgver=1.4
pkgrel=0
pkgdesc="CoovaChilli is an open source access controller for wireless LAN"
url="http://www.coova.org/"
arch="all"
license="GPL-3.0-or-later"
makedepends="perl libressl-dev autoconf automake libtool curl-dev
	linux-headers gengetopt-dev"
install="$pkgname.pre-install"
pkgusers="chilli"
pkggroups="chilli"
subpackages="$pkgname-doc $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/coova/coova-chilli/archive/$pkgver.tar.gz
	posix-regex.patch
	system.patch
	des.patch
	"
options="suid"
builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	default_prepare
	cd $builddir
	sed -i 's/-Werror//g' src/Makefile.am || return 1
	sed -i 's%(localstatedir)/run%(localstatedir)%' src/Makefile.am || return 1
	libtoolize --force \
		&& autoreconf -vif || return 1
}

build() {
	cd $builddir
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var/run/chilli \
		--libdir=/usr/lib \
		--sysconfdir=/etc \
		--with-openssl \
		--with-poll \
		--enable-binstatusfile \
		--enable-statusfile \
		--enable-chillixml \
		--enable-ipwhitelist \
		--enable-redirinject \
		--enable-redirdnsreq \
		--enable-redirinject \
		--enable-debug \
		--enable-debug2 \
		--enable-miniportal \
		--enable-sessgarden \
		--enable-shared \
		--enable-chilliredir \
		--enable-chilliscript \
		--enable-layer3 \
		--enable-dhcpopt \
		--enable-largelimits
	export CFLAGS="$CFLAGS -Wno-error=unused-but-set-variable"
	make -j1
}

check() {
	cd $builddir
	make check
}

package() {
	cd $builddir
	make DESTDIR="$pkgdir" install
	install -D -m755 ../../chilli.initd $pkgdir/etc/init.d/chilli
	install -D -m755 ../../chilli.confd $pkgdir/etc/conf.d/chilli
	mkdir -p $pkgdir/var/run/chilli
	chown -R $pkgusers:$pkggroups $pkgdir/var/run/chilli
}

sha512sums="2ee31731c59af0f4282255a76ef045e9f37dc85da6d18a374154ae5cc690dc485acae2d83372bf48d9326db53292603d69b0093e845b4d08b26d2586455590c5  coova-chilli-1.4.tar.gz
d47d176d01eda436b04700bb4404fe2a3c17e00bd8c2e4ed08149841c3e692435fee4f7dc22135d07b95556dd2f2d08b540a345bb7d5bdff3266bfcc46dcda76  posix-regex.patch
7dbfa571f5eb7065a3a6c2f7c14e2d33cec52771e0236f29837d28cc216ca5a12eb31e1f3d3a780964c8e0f65eb057a9c040b14c65d84cd8483858f757240d6b  system.patch
b2dce18c72808e58dd97a235191e9b843f0bfa06805b12c39488bf4464d055c0734248c89c571cc8069e0f06856f7fcf8458aac84f895da4ed2b0ceb7cbd6f82  des.patch"
