expectをインストール

scpで会社外へファイルを送るっていうタスクが発生。鍵認証にしてほしいところなんですが、なぜかパスワード認証。ってことでexpectをインストール。懐かしい。大昔に使った覚えがある。

ダウンロード

ソースはここからダウンロードできます。

http://expect.nist.gov/#unix

展開してINSTALLをチェック。

$ pwd /home/hoge/expect
$ tar -zxvf /tmp/expect.tar.gz
$ vi INSTALL

tclのソースが必要らしい。ということでtclもダウンロード。

tclをダウンロードして展開。

tclはここからダウンロード。
http://www.tcl.tk/

展開して、expectのソースと同レベルディレクトリへリンクをはる。

$ pwd
/home/hoge/tcl
$ tar -zxvf /tmp/tcl8.5.8-src.tar.gz
$ ls
tcl8.5.8
$ cd ../expect
$ pwd
/home/hoge/expect
$ ls
expect-5.43
$ ln -s /home/hoge/tcl/tcl8.5.8 .
$ ls
expect-5.43  tcl8.5.8

expectの開発ディレクトリでconfigure,make

$ pwd
/home/hoge/expect
$ cd expect-5.43
$ ./configure
(中略)
$ make

gcc -c  -I. -I. -I/home/hoge/expect/tcl8.5.8/generic   -DEXP_VERSION=\"5.43.0\" -DSCRIPTDIR=\"/usr/local/lib/expect5.43\" -DEXECSCRIPTDIR=\"/usr/local/lib/expect5.43\" -DTCL_DEBUGGER -DUSE_NON_CONST -DSTTY_BIN=\"/bin/stty\" -pipe  -DDFLT_STTY="\"sane\""  exp_inter.c
exp_command.h:26 から include されたファイル中,
                 exp_inter.c:44 から:
/home/hoge/expect/tcl8.5.8/generic/tclPort.h:27:28: error: tclUnixPort.h: そのようなファイルやディレクトリはありません

と、エラーになった。tclUnixPort.hはtcl8.5.8/unixディレクトリにあります。CFLAGSで参照ディレクトリを指定して再conifigure。

$ export CFLAGS='-I../tcl8.5.8/unix'
$ ./configure
(中略)
$ make
gcc -c  -I. -I. -I/home/hoge/expect/tcl8.5.8/generic   -DEXP_VERSION=\"5.43.0\" -DSCRIPTDIR=\"/usr/local/lib/expect5.43\" -DEXECSCRIPTDIR=\"/usr/local/lib/expect5.43\" -DTCL_DEBUGGER -DUSE_NON_CONST -DSTTY_BIN=\"/bin/stty\" -I../tcl8.5.8/unix  -pipe  -DDFLT_STTY="\"sane\""  exp_inter.c
exp_inter.c: In function ‘intMatch’:
exp_inter.c:294: error: ‘TCL_REG_BOSONLY’ undeclared (first use in this function)

今度は何やらマクロ変数が見つからないとのこと。
探すと、tcl8.5.8/genericにあった。

$ find . -name '*.[ch]' -exec fgrep TCL_REG_BOSONLY {} /dev/null \;
./generic/tclInt.h:#define TCL_REG_BOSONLY 002000	/* Prepend \A to pattern so it only matches at


CFLAGSを再度設定して再configure,make

$ export CFLAGS='-I../tcl8.5.8/unix -I../tcl8.5.8/generic'
$ ./configure
(中略)
$ make
gcc -c  -I. -I. -I/home/hoge/expect/tcl8.5.8/generic   -DEXP_VERSION=\"5.43.0\" -DSCRIPTDIR=\"/usr/local/lib/expect5.43\" -DEXECSCRIPTDIR=\"/usr/local/lib/expect5.43\" -DTCL_DEBUGGER -DUSE_NON_CONST -DSTTY_BIN=\"/bin/stty\" -I../tcl8.5.8/unix  -I../tcl8.5.8/generic -pipe  -DDFLT_STTY="\"sane\""  exp_inter.c
exp_inter.c: In function ‘intMatch’:
exp_inter.c:294: error: ‘TCL_REG_BOSONLY’ undeclared (first use in this function)

っと同じエラー。exp_inter.cをみると、TCL_REG_BOSONLYを参照しているのに、その変数が定義されているgeneric/tclInt.hをインクルードしていない。ソースを改変(いいのか?)。39行めあたりに追加。

#include "tcl.h"
#include "tclInt.h" ← 追加
#include "string.h"

これでmake。

$ make
(中略)
gcc -I../tcl8.5.8/unix -I../tcl8.5.8/generic  -pipe   -Wl,--export-dynamic  -o expect exp_main_exp.o libexpect5.43.a -L/usr/local/lib -ltcl8.5  -ldl  -lieee -lm -lutil -Wl,-rpath,/usr/local/lib:/usr/local/lib
/usr/bin/ld: cannot find -ltcl8.5
collect2: ld はステータス 1 で終了しました
make: *** [expect] エラー 1

あぁ、tclのライブラリもいるんですね。そっちもmakeしないとなのか。tclのmakeはするっといった。

$ cd unix
$ ./configure --enable-shared
(中略)
$ make
(中略)
gcc -I../tcl8.5.8/unix -I../tcl8.5.8/generic -I../tcl8.5.8/unix -I../tcl8.5.8/generic -pipe  -L/usr/local/lib -Wl,--export-dynamic  -o expect exp_main_exp.o libexpect5.43.a -L/home/hoge/tcl/tcl8.5.8/unix -ltcl8.5 -L/usr/local/lib -ldl  -lieee -lm -lutil -Wl,-rpath,/usr/local/lib:/usr/local/lib
libexpect5.43.a(exp_command.o): In function `Exp_CloseObjCmd':
exp_command.c:(.text+0x3c55): undefined reference to `Tcl_CloseObjCmd'
libexpect5.43.a(exp_command.o): In function `Exp_InterReturnObjCmd':
exp_command.c:(.text+0x4bd6): undefined reference to `Tcl_ReturnObjCmd'
collect2: ld はステータス 1 で終了しました
make: *** [expect] エラー 1

うーむ。なんだろ。今度はシンボルが見えないと。これらのシンボルはgeneric以下のソースに書いてありますが、tclをunixディレクトリでコンパイルしたときにはリンクされないみたい。
さて、どうしよう。

tclの一個前バージョンでやってみる

expectのREADMEをよく読むと、tcl8.2で動作しまっせってかいてあった。

--------------------
Introduction
--------------------

This is the README file for Expect, a program that performs programmed
dialogue with other interactive programs.  It is briefly described by
its man page, expect(1).  This directory contains the source and man
page for Expect.

This README file covers Expect 5.38 and up.  These versions of Expect
work with Tcl 8.2 and up and Tk 8.2 and up.  Significant changes and
other news can be found in the NEWS file.

The Expect home page is: http://expect.nist.gov
The Expect FAQ is:       http://expect.nist.gov/FAQ.html

や、そうすか。とりあえずtcl8.4でやってみる。8.4.19をダウンロードして、インストール。
tcl8.4.19のインストールは省略。あとexpectのconfigureではtclのソースの場所を指定てきるみたい。

$ configure --with-tcl=/home/hoge/tcl/tcl8.5.19/unix
$ make
# make insatll

やっとインストールできた。