Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 5 additions & 36 deletions ext/rugged/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,16 @@
$CFLAGS << " -Wall"
end

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

MAKE_PROGRAM = find_executable('gmake') || find_executable('make')

if MAKE_PROGRAM.nil?
STDERR.puts "ERROR: GNU make is required to build Rugged"
exit(1)
abort 'GNU make is required to build Rugged'
end

if p = ENV['LIBGIT2_PATH']
$INCFLAGS[0,0] = " -I#{File.join(p, 'include')} "
$LDFLAGS << " -L#{p} "
unless have_library 'git2' and have_header 'git2.h'
STDERR.puts "ERROR: Invalid `LIBGIT2_PATH` environment"
exit(1)
end
else
CWD = File.expand_path(File.dirname(__FILE__))
LIBGIT2_DIR = File.join(CWD, '..', '..', 'vendor', 'libgit2')
LIBGIT2_LIB_PATH = "#{CWD}/libgit2_embed.a"

if !File.exists?(LIBGIT2_LIB_PATH)
Dir.chdir(LIBGIT2_DIR) do
sys("#{MAKE_PROGRAM} -f Makefile.embed")
FileUtils.cp 'libgit2.a', LIBGIT2_LIB_PATH
end
end

$INCFLAGS[0,0] = " -I#{LIBGIT2_DIR}/include "
$LDFLAGS << " -L#{CWD} "

unless have_library 'git2_embed' and have_header 'git2.h'
STDERR.puts "ERROR: Failed to build libgit2"
exit(1)
end
dir_config('libgit2')

unless have_library 'git2' and have_header 'git2.h'
abort 'libgit2 is missing. please install libgit2'
end

create_makefile("rugged/rugged")
3 changes: 2 additions & 1 deletion rugged.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Gem::Specification.new do |s|
s.files += Dir.glob("man/**/*")
s.files += Dir.glob("test/**/*")
s.files += Dir.glob("ext/**/*.[ch]")
s.files += Dir.glob("vendor/libgit2/{include,src,deps}/**/*.[ch]")
s.files += Dir.glob("vendor/libgit2/{include,src,deps}/**/*.{c,h,rb}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think there are any *.rb files inside vendor/libgit2, so this change is not needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh shoot, wrong line, it was supposed to be the one above to include the extconf.rb as per http://guides.rubygems.org/c-extensions/ Seems that it isn't necessary though as the gem worked fine like this.

s.files += Dir.glob("vendor/libgit2/Makefile.embed")
s.extensions = ['ext/rugged/extconf.rb']
s.require_paths = [ 'lib', 'ext' ]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're never loading files from the ext directory, I'm not sure why adding it to the load path would be necessary.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Apparently on my system this is needed to get ruby to be able to find the rugged.so shared object which gets installed in vendor/bundle/ruby/2.0.0/gems/rugged-0.19.0/ext/rugged/rugged.so This was the reason to start with the whole exercise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When you install a gem via gem install, the process involves a make install that copies the compiled extension from ext directory into the appropriate lib directory.

Adding ext to the load path is not recommended as other files inside the extension folder might be inadvertently required.

s.required_ruby_version = '>= 1.9.3'
s.description = <<desc
Rugged is a Ruby bindings to the libgit2 linkable C Git library. This is
Expand Down