CygwinでBerkshelfをインストールする


背景

gem install berkshelfで以下のメッセージでインストールできず(2014-08-18)。

$ gem install berkshelf
Building native extensions.  This could take a while...
ERROR:  Error installing berkshelf:
        ERROR: Failed to build gem native extension.

    /c/Users/xxx/.rbenv/versions/2.1.1/bin/ruby.exe extconf.rb
-> sh /c/Users/xxx/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/dep-selector-libgecode-1.0.2/ext/libgecode3/vendor/gecode-3.7.3/configure
--prefix=/c/Users/xxx/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/dep-selector-libgecode-1.0.2/lib/dep-selector-libgecode/vendored-gecode
--disable-doc-dot --disable-doc-search --disable-doc-tagfile
--disable-doc-chm --disable-doc-docset --disable-qt --disable-examples
--disable-flatzinc
checking for the host operating system... Windows
checking whether the C++ compiler works... no
configure: error: in
`/c/Users/xxx/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/dep-selector-libgecode-1.0.2/ext/libgecode3/vendor/gecode-3.7.3':
configure: error: C++ compiler cannot create executables
See `config.log' for more details
extconf.rb:98:in `block in run': Failed to build gecode library.
(GecodeBuild::BuildError)
        from extconf.rb:97:in `chdir'
        from extconf.rb:97:in `run'
        from extconf.rb:104:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in
/c/Users/xxx/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/dep-selector-libgecode-1.0.2
for inspection.
Results logged to
/c/Users/xxx/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/extensions/x86_64-cygwin/2.1.0/dep-selector-libgecode-1.0.2/gem_make.out

dep-selector-libgecode のビルドに失敗してる?
extconf.rb がおかしいらしい。

Berkshelfインストール手順

gemを修正して無理やりインストールしてみる。
以下の手順でdep-selector-libgecodeを無理やりインストールできた。

$ gem fetch dep-selector-libgecode
Fetching: dep-selector-libgecode-1.0.2.gem (100%)
Downloaded dep-selector-libgecode-1.0.2

$ gem unpack dep-selector-libgecode-1.0.2.gem
Unpacked gem: '/c/Users/xxx/Workspaces/Sandbox/dep-selector-libgecode-1.0.2'

$ cd dep-selector-libgecode-1.0.2
$ vim ext/libgecode3/extconf.rb
修正...

$ gem spec --ruby ../dep-selector-libgecode-1.0.2.gem > dep-selector-libgecode.gemspec

$ gem build dep-selector-libgecode.gemspec
WARNING:  no homepage specified
WARNING:  description and summary are identical
WARNING:  open-ended dependency on rake (>= 0, development) is not recommended
  if rake is semantically versioned, use:
    add_development_dependency 'rake', '~> 0'
WARNING:  See http://guides.rubygems.org/specification-reference/ for help
  Successfully built RubyGem
  Name: dep-selector-libgecode
  Version: 1.0.2m
  File: dep-selector-libgecode-1.0.2m.gem

$ gem install ./dep-selector-libgecode-1.0.2m.gem
Building native extensions.  This could take a while...
Successfully installed dep-selector-libgecode-1.0.2m
Parsing documentation for dep-selector-libgecode-1.0.2m
unable to convert "\xED" from ASCII-8BIT to UTF-8 for
lib/dep-selector-libgecode/vendored-gecode/include/gecode/int.hh,
skipping
unable to convert "\xED" from ASCII-8BIT to UTF-8 for
lib/dep-selector-libgecode/vendored-gecode/include/gecode/int/cumulative.hh,
skipping
unable to convert "\xE9" from ASCII-8BIT to UTF-8 for
lib/dep-selector-libgecode/vendored-gecode/include/gecode/int/distinct.hh,
skipping
unable to convert "\xF3" from ASCII-8BIT to UTF-8 for
lib/dep-selector-libgecode/vendored-gecode/include/gecode/int/gcc.hh,
skipping
unable to convert "\xE4" from ASCII-8BIT to UTF-8 for
lib/dep-selector-libgecode/vendored-gecode/include/gecode/int/sorted.hh,
skipping
unable to convert "\xED" from ASCII-8BIT to UTF-8 for
lib/dep-selector-libgecode/vendored-gecode/include/gecode/int/unary.hh,
skipping
Installing ri documentation for dep-selector-libgecode-1.0.2m
Done installing documentation for dep-selector-libgecode after 1 seconds
1 gem installed

修正内容は、以下

diff -r dep-selector-libgecode-1.0.2/ext/libgecode3/extconf.rb dep-selector-libgecode-1.0.2m/ext/libgecode3/extconf.rb
13c13
<    !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
---
>    !!(RUBY_PLATFORM =~ /cygwin|mswin|mingw|windows/)

このあと gem install berkshelf でインストールできた筈、たぶん。