Top Level Namespace

Defined Under Namespace

Modules: GSL, Jac, OOL Classes: Array, Range

Instance Method Summary collapse

Instance Method Details

#create_conf_h(file) ⇒ Object

Function derived from NArray’s extconf.rb.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'ext/gsl_native/extconf.rb', line 13

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'
    hfile.puts "#define RUBY_3 1" if RUBY_VERSION >= '3.0'

    for line in $defs
      line =~ /^-D(.*)/
      match_data = $1.dup

      if match_data.match(/GSL_VERSION*/)
        hfile.printf "#define #{match_data.to_s.split('=').join(' ')}\n"
      else
        hfile.printf "#define %s 1\n", match_data
      end
    end

    hfile.puts
    hfile.puts "#endif"
  end
end

#gsl_config_arg(arg) ⇒ Object



3
4
5
6
7
8
9
10
# File 'ext/gsl_native/extconf.rb', line 3

def gsl_config_arg(arg)
  yield arg_config("--with-gsl-#{arg}") {
    sh = 'sh ' if RUBY_PLATFORM =~ /mingw/
    IO.popen("#{sh}gsl-config --#{arg}") { |f| f.gets.chomp }
  }, lambda { |val| puts "checking gsl #{arg}... #{val}"; val }
rescue => err
  abort "*** ERROR: missing required library to compile this module: #{err}"
end

#gsl_def(const, value = nil) ⇒ Object



42
43
44
45
# File 'ext/gsl_native/extconf.rb', line 42

def gsl_def(const, value = nil)
  value = "=#{value}" if value
  $defs << "-D#{const}#{value}"
end

#gsl_dir_config(target, idir = nil, ldir = idir) ⇒ Object



55
56
57
# File 'ext/gsl_native/extconf.rb', line 55

def gsl_dir_config(target, idir = nil, ldir = idir)
  dir_config(target, idir || $sitearchdir, ldir || $sitearchdir)
end

#gsl_gem_config(target, dir = 'ext') ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'ext/gsl_native/extconf.rb', line 59

def gsl_gem_config(target, dir = 'ext')
  path = begin
    require 'rubygems'

    # For some weird reason finding narray and nmatrix headers works with specific
    # functions only. Might need to fix nmatrix/narray to place headers in correct
    # locations?
    if target == 'narray'
      gem 'narray'
      spec = Gem::Specification.find_by_path("#{target}")
      File.join(spec.full_gem_path, dir) if spec
    else
      gem 'nmatrix'
      spec = Gem::Specification.find_all_by_name("#{target}").compact
      File.join(spec[0].require_path)
    end

  rescue LoadError
  end

  gsl_dir_config(target, path)

  $LOCAL_LIBS += " -l:#{target}.so" if arg_config("--force-link-#{target}")   ||
                                       $CFLAGS.include?('-Wl,--no-undefined') ||
                                       $LDFLAGS.include?('-Wl,--no-undefined')
end

#gsl_have_header(library, header) ⇒ Object



47
48
49
# File 'ext/gsl_native/extconf.rb', line 47

def gsl_have_header(library, header)
  have_library(library) if have_header(header)
end

#gsl_have_library(func) ⇒ Object



51
52
53
# File 'ext/gsl_native/extconf.rb', line 51

def gsl_have_library(func)
  have_func(func) if have_library('gsl', func)
end