%{!?tcl_version: %define tcl_version %(echo 'puts $tcl_version' | tclsh)}
%{!?tcl_sitearch: %define tcl_sitearch %{_libdir}/tcl%{tcl_version}}

%define tcl_major 8.4
%define majorver 5.45

Summary: A Tcl/Tk development environment: expect 
Summary(ja): Tcl/Tk 開発環境: expect
Name: expect
Version: %{majorver}
Release: 2%{?_dist_release}
License: Public Domain
Group: Development/Languages
# URL: probably more useful is http://sourceforge.net/projects/expect/
URL: http://expect.nist.gov/

Source: http://downloads.sourceforge.net/%{name}/%{name}%{version}.tar.gz
# Patch0: fixes change log file permissions
Patch0: expect-5.43.0-log_file.patch
# Patch1: fixes install location, change pkgIndex
Patch1: expect-5.43.0-pkgpath.patch
# Patch2: fixes minor man page formatting issue
Patch2: expect-5.45-man-page.patch
# Patch3: fixes segmentation fault during matching characters
Patch3: expect-5.45-match-gt-numchars-segfault.patch
# Patch4: fixes memory leak when using -re, http://sourceforge.net/p/expect/patches/13/
Patch4: expect-5.45-re-memleak.patch
# Patch5: use vsnprintf instead of vsprintf to avoid buffer overflow
Patch5: expect-5.45-exp-log-buf-overflow.patch
# Patch6: fixes segfaults if Tcl is built with stubs and Expect is used directly
#   from C program rhbz#1091060
Patch6: expect-5.45-segfault-with-stubs.patch
# Patch7: fixes leaked fd, patch by Matej Mužila, rhbz#1001220
Patch7: expect-5.45-fd-leak.patch
# examples patches
# Patch100: changes random function
Patch100: expect-5.32.2-random.patch
# Patch101: fixes bz674184 - mkpasswd fails randomly
Patch101: expect-5.45-mkpasswd-dash.patch
# Patch102: fixes bz703702 - let user know that telnet is needed for
# running some examples
Patch102: expect-5.45-check-telnet.patch
# Patch103: use full path to 'su', it's safer
Patch103: expect-5.45-passmass-su-full-path.patch
# Patch104: rhbz 963889, fixes inaccuracy in mkpasswd man page
Patch104: expect-5.45-mkpasswd-man.patch

Buildroot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: tk-devel >= %{tcl_major}
BuildRequires: autoconf
BuildRequires: chrpath
BuildRequires: libX11-devel
BuildRequires: libXft-devel

Vendor: Project Vine
Distribution: Vine Linux

%description -n expect
Expect is a tcl extension for automating interactive applications such
as telnet, ftp, passwd, fsck, rlogin, tip, etc.  Expect is also useful
for testing the named applications.  Expect makes it easy for a script
to control another program and interact with it.

Install the expect package if you'd like to develop scripts which interact
with interactive applications.  You'll also need to install the tcl
package.

%package devel
Summary: Development files for expect library.
Summary(ja): expect ライブラリの開発用ファイル
Group: Development/Libraries
Requires: expect = %{version}-%{release}
Obsoletes: expect <= 5.43-0vl4

%description devel
This package contains development files for the expect library.

%package -n expectk
Summary: A program-script interaction and testing utility
Group: Development/Tools
Requires: expect = %{version}-%{release}
Obsoletes: expect <= 5.43-0vl4

%description -n expectk
This package originally contained expectk and some scripts
that used it. As expectk was removed from upstream tarball
in expect-5.45, now the package contains just these scripts.
Please use tclsh with package require Tk and Expect instead
of expectk.

%prep
%setup -q -n expect%{version}
%patch0 -p1 -b .log_file
%patch1 -p1 -b .pkgpath
%patch2 -p1 -b .man-page
%patch3 -p1 -b .match-gt-numchars-segfault
%patch4 -p1 -b .re-memleak
%patch5 -p1 -b .exp-log-buf-overflow
%patch6 -p1 -b .segfault-with-stubs
%patch7 -p1 -b .fd-leak
# examples fixes
%patch100 -p1 -b .random
%patch101 -p1 -b .mkpasswd-dash
%patch102 -p1 -b .check-telnet
%patch103 -p1 -b .passmass-su-full-path
%patch104 -p1 -b .mkpasswd-man
# -pkgpath.patch touch configure.in
aclocal
autoconf
( cd testsuite
  autoconf -I.. )

%build
%configure --with-tcl=%{_libdir} --with-tk=%{_libdir} --enable-shared \
	--with-tclinclude=%{_includedir}/tcl-private/generic
make %{?_smp_mflags}

%check
make test

%install
rm -rf ${RPM_BUILD_ROOT}
make install DESTDIR="$RPM_BUILD_ROOT"

# move
mv "$RPM_BUILD_ROOT"%{tcl_sitearch}/expect%{version}/libexpect%{version}.so "$RPM_BUILD_ROOT"%{_libdir}

# for linking with -lexpect
ln -s libexpect%{majorver}.so "$RPM_BUILD_ROOT"%{_libdir}/libexpect.so

# remove cryptdir/decryptdir, as Linux has no crypt command (bug 6668).
rm -f "$RPM_BUILD_ROOT"%{_bindir}/{cryptdir,decryptdir}
rm -f "$RPM_BUILD_ROOT"%{_mandir}/man1/{cryptdir,decryptdir}.1*
rm -f "$RPM_BUILD_ROOT"%{_bindir}/autopasswd

# remove rpath
chrpath --delete $RPM_BUILD_ROOT%{_libdir}/libexpect%{version}.so


%post -p /sbin/ldconfig -n expect

%postun -p /sbin/ldconfig -n expect

%clean
rm -rf $RPM_BUILD_ROOT

%files
%%defattr(-,root,root)
%doc FAQ HISTORY NEWS README
%{_bindir}/expect
%{_bindir}/autoexpect
%{_bindir}/dislocate
%{_bindir}/ftp-rfc
%{_bindir}/kibitz
%{_bindir}/lpunlock
%{_bindir}/mkpasswd
%{_bindir}/passmass
%{_bindir}/rftp
%{_bindir}/rlogin-cwd
%{_bindir}/timed-read
%{_bindir}/timed-run
%{_bindir}/unbuffer
%{_bindir}/weather
%{_bindir}/xkibitz
%dir %{tcl_sitearch}/expect%{version}
%{tcl_sitearch}/expect%{version}/pkgIndex.tcl
%{_libdir}/libexpect%{version}.so
%{_mandir}/man1/autoexpect.1.gz
%{_mandir}/man1/dislocate.1.gz
%{_mandir}/man1/expect.1.gz
%{_mandir}/man1/kibitz.1.gz
%{_mandir}/man1/mkpasswd.1.gz
%{_mandir}/man1/passmass.1.gz
%{_mandir}/man1/tknewsbiff.1.gz
%{_mandir}/man1/unbuffer.1.gz
%{_mandir}/man1/xkibitz.1.gz

%files devel
%defattr(-,root,root,-)
%{_libdir}/libexpect.so
%{_mandir}/man3/libexpect.3*
%{_includedir}/*

%files -n expectk
%defattr(-,root,root,-)
%{_bindir}/multixterm
%{_bindir}/tknewsbiff
%{_bindir}/tkpasswd
%{_bindir}/xpstat
%{_mandir}/man1/multixterm.1*
%{_mandir}/man1/tknewsbiff.1*


%changelog
* Sat Dec 5 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 5.45-2
- fixed a symlink.
- fixed BR:.

* Wed Dec 31 2014 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 5.45-1
- updated to 5.45
- rebuilt with tcl/tk 8.5.15

* Fri Jan  4 2013 IWAI, Masaharu <iwai@alib.jp> 5.44.1.15-1
- update to 5.44.1.15:sync ed Hat Enterprise Linux 6 expect-5.44.1.15-4.el6
- add BuildRequires: tk, chrpath
- update License: Public Domain
- drop obsolete patches
 - random patch (Patch0)
 - spawn-43310 patch (Patch6)
 - setpgrp patch (Patch8)
 - lib spec patch (Patch10)
 - libdir patch (Patch11)
- add some patches from RHEL expect-5.44.1.15-4.el6
 - fixes log file permissions patch (Patch500)
 - fixes install location patch (Patch501)
 - tk init patch (Patch502)
 - match gt numchars segfault patch (Patch503)
 - man page patch (Patch504)
 - random patch (Patch600)
 - unbuffer exit code patch (Patch601)
 - passmass su full path Patch (Patch602)
- update build and install section: sync RHEL expect-5.44.1.15-4.el6
- add Vendor and Distribution tags

* Tue Apr 19 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.43-5
- add missing BuildRequires: libX11-devel

* Sat Apr 16 2011 Shu KONNO <owa@bg.wakwak.com> 5.43-4
- rebuilt with rpm-4.8.1-3

* Tue Jun 29 2010 Shu KONNO <owa@bg.wakwak.com> 5.43-3
- rebuilt with tcl/tk-8.4.19-2

* Tue May 18 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 5.43-2
- rebuilt with new toolchain
- changed devel Group to Development/Libraries

* Sun Jul 27 2008 Shu KONNO <owa@bg.wakwak.com> 5.43-1vl5
- applied new versioning policy and spec in utf-8

* Sun Feb 17 2008 Shu KONNO <owa@bg.wakwak.com> 5.43-0vl6
- rebuilt with tcl/tk-8.4.18

* Fri Nov 09 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 5.43-0vl5
- split to expect-devel and expectk sub package.
- add libexpect.so to expect-devel (<BTS:wishes:0136>)

* Tue Oct 09 2007 Shu KONNO <owa@bg.wakwak.com> 5.43-0vl4
- rebuilt with tcl/tk-8.4.16

* Wed Jun 13 2007 Shu KONNO <owa@bg.wakwak.com> 5.43-0vl3
- rebuilt with new toolchain

* Sun Jan 29 2006 Shu KONNO <owa@bg.wakwak.com> 5.43-0vl2
- rebuild for tcl/tk-8.4.12
- added --enable-64bit to configure's option

* Fri Sep 09 2005 Shu KONNO <owa@bg.wakwak.com> 5.43-0vl1
- updated expect to 5.43.0
- dropped expect-5.39.0-64bit-82547.patch (for fixed)
- dropped expect-5.32.2-kibitz.patch (for fixed)
- dropped expect-5.38.0-autopasswd-9917.patch (for fixed)
- rebuilt with tcl/tk 8.4.11

* Wed Jun 30 2004 Shu KONNO <owa@bg.wakwak.com> 5.39-95vl2
- rebuild for tcl/tk-8.4.6

* Mon Jan 12 2004 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 5.39-95vl1
- update based on fedora

* Mon Mar 31 2003 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 8.4.2-0vl1
- update based on BitWalk's tcltk-8.4.2-83bw and RawHide tcltk-8.3.5-89

* Thu Nov 15 2001 Kazuhusa TAKEI <takei@linux.or.jp> 8.0.5_jp-10vl3
- splite source package
- add include files

* Sun Jul 15 2001 Daisuke SUZUKI <daisuke@linux.or.jp> 8.0.5_jp-10vl2
- expand some macros.. (FIXME)

* Sat Jul 14 2001 Daisuke SUZUKI <daisuke@linux.or.jp> 8.0.5_jp-10vl1
- use %configure macros
- add Patch 47,50

* Thu May 31 2001 <sagami@vinelinux.org>
- 8.0.5_jp-10
- unexpand old %%{configure}, new one causes build failure
- fixed missing libtkx.so libtclx.so symlink in /usr/lib
- install manpages into %%{_mandir} and mode 644

* Wed Jul 19 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 8.0.5_jp-9
- modified %install section to handle compressed man pages
- fixed /usr/lib/tk8.0jp/demos.jp/images symlink

* Sun Jul  2 2000 Daisuke SUZUKI <daisuke@linux.or.jp>
- changed default fonts

* Tue Jan 25 2000 Jun Nishii <jun@vinelinux.org>
- added defattr

* Mon Jan 24 2000 Jun Nishii <jun@vinelinux.org>
- added some symlinks, such as libtcl8.0.so.
- obsoletes version number using _jp, now 8.0.5-31vl1

* Wed Jan 5 2000 Norihito Ohmori <nono@vinelinux.org>
- Apply Tcl/Tk 8.0 Japanese Patch 1.7

* Tue Nov 30 1999 Jakub Jelinek <jakub@redhat.com>
- fix tclX symlinks.
- compile on systems where SIGPWR == SIGLOST.

* Sat May  1 1999 Jeff Johnson <jbj@redhat.com>
- update tcl/tk to 8.0.5.
- avoid "containing" in Tix (#2332).

* Thu Apr  8 1999 Jeff Johnson <jbj@redhat.com>
- use /usr/bin/write in kibitz (#1320).
- use cirrus.sprl.umich.edu in weather (#1926).

* Sun Mar 21 1999 Cristian Gafton <gafton@redhat.com> 
- auto rebuild in the new build environment (release 28)

* Mon Mar 08 1999 Preston Brown <pbrown@redhat.com>
- whoops, exec-prefix for itcl was set to '/foo', changed to '/usr'.

* Tue Feb 16 1999 Jeff Johnson <jbj@redhat.com>
- expect does unaligned access on alpha (#989)
- upgrade tcl/tk/tclX to 8.0.4
- upgrade expect to 5.28.
- add itcl 3.0.1

* Tue Jan 12 1999 Cristian Gafton <gafton@redhat.com>
- call libtoolize to allow building on the arm
- build for glibc 2.1
- strip binaries

* Thu Sep 10 1998 Jeff Johnson <jbj@redhat.com>
- update tcl/tk/tclX to 8.0.3, expect is updated also.

* Mon Jun 29 1998 Jeff Johnson <jbj@redhat.com>
- expect: mkpasswd needs delay before sending password (problem #576)

* Thu May 07 1998 Prospector System <bugs@redhat.com>
- translations modified for de, fr, tr

* Sat May 02 1998 Cristian Gafton <gafton@redhat.com>
- fixed expect binaries exec permissions

* Thu Apr 09 1998 Erik Troan <ewt@redhat.com>
- updated to Tix 4.1.0.006
- updated version numbers of tcl/tk to relflect includsion of p2

* Wed Mar 25 1998 Cristian Gafton <gafton@redhat.com>
- updated tcl/tk to patch level 2
- updated tclX to 8.0.2

* Thu Oct 30 1997 Otto Hammersmith <otto@redhat.com>
- fixed filelist for tix... replacing path to the expect binary in scripts
  was leaving junk files around.

* Wed Oct 22 1997 Otto Hammersmith <otto@redhat.com>
- added patch to remove libieee test in configure.in for tcl and tk.
  Shoudln't be needed anymore for glibc systems, but this isn't the "proper" 
  solution for all systems
- fixed src urls

* Mon Oct 06 1997 Erik Troan <ewt@redhat.com>
- removed version numbers from descriptions

* Mon Sep 22 1997 Erik Troan <ewt@redhat.com>
- updated to tcl/tk 8.0 and related versions of packages

* Tue Jun 17 1997 Erik Troan <ewt@redhat.com>
- built against glibc
- fixed dangling tclx/tkx symlinks
