pkgname=expect
pkgver=5.45.4
pkgdesc='A tool for automating interactive applications'
homepage='https://www.nist.gov/el/msid/expect.cfm'
license=(custom)
_archive=${pkgname}${pkgver}
sources=("${_archive}.tar.gz"
  "${pkgname}-${pkgver}-gcc15-1.patch"
)
urls=("https://prdownloads.sourceforge.net/expect/${sources[0]}"
  "https://www.linuxfromscratch.org/patches/lfs/12.4/${sources[1]}"
)
md5sums=("00fce8de158422f5ccd2666512329bd2"
  "0ca4d6bb8d572fbcdb13cb36cd34833e"
)


src_prepare() {
  if ! python3 -c 'from pty import spawn; spawn(["echo", "ok"])'; then
    leaf_error "PTY issue. Cannot build."
  fi
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  patch -Np1 -i ${distdir}/${sources[1]}
}

src_build() {
  ./configure --prefix=/usr           \
              --with-tcl=/usr/lib     \
              --enable-shared         \
              --disable-rpath         \
              --mandir=/usr/share/man \
              --with-tclinclude=/usr/include
  make
}

src_check() {
  make test
}

src_install() {
  make DESTDIR="$pkgdir" install
  ln -svf ${pkgname}${pkgver}/libexpect${pkgver}.so "${pkgdir}/usr/lib"

  install -Dm644 README "$pkgdir/usr/share/licenses/$pkgname/README"
  # avoid file conflict with the more powerful mkpasswd from the whois package
  mv -v "$pkgdir"/usr/bin/mkpasswd{,-expect}
  mv -v "$pkgdir"/usr/share/man/man1/mkpasswd{,-expect}.1
}
