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

pkgname=expect
pkgver=5.45.4
pkgrel=2
pkgdesc="A tool for automating interactive applications"
arch=('i686' 'x86_64')
url="https://www.nist.gov/el/msid/expect.cfm"
license=('custom')
depends=('tcl')
source=(https://downloads.sourceforge.net/project/expect/Expect/${pkgver}/expect${pkgver}.tar.gz
        config.guess
        config.sub
        5.45-openpty.patch
        5.45-msysize.patch)
sha256sums=('49a7da83b0bdd9f46d04a04deec19c7767bb9a323e40c4781f89caf760b92c34'
            '5744cab7fda627ef53dbd0d8cb1fa08b30d3702e01a621e028c5a12deee7c21c'
            '6ef568e79ee95214ecb8b187bf14f168bd0889575e922e5e866c455186cfb063'
            '51767a9781b8844280265b290ac894fda176b7b92dad9b868f07b4e83b478207'
            '4f0bd47194289969877b5c75f72e99db8120c430a063c99b1465179ac8cbb7b4')

prepare() {
  cd ${srcdir}/expect${pkgver}
  patch -p2 -i ${srcdir}/5.45-openpty.patch
  patch -p1 -i ${srcdir}/5.45-msysize.patch
  cp ${srcdir}/config.guess tclconfig/config.guess
  cp ${srcdir}/config.sub   tclconfig/config.sub
  autoreconf -vfi
}

build() {
  cd ${srcdir}/expect${pkgver}
  ./configure --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
  rm ${pkgdir}/usr/bin/mkpasswd
  
  sed -i -e 's|\(\$dir\)|\1 .. .. bin|' ${pkgdir}/usr/lib/expect${pkgver}/pkgIndex.tcl

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