Skip to content

Commit

Permalink
Allow installation on non-supported systems
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
Maher4Ever committed Feb 2, 2013
1 parent 1b2c80a commit 3b3a7a8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
10 changes: 6 additions & 4 deletions 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"
Expand Down
22 changes: 20 additions & 2 deletions 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
2 changes: 1 addition & 1 deletion ext/wdm/wdm.c
Expand Up @@ -32,7 +32,7 @@ rb_encoding *wdm_rb_enc_utf8;
// ----------------------------------------------------------

void
Init_wdm()
Init_wdm_ext()
{
WDM_DEBUG("Registering WDM with Ruby!");

Expand Down
6 changes: 6 additions & 0 deletions ext/wdm/wdm.h
Expand Up @@ -57,6 +57,12 @@ extern VALUE eWDM_Error;

extern rb_encoding *wdm_rb_enc_utf8;

// ---------------------------------------------------------
// Prototypes
// ---------------------------------------------------------

void Init_wdm_ext();

// ---------------------------------------------------------

#ifdef __cplusplus
Expand Down
10 changes: 10 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion wdm.gemspec
Expand Up @@ -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)/})
Expand Down

2 comments on commit 3b3a7a8

@thibaudgg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad to see you back! Thanks!

@Maher4Ever
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'm glad to be back as well :)

Please sign in to comment.