lib/rbplusplus/writers/extension.rb in rbplusplus-0.1.1 vs lib/rbplusplus/writers/extension.rb in rbplusplus-0.8

- old
+ new

@@ -4,41 +4,49 @@ # Writes out the code for building the extension. # This writer takes care of building the extconf.rb # file with the appropriate options. class ExtensionWriter < Base - # List of -I directives - attr_accessor :includes + # Options given from the extension + attr_accessor :options - # List of -L directives - attr_accessor :library_paths + def write + extconf = File.join(working_dir, "extconf.rb") - # List of -l directives - attr_accessor :libraries + inc_str = @options[:include_paths].flatten.uniq.map {|i| "-I#{i}"}.join(" ") + inc_str += " " + @options[:cxxflags].flatten.join(" ") + lib_path_str = @options[:library_paths].flatten.uniq.map {|i| "-L#{i}"}.join(" ") + lib_str = @options[:libraries].flatten.uniq.map {|i| "-l#{i}"}.join(" ") + lib_str += " " + @options[:ldflags].flatten.join(" ") - # Extra CXXFLAGS - attr_accessor :cxxflags + File.open(extconf, "w+") do |file| + file.puts <<-EOF +require 'rubygems' +require 'mkmf-rice' - # Extra LDFLAGS - attr_accessor :ldflags +# Add the arguments to the linker flags. +def append_ld_flags(flags) + flags = [flags] unless flags.is_a?(Array) + with_ldflags("\#{$LDFLAGS} \#{flags.join(' ')}") { true } +end - def write - extconf = File.join(working_dir, "extconf.rb") +$CPPFLAGS += \" -I'#{working_dir}' #{inc_str}\" +$LDFLAGS += \" #{lib_path_str} #{lib_str}\" - @includes ||= [] +if RUBY_PLATFORM =~ /darwin/ + # In order to link the shared library into our bundle with GCC 4.x on OSX, we have to work around a bug: + # GCC redefines symbols - which the -fno-common prohibits. In order to keep the -fno-common, we + # remove the flat_namespace (we now have two namespaces, which fixes the GCC clash). Also, we now lookup + # symbols in both the namespaces (dynamic_lookup). - inc_str = @includes.flatten.uniq.map {|i| "-I#{i}"}.join(" ") - inc_str += " " + @cxxflags.flatten.join(" ") - lib_path_str = @library_paths.flatten.uniq.map {|i| "-L#{i}"}.join(" ") - lib_str = @libraries.flatten.uniq.map {|i| "-l#{i}"}.join(" ") - lib_str += " " + @ldflags.flatten.join(" ") + $LDSHARED_CXX.gsub!('suppress', 'dynamic_lookup') + $LDSHARED_CXX.gsub!('-flat_namespace', '') + + append_ld_flags '-all_load' +end - File.open(extconf, "w+") do |file| - file.puts "require \"rubygems\"" - file.puts "require \"mkmf-rice\"" - file.puts %Q($CPPFLAGS = $CPPFLAGS + " -I#{working_dir} #{inc_str}") - file.puts %Q($LDFLAGS = $LDFLAGS + " #{lib_path_str} #{lib_str}") - file.puts "create_makefile(\"#{builder.name}\")" +create_makefile(\"#{builder.name}\") +EOF end end end end