Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Stole library_path help from Nokogiri :)

Add initial support for MacOSX.
  • Loading branch information...
commit ef7b0ebea1988ae651c4e5ffac84b5e5f987271f 1 parent 6e0a4ee
@remogatto remogatto authored
Showing with 18 additions and 1 deletion.
  1. +18 −1 lib/johnson/spidermonkey/ffi/ffi-spidermonkey.rb
View
19 lib/johnson/spidermonkey/ffi/ffi-spidermonkey.rb
@@ -5,7 +5,24 @@ module Johnson
module SpiderMonkey
extend FFI::Library
- ffi_lib '/usr/local/lib/libmozjs.so'
+
+ def self.expand_library_path(library)
+ return File.expand_path(library) if library =~ %r{^[^/].*/}
+
+ dirs = ['/opt/local/lib', '/usr/local/lib', '/usr/lib']
+
+ ['LD_LIBRARY_PATH', 'DYLD_LIBRARY_PATH'].each do |dyld_dir|
+ dirs = ENV[dyld_dir].split(':') + dirs if ENV.key? dyld_dir
+ end
+
+ library = Dir[ *( dirs.collect {|dir| File.join(dir, "#{library}.{so,dylib}")} ) ].first
+
+ raise "Couldn't find #{library}" unless library
+
+ library
+ end
+
+ ffi_lib expand_library_path('libmozjs')
# libc
attach_function :calloc, [ :int, :int ], :pointer
Please sign in to comment.
Something went wrong with that request. Please try again.