forked from herrtreas/rspactor
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve extconf so it compiles when called from the project root dir
- Loading branch information
Showing
1 changed file
with
24 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |