# = NMatrix # # A linear algebra library for scientific computation in Ruby. # NMatrix is part of SciRuby. # # NMatrix was originally inspired by and derived from NArray, by # Masahiro Tanaka: http://narray.rubyforge.org # # == Copyright Information # # SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation # NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation # # Please see LICENSE.txt for additional copyright notices. # # == Contributing # # By contributing source code to SciRuby, you agree to be bound by # our Contributor Agreement: # # * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement # # == extconf.rb # # This file checks for ATLAS and other necessary headers, and # generates a Makefile for compiling NMatrix. require "mkmf" # Function derived from NArray's extconf.rb. def have_type(type, header=nil) #:nodoc: printf "checking for %s... ", type STDOUT.flush src = <<"SRC" #include SRC src << <<"SRC" unless header.nil? #include <#{header}> SRC r = try_link(src + <<"SRC") int main() { return 0; } int t() { #{type} a; return 0; } SRC unless r print "no\n" return false end $defs.push(format("-DHAVE_%s", type.upcase)) print "yes\n" return true end # Function derived from NArray's extconf.rb. def create_conf_h(file) #:nodoc: print "creating #{file}\n" File.open(file, 'w') do |hfile| header_guard = file.upcase.sub(/\s|\./, '_') hfile.puts "#ifndef #{header_guard}" hfile.puts "#define #{header_guard}" hfile.puts # FIXME: Find a better way to do this: hfile.puts "#define RUBY_2 1" if RUBY_VERSION >= '2.0' for line in $defs line =~ /^-D(.*)/ hfile.printf "#define %s 1\n", $1 end hfile.puts hfile.puts "#endif" end end if RUBY_VERSION < '1.9' raise(NotImplementedError, "Sorry, you need at least Ruby 1.9!") else #$INSTALLFILES = [['nmatrix.h', '$(archdir)'], ['nmatrix.hpp', '$(archdir)'], ['nmatrix_config.h', '$(archdir)'], ['nm_memory.h', '$(archdir)']] if /cygwin|mingw/ =~ RUBY_PLATFORM #$INSTALLFILES << ['libnmatrix.a', '$(archdir)'] end end if /cygwin|mingw/ =~ RUBY_PLATFORM CONFIG["DLDFLAGS"] << " --output-lib libnmatrix.a" end $DEBUG = true #not the right way to add this include directory $CFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix",$CFLAGS].join(" ") $CXXFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix",$CXXFLAGS].join(" ") $CPPFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix",$CPPFLAGS].join(" ") # When adding objects here, make sure their directories are included in CLEANOBJS down at the bottom of extconf.rb. # Why not just autogenerate this list from all .c/.cpp files in directory? basenames = %w{nmatrix_atlas math_atlas} $objs = basenames.map { |b| "#{b}.o" } $srcs = basenames.map { |b| "#{b}.cpp" } #CONFIG['CXX'] = 'clang++' CONFIG['CXX'] = 'g++' def find_newer_gplusplus #:nodoc: print "checking for apparent GNU g++ binary with C++0x/C++11 support... " [9,8,7,6,5,4,3].each do |minor| ver = "4.#{minor}" gpp = "g++-#{ver}" result = `which #{gpp}` next if result.empty? CONFIG['CXX'] = gpp puts ver return CONFIG['CXX'] end false end def gplusplus_version cxxvar = proc { |n| `#{CONFIG['CXX']} -E -dM -