# $Id$
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>
# Maintainer (ArchLinux): Allan McRae <allan@archlinux.org>

pkgname=expect
pkgver=5.45.4
pkgrel=6
pkgdesc="A tool for automating interactive applications"
arch=('i686' 'x86_64')
url="https://www.nist.gov/el/msid/expect.cfm"
msys2_references=(
  "cpe: cpe:/a:don_libes:expect"
)
license=('custom')
depends=('tcl')
makedepends=('autotools' 'gcc' 'tcl-devel')
source=(https://downloads.sourceforge.net/project/expect/Expect/${pkgver}/expect${pkgver}.tar.gz
        5.45-openpty.patch)
sha256sums=('49a7da83b0bdd9f46d04a04deec19c7767bb9a323e40c4781f89caf760b92c34'
            '51767a9781b8844280265b290ac894fda176b7b92dad9b868f07b4e83b478207')

prepare() {
  cd ${srcdir}/expect${pkgver}
  patch -p2 -i ${srcdir}/5.45-openpty.patch

  autoreconf -vfi
}

build() {
  cd ${srcdir}/expect${pkgver}
  export MSYSTEM=CYGWIN
  ./configure --build=${CHOST} --prefix=/usr --mandir=/usr/share/man 
  make SHLIB_LD='$(CC) -shared -Wl,--out-implib,$@.a'
}

check() {

  cd ${srcdir}/expect${pkgver}
  make test
}

package() {
  cd ${srcdir}/expect${pkgver}
  make DESTDIR=${pkgdir} install

  mv ${pkgdir}/usr/lib/expect${pkgver}/libexpect${pkgver}.dll ${pkgdir}/usr/bin/libexpect${pkgver}.dll

  # mkpasswd is provided by cygwin, so this would conflict
  rm ${pkgdir}/usr/bin/mkpasswd
  rm ${pkgdir}/usr/share/man/man1/mkpasswd.1
  
  sed -i -e 's|\(\$dir\)|\1 .. .. bin|' ${pkgdir}/usr/lib/expect${pkgver}/pkgIndex.tcl

  install -D -m644 README ${pkgdir}/usr/share/licenses/${pkgname}/README
}
