MacOSXでJubatusのjeneratorコマンドをビルドする

メモ残し

## 前提条件

```
$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.11.5
BuildVersion:	15F34
$ ocaml -version
The OCaml toplevel, version 4.03.0
$ opam --version
1.2.2
$ git clone https://github.com/jubatus/jubatus.git && cd jubatus
$ git log --oneline -n1
a7c2bbe bump RPM packaging version
```

## インストール手順

HomebrewでOCamlのパッケージインストーラ`opam`をインストールする。
その後セットアップ。

```
$ brew install opam
$ opam init
$ eval `opam config env`
$ . ~/.opam/opam-init/init.sh
$ opam install ounit extlib omake ppx_deriving
```

ここまでで`omake`が使えるようになり、`jenerator`のビルドに必要なパッケージもインストールされる。

## `jenerator`のビルド

OCamlのバージョンが異なるのか、エラーになるので以下のパッチを当てる。

エラー

```
$ omake
*** omake: reading OMakefiles
--- Checking for ocamlfind... (found /Users/hattori/.opam/system/bin/ocamlfind)
--- Checking for ocamlc.opt... (found /usr/local/bin/ocamlc.opt)
--- Checking for ocamlopt.opt... (found /usr/local/bin/ocamlopt.opt)
--- Checking whether ocamlc understands the "z" warnings... (yes)
--- Checking if ocamldep understands -modules... (yes)
*** omake: finished reading OMakefiles (0.06 sec)
- build src lib.o
+ ocamlfind ocamlopt -package extlib,ppx_deriving.show -warn-error A -g -I . -c lib.ml
File "lib.ml", line 135, characters 38-55:
Warning 3: deprecated: String.capitalize
Use String.capitalize_ascii instead.
File "lib.ml", line 142, characters 29-46:======================================                                                                                    ] 00067 / 00137
Warning 3: deprecated: String.capitalize
Use String.capitalize_ascii instead.
File "lib.ml", line 1:
Error: Some fatal warnings were triggered (2 occurrences)
*** omake: 67/137 targets are up to date
*** omake: failed (0.91 sec, 14/14 scans, 11/25 rules, 47/176 digests)
*** omake: targets were not rebuilt because of errors:
   src/lib.cmi
      depends on: src/lib.ml
   src/lib.cmx
      depends on: src/lib.ml
   src/lib.o
      depends on: src/lib.ml
```

パッチ

```diff
$ git diff
diff --git a/tools/jenerator/src/cpp.ml b/tools/jenerator/src/cpp.ml
index 0402490..384c47c 100644
--- a/tools/jenerator/src/cpp.ml
+++ b/tools/jenerator/src/cpp.ml
@@ -182,7 +182,7 @@ let gen_ret_type names server  = function

 let make_guard_name filename =
   let name = Filename.basename filename in
-  let upper = String.uppercase name in
+  let upper = String.uppercase_ascii name in
   Str.global_replace (Str.regexp "[\\./]") "_" upper ^ "_"
 ;;

diff --git a/tools/jenerator/src/go.ml b/tools/jenerator/src/go.ml
index b31d383..971355d 100644
--- a/tools/jenerator/src/go.ml
+++ b/tools/jenerator/src/go.ml
@@ -28,7 +28,7 @@ let snake_to_go_ident s =
   String.concat "" (List.map (fun x ->
     match x with
     | "id" -> "ID"
-    | _ -> String.capitalize x) ss)
+    | _ -> String.capitalize_ascii x) ss)

 let make_header conf source filename content =
   make_source conf source filename content comment_out_head
diff --git a/tools/jenerator/src/lib.ml b/tools/jenerator/src/lib.ml
index ddd2b27..97c99e9 100644
--- a/tools/jenerator/src/lib.ml
+++ b/tools/jenerator/src/lib.ml
@@ -132,12 +132,12 @@ let snake_to_lower s =
   let ss = Str.split (Str.regexp "_") s in
   match ss with
     | hd::tl ->
-      hd ^ String.concat "" (List.map String.capitalize tl)
+      hd ^ String.concat "" (List.map String.capitalize_ascii tl)
     | [] ->
       ""
 ;;

 let snake_to_upper s =
   let ss = Str.split (Str.regexp "_") s in
-  String.concat "" (List.map String.capitalize ss)
+  String.concat "" (List.map String.capitalize_ascii ss)
 ;;
```

パッチ当てたらもう一度`omake && omake install`。

```
$ omake
$ omake install
```

これで`jenerator`が実行できる。

```
$ jenerator
Please specify language with -l option
usage: jenerator -l <lang> [-o <out>] [-i] [-n <namespace>] [-t] [-g <includeguard>] idl ...

  -l {server|cpp|python|java|ruby|go}Language
  -o Output directory (default: ".")
  -i Internal include (generate #include with relative path)
  -n Namespace
  -t Output default template xxx_serv files
  -g Prefix of include guard (used in C++)
  --idl-version Versioin of IDL
  --version Show version
  -help  Display this list of options
  --help  Display this list of options
```