Skip to content

Commit

Permalink
improve extconf so it compiles when called from the project root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Oct 10, 2010
1 parent a42568f commit 5b09b5b
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions ext/extconf.rb
@@ -1,18 +1,34 @@
require 'rbconfig'

# Workaround to make Rubygems believe it builds a native gem
require 'mkmf'
create_makefile('none')
File.open(File.expand_path('../Makefile', __FILE__), 'w') do |f|
f.puts("install:\n\t$(exit 0)")
end

if `uname -s`.chomp == 'Darwin'
gem_root = File.expand_path(File.join('..'))
if Config::CONFIG['host_os'].to_s =~ /\b(darwin|osx)/i
darwin_verion = `uname -r`.to_i
sdk_verion = { 9 => '10.5', 10 => '10.6', 11 => '10.7' }[darwin_verion]

raise "Darwin #{darwin_verion} is not supported" unless sdk_verion

# Compile the actual fsevent_watch binary
system("CFLAGS='-isysroot /Developer/SDKs/MacOSX#{sdk_verion}.sdk -mmacosx-version-min=#{sdk_verion}' /usr/bin/gcc -framework CoreServices -o '#{gem_root}/bin/fsevent_watch' fsevent/fsevent_watch.c")
source_file = File.expand_path("../fsevent/fsevent_watch.c", __FILE__)
target_bin = File.expand_path("../../bin/#{File.basename(source_file, '.c')}", __FILE__)

old_cflags = ENV['CFLAGS']

cflags = %w[-isysroot] <<
"/Developer/SDKs/MacOSX#{sdk_verion}.sdk" <<
"-mmacosx-version-min=#{sdk_verion}" <<
old_cflags

ENV['CFLAGS'] = cflags.join(' ')

unless File.executable?("#{gem_root}/bin/fsevent_watch")
raise "Compilation of fsevent_watch failed (see README)"
begin
# Compile the actual fsevent_watch binary
system('gcc', '-framework', 'CoreServices', '-o', target_bin, source_file)
ensure
ENV['CFLAGS'] = old_cflags
end

raise 'Compiling "fsevent_watch" failed' unless File.executable? target_bin
end

0 comments on commit 5b09b5b

Please sign in to comment.