# $Id$
# Maintainer: Thomas Bächler <thomas@archlinux.org>

pkgname=wpa_supplicant
pkgver=2.1
pkgrel=3
pkgdesc="A utility providing key negotiation for WPA wireless networks"
url="http://hostap.epitest.fi/wpa_supplicant"
arch=('i686' 'x86_64')
depends=('openssl' 'libdbus' 'readline' 'libnl')
optdepends=('wpa_supplicant_gui: wpa_gui program')
license=('GPL')
backup=('etc/wpa_supplicant/wpa_supplicant.conf')
source=("http://w1.fi/releases/${pkgname}-${pkgver}.tar.gz"
	config
	0001-Revert-OpenSSL-Do-not-accept-SSL-Client-certificate-.patch)
sha256sums=('91632e7e3b49a340ce408e2f978a93546a697383abf2e5a60f146faae9e1b277'
            '522b1e2b330bd3fcb9c3c964b0f05ad197a2f1160741835a47585ea45ba8e0a4'
            '3c85fa2cf2465fea86383eece75fa5479507a174da6f0cd09e691fbaaca03c74')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}/"
  patch -p1 -i "${srcdir}"/0001-Revert-OpenSSL-Do-not-accept-SSL-Client-certificate-.patch

  cd "${pkgname}/"
  cp "${srcdir}/config" ./.config
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}/${pkgname}"

  # The Makefile does not pick up our CPPFLAGS
  export CFLAGS="$CPPFLAGS $CFLAGS"
  make LIBDIR=/usr/lib BINDIR=/usr/bin
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}/${pkgname}"
  make LIBDIR=/usr/lib BINDIR=/usr/bin DESTDIR="${pkgdir}" install

  install -d -m755 "${pkgdir}/etc/wpa_supplicant"
  install -m644 wpa_supplicant.conf "${pkgdir}/etc/wpa_supplicant/wpa_supplicant.conf"

  install -d -m755 "${pkgdir}/usr/share/man/man"{5,8}
  install -m644 doc/docbook/*.5 "${pkgdir}/usr/share/man/man5/"
  install -m644 doc/docbook/*.8 "${pkgdir}/usr/share/man/man8/"
  rm -f "${pkgdir}/usr/share/man/man8/wpa_"{priv,gui}.8

  install -d -m755 "${pkgdir}/usr/share/dbus-1/system-services"
  install -m644 dbus/{fi.epitest.hostap.WPASupplicant.service,fi.w1.wpa_supplicant1.service} "${pkgdir}/usr/share/dbus-1/system-services/"

  install -d -m755 "${pkgdir}/etc/dbus-1/system.d"
  install -m644 dbus/dbus-wpa_supplicant.conf "${pkgdir}/etc/dbus-1/system.d/wpa_supplicant.conf"

  install -d -m755 "${pkgdir}/usr/lib/systemd/system"
  install -m644 systemd/*.service "${pkgdir}/usr/lib/systemd/system/"
}