# Template file for 'wpa_supplicant'
pkgname=wpa_supplicant
version=2.10
revision=1
build_wrksrc="$pkgname"
short_desc="WPA/WPA2/IEEE 802.1X Supplicant"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="BSD-3-Clause"
homepage="http://w1.fi/wpa_supplicant/"
distfiles="http://w1.fi/releases/${pkgname}-${version}.tar.gz"
checksum=20df7ae5154b3830355f8ab4269123a87affdea59fe74fe9292a91d0d7e17b2f

hostmakedepends="pkg-config"
makedepends="libnl3-devel openssl-devel $(vopt_if dbus dbus-devel) $(vopt_if readline readline-devel)"
build_options="dbus readline"
build_options_default="dbus readline"
conf_files="/etc/${pkgname}/${pkgname}.conf"

pre_build() {
	vsed -e 's|/usr/local|$(PREFIX)|g' -i Makefile
	cp -f ${FILESDIR}/config .config

	if [ "$build_option_dbus" ]; then
		vsed -i -e 's, -u, -uq,' dbus/*.service.in
	else
		vsed -i -e 's|#\{0,1\}\(CONFIG_CTRL_IFACE_DBUS_NEW\)=\(.*\)|\1=|' .config
		vsed -i -e 's|#\{0,1\}\(CONFIG_CTRL_IFACE_DBUS_INTRO\)=\(.*\)|\1=|' .config
	fi

	if [ "$build_option_readline" ]; then
		vsed -i -e 's|#\{0,1\}\(CONFIG_READLINE\)=\(.*\)|\1=y|' .config
	fi
}
do_build() {
	export CFLAGS+=" $(pkg-config --cflags libnl-3.0) $CPPFLAGS"
	make ${makejobs} V=1 PREFIX=/usr BINDIR=/usr/bin
}
do_install() {
	make PREFIX=/usr BINDIR=/usr/bin DESTDIR=${DESTDIR} install

	if [ "$build_option_dbus" ]; then
		install -d ${DESTDIR}/usr/share/dbus-1/system-services
		install -m644 dbus/*.service ${DESTDIR}/usr/share/dbus-1/system-services/
		vinstall dbus/dbus-${pkgname}.conf 644 etc/dbus-1/system.d ${pkgname}.conf
	fi

	vinstall ${FILESDIR}/${pkgname}.conf 640 etc/$pkgname
	vsconf wpa_supplicant.conf

	for d in doc/docbook/*.[58]; do
		vman $d
	done

	rm ${DESTDIR}/usr/share/man/man8/wpa_gui.8
	rm ${DESTDIR}/usr/share/man/man8/wpa_priv.8
	rm ${DESTDIR}/usr/share/man/man8/eapol_test.8

	vlicense README
	vsv wpa_supplicant
}
