Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented paths option to has_library?

 o Updated example to show how it can be called


git-svn-id: http://mkrf.rubyforge.org/svn/trunk@51 6e48df83-f314-0410-b1e7-e69642b30866
  • Loading branch information...
commit 14c81399622d1e1e585ea7aa6dd160ab6a8f235a 1 parent 5dff8d2
hoanga authored
View
4 examples/trivial/ext/trivial/mkrf_conf.rb
@@ -1,4 +1,6 @@
require 'rubygems'
require 'mkrf'
-Mkrf::Generator.new('trivial')
+Mkrf::Generator.new('trivial') do |g|
+ g.include_library('', '', '/usr/local/lib')
+end
View
40 lib/mkrf/availability.rb
@@ -22,12 +22,14 @@ class Availability
#
# Valid keys for the options hash include:
# * <tt>:loaded_libs</tt> -- libraries to load by default
+ # * <tt>:library_paths</tt> -- libraries paths to include by default
# * <tt>:headers</tt> -- headers to load by default
# * <tt>:compiler</tt> -- which compiler to use when determining availability
# * <tt>:includes</tt> -- directories that should be searched for include files
def initialize(options = {})
@loaded_libs = (options[:loaded_libs] || Config::CONFIG["LIBS"].gsub('-l', '').split).to_a
+ @library_paths = (options[:library_paths] || "").to_a
# Not sure what COMMON_HEADERS looks like when populated
@headers = options[:headers] || [] # Config::CONFIG["COMMON_HEADERS"]
@compiler = options[:compiler] || Config::CONFIG["CC"]
@@ -42,7 +44,11 @@ def initialize(options = {})
# Params:
# * <tt>library</tt> -- the library to be included as a string.
# * <tt>function</tt> -- a method to base the inclusion of the library on. +main+ by default.
- def include_library(library, function = "main")
+ # * <tt>paths</tt> -- an optional list of search paths if the library is not found in the default paths.
+ def include_library(library, function = "main", *paths)
+ paths.each do |library_dir|
+ @library_paths << library_dir
+ end
@loaded_libs << library if has_library?(library, function)
end
@@ -64,9 +70,12 @@ def include_header(header, *paths)
# Params:
# * <tt>library</tt> -- the library to be included as a string
# * <tt>function</tt> -- a method to base the inclusion of the library on. +main+ by default.
- def has_library?(library, function = "main")
+ # * <tt>paths</tt> -- an optional list of search paths if the library is not found in the default paths
+ def has_library?(library, function = "main", *paths)
logger.info "Checking for library: #{library}"
return true if library_already_loaded?(library)
+ # Should this be only found_library? or a specialized version with
+ # path searching?
found_library?(library, function)
end
@@ -133,6 +142,11 @@ def library_compile_string
@loaded_libs.collect {|l| "-l#{l}"}.join(' ')
end
+ # Returns a string of libraries directories formatted for compilation
+ def library_paths_compile_string
+ @library_paths.collect {|l| "-L#{l}"}.join(' ')
+ end
+
# Returns a string of include directories formatted for compilation
def includes_compile_string
@includes.collect {|i| "-I#{i}"}.join(' ')
@@ -192,6 +206,19 @@ def header_already_loaded?(header)
return false
end
+# def library_found_in_paths?(library, paths)
+# paths.each do |include_path|
+#
+# if with_libs(include_path) { library_can_link?(header) }
+# @libspath << include_path
+# return true
+# end
+# end
+#
+# return false
+#
+# end
+
def header_found_in_paths?(header, paths)
paths.each do |include_path|
if with_includes(include_path) { header_can_link?(header) }
@@ -218,8 +245,11 @@ def header_include_string
end
def link_command
- "#{@compiler} -o #{TEMP_EXECUTABLE} #{library_compile_string} " +
- "#{includes_compile_string} #{TEMP_SOURCE_FILE}"
+ # This current implementation just splats the library_paths in
+ # unconditionally. Is this problematic?
+ "#{@compiler} -o #{TEMP_EXECUTABLE} #{library_paths_compile_string}" +
+ " #{library_compile_string} #{includes_compile_string}" +
+ " #{TEMP_SOURCE_FILE}"
end
# Creates a temporary source file with the string passed
@@ -284,4 +314,4 @@ def silence_stream(stream)
end
end
-end
+end
View
8 lib/mkrf/generator.rb
@@ -32,6 +32,12 @@ module Mkrf
# '/usr/include/libxml2')
# end
#
+ # It is also possible to specify the library paths in
+ # include_library
+ # Mkrf::Generator.new('libxml') do |g|
+ # g.include_library('socket','socket', '/usr/local/lib/libxml')
+ # end
+ #
class Generator
include Rake
@@ -164,7 +170,7 @@ def rakefile_contents # :nodoc:
LDSHARED = "#{CONFIG['LDSHARED']} #{ldshared}"
-LIBPATH = '-L"#{CONFIG['rubylibdir']}"'
+LIBPATH = "-L#{CONFIG['rubylibdir']} #{@available.library_paths_compile_string}"
INCLUDES = "#{@available.includes_compile_string}"
Please sign in to comment.
Something went wrong with that request. Please try again.