diff --git a/Rakefile b/Rakefile index 61588fc..ada9045 100644 --- a/Rakefile +++ b/Rakefile @@ -1,13 +1,15 @@ #!/usr/bin/env rake require 'bundler/gem_tasks' require 'rake/extensiontask' - -# Compile the extension -Rake::ExtensionTask.new('wdm') - require 'rspec/core/rake_task' + RSpec::Core::RakeTask.new(:spec) +# Compile the extension +Rake::ExtensionTask.new('wdm_ext') do |ext| + ext.ext_dir = 'ext/wdm' +end + desc "Open an irb session preloaded with WDM" task :console do sh "irb -rubygems -I lib -r wdm" diff --git a/ext/wdm/extconf.rb b/ext/wdm/extconf.rb index 8a7c50f..65abd8e 100644 --- a/ext/wdm/extconf.rb +++ b/ext/wdm/extconf.rb @@ -1,9 +1,27 @@ require 'mkmf' +require 'rbconfig' -if have_library("kernel32") and +def generate_makefile + create_makefile("wdm_ext") +end + +def generate_dummy_makefile + File.open("Makefile", "w") do |f| + f.puts dummy_makefile('wdm_ext').join + end +end + +def windows? + RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ +end + +if windows? and + have_library("kernel32") and have_header("windows.h") and have_header("ruby.h") and have_const('HAVE_RUBY_ENCODING_H') then - create_makefile("wdm") + generate_makefile() +else + generate_dummy_makefile() end diff --git a/ext/wdm/wdm.c b/ext/wdm/wdm.c index 436eefa..356618c 100644 --- a/ext/wdm/wdm.c +++ b/ext/wdm/wdm.c @@ -32,7 +32,7 @@ rb_encoding *wdm_rb_enc_utf8; // ---------------------------------------------------------- void -Init_wdm() +Init_wdm_ext() { WDM_DEBUG("Registering WDM with Ruby!"); diff --git a/ext/wdm/wdm.h b/ext/wdm/wdm.h index 6d94636..6a609ef 100644 --- a/ext/wdm/wdm.h +++ b/ext/wdm/wdm.h @@ -57,6 +57,12 @@ extern VALUE eWDM_Error; extern rb_encoding *wdm_rb_enc_utf8; +// --------------------------------------------------------- +// Prototypes +// --------------------------------------------------------- + +void Init_wdm_ext(); + // --------------------------------------------------------- #ifdef __cplusplus diff --git a/lib/wdm.rb b/lib/wdm.rb new file mode 100644 index 0000000..3ee934d --- /dev/null +++ b/lib/wdm.rb @@ -0,0 +1,10 @@ +begin + require 'wdm_ext' +rescue LoadError + raise LoadError.new(<<-EOS) + Can't load WDM! + + WDM is not supported on your system. For a cross-platform alternative, + we recommend using Listen: http://github.com/guard/listen + EOS +end \ No newline at end of file diff --git a/wdm.gemspec b/wdm.gemspec index 6cfe682..7cb1016 100644 --- a/wdm.gemspec +++ b/wdm.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |gem| gem.summary = %q{Windows Directory Monitor (WDM) is a threaded directories monitor for Windows.} gem.homepage = "https://github.com/Maher4Ever/wdm" - gem.files = `git ls-files -- ext/*`.split($\) + %w[LICENSE README.md] + gem.files = `git ls-files -- ext/* lib/*`.split($\) + %w[LICENSE README.md] gem.extensions = ['ext/wdm/extconf.rb'] gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/})