Permalink
Browse files

Better defaults and accessors. See changelog

git-svn-id: http://mkrf.rubyforge.org/svn/trunk@30 6e48df83-f314-0410-b1e7-e69642b30866
  • Loading branch information...
1 parent aa65e55 commit f7c195fb7d6ddeb5a6cdac21beecaae9be9769bc kevinclark committed Sep 10, 2006
Showing with 44 additions and 13 deletions.
  1. +4 −0 CHANGELOG
  2. +9 −6 lib/mkrf/availability.rb
  3. +9 −7 lib/mkrf/generator.rb
  4. +22 −0 test/test_availability.rb
View
@@ -1,4 +1,8 @@
= svn
+* [FIXED] Correct defaults in Availability. [29]
+* [NEW] Using rubylibdir from rbconfig for library path. [29]
+* [NEW] Availability options go straight to availability without generator modification. [29]
+* [NEW] CFLAGS and LDSHARED now accessible through .cflags and .ldshared. [29]
* [FIXED] Can now modify Availability options from the Generator contructor. This may break some existing extconfs that use the .new('libname','file_pattern_a', 'file_pattern_b') syntax. File patterns now only belong as arg 2 and should be an array or a string.
* [FIXED] No indenting generated Rakefile code. [26]
View
@@ -9,8 +9,9 @@ module Mkrf
# which need to determine functionality based on what libraries are available
# on the current system.
class Availability
- DEFAULT_LIBS = ["ruby", "dl"]
-
+ DEFAULT_INCLUDES = [Config::CONFIG['includedir'], Config::CONFIG["archdir"],
+ Config::CONFIG['sitelibdir'], "."]
+
# These really shouldn't be static like this..
TEMP_SOURCE_FILE = "temp_source.c"
TEMP_EXECUTABLE = "temp_executable"
@@ -25,10 +26,12 @@ class Availability
# * <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].to_a || DEFAULT_LIBS
- @headers = options[:headers] || []
- @compiler = options[:compiler] || "gcc"
- @includes = (options[:includes].to_a) || []
+
+ @loaded_libs = (options[:loaded_libs] || Config::CONFIG["LIBS"].gsub('-l', '').split).to_a
+ # Not sure what COMMON_HEADERS looks like when populated
+ @headers = options[:headers] || [] # Config::CONFIG["COMMON_HEADERS"]
+ @compiler = options[:compiler] || Config::CONFIG["CC"]
+ @includes = (options[:includes] || DEFAULT_INCLUDES).to_a
@logger = Logger.new('mkrf.log')
end
View
@@ -33,6 +33,8 @@ class Generator
attr_accessor :additional_code # Any extra code to be added to the Rakefile as a string
+ attr_accessor :ldshared, :cflags
+
# Create a new generator which will write a new +Rakefile+ to the local
# filesystem.
#
@@ -42,12 +44,12 @@ class Generator
def initialize(extension_name, source_patterns = ["lib/*.c"], availability_options = {})
@sources = source_patterns
@extension_name = extension_name + ".#{CONFIG['DLEXT']}"
- default_availability_options = {
- :includes => [CONFIG['includedir'], CONFIG["archdir"], CONFIG['sitelibdir'], "."]
- }
- @available = Mkrf::Availability.new(default_availability_options.merge(availability_options))
+ @available = Mkrf::Availability.new(availability_options)
@defines = []
+ @ldshared = CONFIG['LDSHARED']
+ @cflags = "#{CONFIG['CCDLFLAGS']} #{CONFIG['CFLAGS']} #{CONFIG['ARCH_FLAG']}"
+
yield self if block_given?
write_rakefile
end
@@ -134,14 +136,14 @@ def rakefile_contents # :nodoc:
OBJ = SRC.ext('o')
CC = "gcc"
-LDSHARED = "#{CONFIG['LDSHARED']}"
-LIBPATH = '-L"/usr/local/lib"'
+LDSHARED = "#{@ldshared}"
+LIBPATH = '-L"#{CONFIG['rubylibdir']}"'
INCLUDES = "#{@available.includes_compile_string}"
LIBS = "#{@available.library_compile_string}"
-CFLAGS = "#{CONFIG['CCDLFLAGS']} #{CONFIG['CFLAGS']} #{CONFIG['ARCH_FLAG']} #{defines_compile_string}"
+CFLAGS = "#{@cflags} #{defines_compile_string}"
task :default => ['#{@extension_name}']
View
@@ -94,4 +94,26 @@ def test_logging
assert_match log_items, source
end
end
+end
+
+class TestAvailabilityDefaults < Test::Unit::TestCase
+ def setup
+ @avail = Mkrf::Availability.new
+ @config = Config::CONFIG
+ end
+
+ def test_default_libs_should_be_from_rbconfig
+ assert_equal @config["LIBS"].chomp(" "), @avail.library_compile_string
+ end
+
+ def test_default_compiler_should_be_from_rbconfig
+ assert_equal @config["CC"], @avail.send(:instance_variable_get, :@compiler)
+ end
+
+ def test_default_include_dir_should_be_from_rbconfig
+ expected = [Config::CONFIG['includedir'], Config::CONFIG["archdir"],
+ Config::CONFIG['sitelibdir'], "."]
+
+ assert_equal expected, @avail.send(:instance_variable_get, :@includes)
+ end
end

0 comments on commit f7c195f

Please sign in to comment.