Top Level Namespace

Defined Under Namespace

Modules: AutoloadMethodExtension, CAMath, CATimeUnitAlgebra Classes: Array, AxisGroup, CABinOp, CABlockIterator, CACategorical, CACategoricalIterator, CAConstString, CAFixlenString, CAFrame, CAGroupIterator, CAIterator, CALazyMarker, CAMeld, CAMonOp, CASlabIterator, CAStack, CAString, CAStruct, CATime, CATimedelta, CAUnboundRepeat, CAUnion, CAWindowIterator, CArray, GroupLabels, GroupedFrame, Range

Instance Method Summary collapse

Instance Method Details

#carray_dir_config(name, pkg = name) ⇒ Object

Configure include/library search for a dependency, preferring its own build description over brute-force prefix probing.

If the dependency ships a pkg-config file (<pkg>.pc), use it to obtain cflags / libs and stop. Otherwise fall back to scanning possible_includes / possible_libs (the only option for hand-rolled scientific libraries that do not provide a .pc file, e.g. nn / ngmath / FITPACK).

carray_dir_config("gsl") # gsl.pc -> done carray_dir_config("nn") # no .pc -> possible_* probe carray_dir_config("foo", "libfoo") # search foo.pc / libfoo.pc as "libfoo"



92
93
94
95
96
# File 'lib/carray/mkmf.rb', line 92

def carray_dir_config (name, pkg = name)
  return true if pkg_config(pkg)
  dir_config(name, possible_includes, possible_libs)
  true
end

#check_fortranvoid

This method returns an undefined value.

Configures the extension to compile Fortran sources, selecting the compiler from --with-fortran (default gfortran) and its flags from --with-fflags. The matching backend registered by #register_fortran_backend links that compiler's runtime; an unmatched compiler warns and leaves the runtime to LIBS / --with-fflags.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/carray/mkmf.rb', line 145

def check_fortran

  SRC_EXT << "f" << "f90" << "f95"

  fc     = with_config("fortran", "gfortran")
  fflags = with_config("fflags", "-O2 -g -fPIC")

  _pattern, backend = FORTRAN_BACKENDS.find { |pat, _| pat =~ fc }
  if backend
    backend.call(fc)
  else
    warn "carray/mkmf: no backend for fortran '#{fc}'; " \
         "register one with register_fortran_backend or pass the " \
         "runtime via LIBS / --with-fflags"
  end

  at_exit do
    if File.file?("Makefile")
      makefile = File.read("Makefile")
      unless makefile =~ /^FC=/
        makefile.sub!(/^COPY =.*$/,
                      '\0' + "\n\n" +
                      "FC=#{fc}\n" +
                      "FFLAGS=#{fflags}\n")
      end
      File.write("Makefile", makefile)
    end
  end

  return fc
end

#have_carrayBoolean

Locates an installed Ruby/CArray and wires its header (and, on Windows, its import library) into the extension being configured. Call this at the top of a companion gem's extconf.rb.

Returns:

  • (Boolean)

    whether every required piece was found.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/carray/mkmf.rb', line 8

def have_carray 
  begin
    require 'carray'
  rescue LoadError
    abort "Ruby/CArray is not installed"
  end
  $LOAD_PATH.each do |path|
    if File.exist? File.join(path, 'carray.h')
      dir_config("carray", path, path)
      break
    end
  end
  status = true
  status &= have_header("carray.h")
  if /cygwin|mingw/ =~ RUBY_PLATFORM
    status &= have_library("carray")
  end
  status
end

#register_fortran_backend(pattern) {|fc| ... } ⇒ void

This method returns an undefined value.

Registers a Fortran runtime backend for #check_fortran to pick up. Only gfortran ships out of the box; a companion gem that needs another compiler registers its own before calling #check_fortran. The block receives the compiler command and is responsible only for linking that compiler's runtime library (dir_config + have_library).

Parameters:

  • pattern (Regexp)

    matched against the configured compiler command.

Yield Parameters:

  • fc (String)

    the compiler command.



127
128
129
# File 'lib/carray/mkmf.rb', line 127

def register_fortran_backend (pattern, &block)
  FORTRAN_BACKENDS[pattern] = block
end