Building OCaml for Windows using Mingw/MSYS

OCamlCygwin 抜きでビルドしたときのメモです。本家の手順だと、Cygwin が必要らしいので、参考程度に。

0. 必要なもの


Mingw/MSYS・bashここ から落としてください。

1. tar ボールを展開する

$ tar zxvf ocaml-3.10.2.tar.gz
$ cd ocaml-3.10.2

2. Mingw 用にヘッダファイルなどを編集する

$ cp config/m-nt.h config/m.h
$ cp config/s-nt.h config/s.h
$ cp config/Makefile.mingw config/Makefile

3. gccコマンドライン処理で不要な処理を行わないようにする

サイズを大きくして対応するのではなく、処理を取り除きたいけれども、今は無理だった。

  • ocaml-3.10.2/utils/ccomp.ml パッチ

*** ocaml-3.10.2/utils/ccomp.ml.org     Sat Nov 10 21:23:37 2007
--- ocaml-3.10.2/utils/ccomp.ml Mon Jun  9 21:17:31 2008
***************
*** 42,48 ****
    let s =
      String.concat " "
        (List.map (fun f -> if f = "" then f else Filename.quote f) lst) in
!   if Sys.os_type = "Win32" && String.length s >= 256
    then build_diversion lst
    else s

--- 42,48 ----
    let s =
      String.concat " "
        (List.map (fun f -> if f = "" then f else Filename.quote f) lst) in
!   if Sys.os_type = "Win32" && String.length s >= 4096
    then build_diversion lst
    else s

4. インストールディレクトリを変更する

PREFIX の値を OCaml のインストールしたいディレクトリに変更します。以下の場合だと、C:/ocamlmgw にインストールされます。

18 ######### General configuration
19
20 PREFIX=C:/ocamlmgw

5. Tcl/Tk ライブラリのビルド対象から除外する

OTHERLIBRARIES 変数から labltk を削除します。これは好みで。ただし、別途 Tcl/Tk をインストールしないといけませんが。試していないです。

148 ############# Configuration for the contributed libraries
149
150 OTHERLIBRARIES=win32unix systhreads str num win32graph dynlink bigarray
151

6. OCaml をビルドする

以下のコマンドを順番に実行していきます。最後の install で PREFIX に指定したディレクトリに必要なファイルがすべてコピーされます。

$ make -f Makefile.nt world
$ make -f Makefile.nt bootstrap
$ make -f Makefile.nt opt
$ make -f Makefile.nt opt.opt
$ make -f Makefile.nt install

ここまでエラーがなければ終了。

参照

  • README.win32(tar パッケージに含まれている)