def sys(cmd)
  puts " -- #{cmd}"
  unless ret = system(cmd)
    raise "ERROR: '#{cmd}' failed"
  end
  ret
end

mkfl = <<MAKEFILE
install:
\t@echo "Nothing to do"

clean:
\t@echo "Nothing to do"
MAKEFILE

CWD = File.expand_path(File.dirname(__FILE__))
LIBSODIUM_DIR = File.expand_path(File.join(CWD, '..', '..', 'vendor', 'libsodium'))
MAKE = ENV['MAKE'] || ENV['make'] || "make"

Dir.chdir(LIBSODIUM_DIR) do
  sys("./configure --prefix=#{LIBSODIUM_DIR}/dist")
  sys(MAKE)
  sys("#{MAKE} install")
end

File.open("Makefile", "w") do |f|
  f.write(mkfl)
end

def sys(cmd)
  puts " -- #{cmd}"
  unless ret = system(cmd)
    raise "ERROR: '#{cmd}' failed"
  end
  ret
end

mkfl = <<MAKEFILE
install:
\t@echo "Nothing to do"

clean:
\t@echo "Nothing to do"
MAKEFILE

CWD = File.expand_path(File.dirname(__FILE__))
LIBSODIUM_DIR = File.expand_path(File.join(CWD, '..', '..', 'vendor', 'libsodium'))
MAKE = ENV['MAKE'] || ENV['make'] || "make"

Dir.chdir(LIBSODIUM_DIR) do
  # sh is required to run configure on Windows
  sys("sh -c \"./configure --prefix=#{LIBSODIUM_DIR}/dist\"")
  sys(MAKE)
  sys("#{MAKE} install")
  if !Dir.glob('dist/bin/libsodium*.dll').empty?
    # copy dll to make it loadable on Windows
    sys("cp dist/bin/libsodium*.dll dist/lib/libsodium.so")
  end
end

File.open("Makefile", "w") do |f|
  f.write(mkfl)
end

Fix issues for Windows MinGW
Fix issues for Windows MinGW

- configure fails because `sh` is not executed
- load fails due to no libsodium.so

This fix works with [RubyInstaller](http://rubyinstaller.org/).
Fix #6
