Snack インストール

Linux につづきWindows でも Tcl/Tk および Snack のインストールを試してみました。

Tcl/Tk のインストール

まず、前回と同じく http://www.tcl.tk/software/tcltk/ から tcl8.4.14-src.tar.gz と tk8.4.14-src.tar.gz をダウンロードします。
tcl...tar.gz を解凍し、tcl8.4.14\win\README を見てみると、Visual C++ か Msys + Mingwコンパイルができると書いてありましたので、今回は Msys + Mingw の環境で試してみたいと思います。

### tcl8.4.14\win\README より

2. Compiling Tcl
                              • -
In order to compile Tcl for Windows, you need the following: Tcl 8.4 Source Distribution (plus any patches) and Visual C++ 5 or newer or Msys + Mingw http://prdownloads.sourceforge.net/tcl/msys_mingw8.zip This Msys + Mingw download is the minimal environment needed to build Tcl/Tk under Windows. It includes a shell environment and gcc. The release is designed to make it as easy a possible to build Tcl/Tk. To install, you just download the zip file and extract the files into a directory. The README.TXT file describes how to launch the msys shell, you then run the configure script in the tcl/win directory.

最初に、http://prdownloads.sourceforge.net/tcl/ (http://sourceforge.net/project/showfiles.php?group_id=10894 にリダイレクトされました) から、msys_mingw8.zip ダウンロードし、C:\ に解凍しました。
C:\msys\msys.bat をダブルクリックして、シェルを起動します。また、あらかじめ解凍した tcl...tar.gz と tk...tar.gz を /home/proj/Tcl/src に置いておきます。
で、以下コマンドのログです。

### Tcl のメイク (--enable-thread はなんとなくつけてみました)
$ cd ~/proj/Tcl/src/tcl8.4.14/win/ 
$ ./configure --prefix=$HOME/proj/Tcl --enable-shared --enable-thread
$ make
$ make install

### Tk のメイク
$ cd ~/proj/Tcl/src/tk8.4.14/win/
$ ./configure --prefix=$HOME/proj/Tcl --enable-shared --enable-thread
$ make 
$ make install

### PATH の設定
$ echo "export PATH=\${HOME}/proj/Tcl/bin:\${PATH}" >> ~/.bashrc
$ source ~/.bashrc

### Tcl 実行確認
$ which tclsh84.exe
/c/home/proj/Tcl/bin/tclsh84.exe
$ tclsh84.exe
% puts $tcl_library
c:/home/proj/Tcl/lib/tcl8.4
% puts $tcl_pkgPath
can't read "tcl_pkgPath": no such variable    # tcl_pkgPath は定義されていないようです
% puts $tcl_patchLevel
8.4.14
% puts $auto_path
c:/home/proj/Tcl/lib/tcl8.4 c:/home/proj/Tcl/lib
% exit

### Wish 実行確認
$ which wish84.exe
/c/home/proj/Tcl/bin/wish84.exe
$ wish84.exe    (空のウィンドウがひとつ+コンソールウィンドウが出れば OK です)

Snack のインストール

つづいて、http://www.speech.kth.se/snack/download.html から snack2.2.10.tar.gz をダウンロードします。これも /home/Tcl/proj/src に解凍しておきます。
では、コマンドのログです。

$ cd ~/proj/Tcl/src/snack2.2.10/win/
$ ./configure --prefix=$HOME/proj/Tcl --enable-shared --enable-thread
...(略)...
checking the location of tclConfig.sh... ./configure: cd: ../../tcl/win: No such
 file or directory
configure: error: There is no tclConfig.sh in /c/home/proj/Tcl/src/snack2.2.10/w
in:  perhaps you did not specify the Tcl *build* directory (not the toplevel Tcl
 directory) or you forgot to configure Tcl?

configure で失敗してしまいました。tclConfig.sh が見つけられないと言っているので、configure ファイルを下記のように書き換えます。

### snack2.2.10\win\configure

# TCL_BIN_DIR_DEFAULT=../../tcl/win
TCL_BIN_DIR_DEFAULT=../../tcl8.4.14/win

# TK_BIN_DIR_DEFAULT=../../tk/win
TK_BIN_DIR_DEFAULT=../../tk8.4.14/win

すると、今度は下記のようにうまくいきました。

$ ./configure --prefix=$HOME/proj/Tcl --enable-shared --enable-thread
...(略)...
checking the location of tclConfig.sh... /c/home/proj/Tcl/src/tcl8.4.14/win/tclC
onfig.sh
checking the location of tkConfig.sh... /c/home/proj/Tcl/src/tk8.4.14/win/tkConf
ig.sh
configure: creating ./config.status
config.status: creating Makefile
config.status: creating snackConfig.sh

configure が無事通ったので、次に make に移ります。

$ make
gcc -g -O2 -O2 -fomit-frame-pointer -DHAVE_STDINT_H -I/c/home/proj/Tcl/src/tcl8.
4.14/generic -I/c/home/proj/Tcl/src/tk8.4.14/generic -I/c/home/proj/Tcl/src/tk8.
4.14/xlib -I/mingw/dx6/include -I./../generic -DWIN -DUSE_TCL_STUBS -DUSE_TK_STU
BS -DBUILD_snack -DTCL_81_API -c -o snackStubInit.o ./../generic/snackStubInit.c

In file included from ./../generic/snack.h:34,
                 from ./../generic/snackStubInit.c:13:
./../generic/jkAudIO.h:52:21: mmreg.h: No such file or directory
./../generic/jkAudIO.h:53:22: dsound.h: No such file or directory
...(略)...

が、失敗してしまいます。snack2.2.10\win\Makefile を見てみると、

# NOTE: You will need to update this path if DX6 is not installed in /mingw/dx6!
# DX6 for Mingw: http://people.montana.com/%7Ebowman/Software/ming.zip
DX6_DIR = /mingw/dx6
DX6_INC_DIR = $(DX6_DIR)/include
DX6_LIB_DIR = $(DX6_DIR)/lib

とあるので、上記の URL (直リンクで取れます) から ming.zip をダウンロードし、/ming/dx6 を作り、ming\i386-mingw32 の下にある lib\ と include\ を /ming/dx6 以下にコピーします。
では、再度 make してみます。

$ make
...(略)...
gcc -g -O2 -O2 -fomit-frame-pointer -DHAVE_STDINT_H -I/c/home/proj/Tcl/src/tcl8.
4.14/generic -I/c/home/proj/Tcl/src/tk8.4.14/generic -I/c/home/proj/Tcl/src/tk8.
4.14/xlib -I/mingw/dx6/include -I./../generic -DWIN -DUSE_TCL_STUBS -DUSE_TK_STU
BS -DBUILD_snack -DTCL_81_API -c -o jkFormatMP3.o ./../generic/jkFormatMP3.c
In file included from ./../generic/jkFormatMP3.c:1312:
C:/msys/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/math.h:673: 
error: syntax error before '(' token
make: *** [jkFormatMP3.o] Error 1

また、失敗してしまいました。問題の math.h は /mingw/include/math.h にあるものです。今回はかなり強引ですが、問題となっている 673 行目をコメントアウトすることで対応してみました。

### /mingw/include/math.h

/* 7.12.9.6 */
/* round away from zero, regardless of fpu control word settings */
extern double __cdecl round (double);
//extern float __cdecl roundf (float);      ### ここをコメントアウト
extern long double __cdecl roundl (long double);

では、もう一度 make してみます。

$ make
...(略)...

うまくいったようです。最後に make install しておきます。

$ make install
mkdir /c/home/proj/Tcl/lib/snack2.2
cp libsnackstub22.a "/c/home/proj/Tcl/lib/snack2.2"
cp libsnack.dll "/c/home/proj/Tcl/lib/snack2.2"
cp libsound.dll "/c/home/proj/Tcl/lib/snack2.2"
cp ./../unix/snack.tcl "/c/home/proj/Tcl/lib/snack2.2"
cp ./../unix/pkgIndex.tcl.dll "/c/home/proj/Tcl/lib/snack2.2/pkgIndex.tcl"

最後に、Snack ライブラリがうまくロードできるか・デモが起動できるか確認してみます。

### ライブラリのロード確認
$ tclsh84.exe
% package require snack
2.2
% package require sound
2.2
% exit

### デモの確認
$ cd ~/proj/Tcl/src/snack2.2.10/demos/tcl/
$ wish84.exe formant.tcl

上記がうまくいけば、大丈夫だと思われます。
なお、VMware Player + Ubuntu Linux の環境では、formant.tcl など波形を合成する類のデモで激しいノイズが載っていたのですが、今回の Msys + Mingw 環境ではノイズ問題は起こりませんでした。
以上、少し苦労しましたが、Windows 環境で Tcl/Tk および Snack をビルドできることが確認できました。
(はじめから、Windows ネイティヴなこちらの方法を試していればよかったなー)