# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: dorphell <dorphell@archlinux.org>

pkgname=wvstreams
pkgver=4.6.1
pkgrel=17
pkgdesc="A network programming library written in C++"
arch=('x86_64')
url="https://web.archive.org/web/20110504183753/http://alumnit.ca:80/wiki/index.php?page=WvDial"
license=('LGPL')
depends=('zlib' 'pam' 'xplc' 'openssl-1.0' 'readline')
source=(https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/wvstreams/wvstreams-$pkgver.tar.gz
        wvstreams-4.6.1-glibc212.patch
        wvstreams-4.6.1-gcc47.patch
        wvstreams-4.6.1-gcc10.patch
        openssl-buildfix.patch
        gcc-6.patch)
md5sums=('2760dac31a43d452a19a3147bfde571c'
         '5f6e24864209055239cb4e7c9bbd4a41'
         '217e5dedd7f1d50588a5a67d637fc8a1'
         '9aa32c56494e82a84d92acdd6ef49d2b'
         'df423c68134a09439b3961c34635e0b4'
         'bc728af9421e04d0c1f358415b6c1421')
options=('!makeflags')

prepare() {
  cd ${pkgname}-${pkgver}

  patch -p0 -i "$srcdir/wvstreams-4.6.1-glibc212.patch"
  patch -p0 -i "$srcdir/wvstreams-4.6.1-gcc47.patch"
  patch -p1 -i "$srcdir/openssl-buildfix.patch"
  patch -p1 -i "$srcdir/gcc-6.patch"
  patch -p1 -i "$srcdir/wvstreams-4.6.1-gcc10.patch" # Gentoo patch
}

build() {
  cd ${pkgname}-${pkgver}

  CPPFLAGS+=" -I/usr/include/openssl-1.0" \
  LDFLAGS+=" -L/usr/lib/openssl-1.0" \
  ./configure --prefix=/usr \
     --sbin=/usr/bin \
     --sysconfdir=/etc \
     --localstatedir=/var \
     --without-dbus \
     --with-pam \
     --with-openssl \
     --without-tcl \
     --without-qt
  make COPTS="$CFLAGS -fPIC" CXXOPTS="$CXXFLAGS -fPIC -fpermissive -fno-tree-dce -fno-optimize-sibling-calls" VERBOSE=1
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  # FS#15974
  # --without-dbus still installs the pkg-config file
  rm "${pkgdir}/usr/lib/pkgconfig/libwvdbus.pc"
  # --without-qt still installs the pkg-config file
  rm "${pkgdir}/usr/lib/pkgconfig/libwvqt.pc"
}
